#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This has to be exported to make some magic below work.
export DH_OPTIONS

CFLAGS		:= $(shell dpkg-buildflags --get CFLAGS)
CPPFLAGS	:= $(shell dpkg-buildflags --get CPPFLAGS)
CXXFLAGS	:= $(shell dpkg-buildflags --get CXXFLAGS)
LDFLAGS		:= $(shell dpkg-buildflags --get LDFLAGS)

DEB_HOST_MULTIARCH	?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
        NUMJOBS := $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
else
	NUMJOBS := 1
endif

export CFLAGS CPPFLAGS CXXFLAGS LDFLAGS

configure-stamp:
	dh_testdir
	dh_auto_configure -- --with-gmp --enable-shared \
		--libdir=/usr/lib/$(DEB_HOST_MULTIARCH)
	touch $@

override_dh_installexamples:
	dh_installexamples -XMakefile -XMakefile.am -XMakefile.in

build-arch: configure-stamp
	dh_testdir
	$(MAKE) -j$(NUMJOBS)

build-indep: configure-stamp
	dh_testdir
	mkdir -p docs/givaro-dev-html
	$(MAKE) -C docs docs_dev
	rm -f docs/givaro-*html/COPYING

build: build-arch

binary-arch: build-arch
	dh $@

binary-indep: build-indep
	dh $@

binary: binary-arch binary-indep

clean:
	dh_testdir
	dh_auto_clean
	dh_clean

.PHONY: build build-arch build-indep binary binary-arch binary-indep clean
