#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/scons.mk

SONAME			:= 2.5.9.9

DEB_DH_MAKESHLIBS_ARGS := -- -c4

CXXFLAGS += -fno-strict-aliasing
CFLAGS += -fno-strict-aliasing
export CFLAGS
export CXXFLAGS

DEB_SCONS_OPTIONS          := library=shared soname=on shlibtype=hidden
DEB_SCONS_BUILD_TARGET     := library
# policy 4.9.1
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	DEB_SCONS_BUILD_OPTIONS    := sample=shell
	DEB_SCONS_BUILD_TARGET     += sample cctests
endif
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	DEB_SCONS_BUILD_OPTIONS += -j$(NUMJOBS)
endif
DEB_SCONS_INSTALL_OPTIONS  := $(DEB_SCONS_OPTIONS) DESTDIR=$(DEB_DESTDIR)

clean::
	rm -f tools/*.pyc libv8-$(SONAME).so
	rm -rf obj
	rm -f test/*/*.pyc
	rm -f shell

common-post-build-impl::
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	LD_PRELOAD=$(CURDIR)/libv8-$(SONAME).so $(CURDIR)/tools/test.py --no-build cctest mjsunit message
endif

common-install-impl::
	cd debian/tmp/usr/lib/ ; \
	mv libv8-$(SONAME)*.so libv8.so.$(SONAME) ; \
	ln -s -T libv8.so.$(SONAME) libv8.so
