#!/usr/bin/make -f

SOVERSION = 0d
SOURCE_DIR = $(dir $(firstword $(MAKEFILE_LIST)))/..
UPSTREAM_VERSION = $(shell cd $(SOURCE_DIR) && dpkg-parsechangelog | sed -n -r -e '/^Version: ([0-9.]+).*/ { s//\1/; p; q; }')

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    N_JOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    SCONS_FLAGS += -j$(N_JOBS)
endif
SCONS = scons $(SCONS_FLAGS)

override_dh_auto_configure:
	rm -f configure configure.ac

override_dh_auto_clean:
	-$(SCONS) -c

override_dh_auto_build:
	$(SCONS) prefix=/usr soversion=$(SOVERSION)

override_dh_auto_install:
	$(SCONS) prefix=$(CURDIR)/debian/tmp/usr/ install soversion=$(SOVERSION)
	cd debian/tmp/usr/lib/ && ln libiulib.so libiulib.so.$(SOVERSION)

get-orig-source:
	sh $(SOURCE_DIR)/debian/get-orig-source.sh $(UPSTREAM_VERSION)

%:
	dh $@
