#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

# see https://github.com/libcheck/check/pull/298 for details
export DEB_CFLAGS_MAINT_APPEND = -Wno-format-extra-args

%:
	dh $@

override_dh_auto_clean:
	dh_auto_clean --builddirectory build-standard
	dh_auto_clean --builddirectory build-pic

override_dh_auto_configure:
	AWK=mawk dh_auto_configure --builddirectory build-standard -- \
		--disable-shared \
		--enable-subunit

	AWK=mawk CFLAGS="-fPIC $(CFLAGS)" dh_auto_configure --builddirectory build-pic -- \
		--disable-shared \
		--enable-subunit

override_dh_auto_build:
	dh_auto_build --builddirectory build-standard
	dh_auto_build --builddirectory build-pic

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	dh_auto_test --builddirectory build-standard --max-parallel=1 -- ARGS="--verbose"
	dh_auto_test --builddirectory build-pic --max-parallel=1 -- ARGS="--verbose"
endif

override_dh_auto_install:
	dh_auto_install --builddirectory build-standard

	# fix the installation / setup
	rm debian/check/usr/share/doc/check/COPYING*
	sed -i '/\/\* generated using gnu compiler .*/d' debian/check/usr/include/check_stdint.h
	rm debian/check/usr/share/doc/check/ChangeLog
	rm debian/check/usr/lib/$(DEB_HOST_MULTIARCH)/libcheck.la
	rm -rf debian/check/usr/share/doc/check/example

	# install the pic library
	install build-pic/src/.libs/libcheck.a debian/check/usr/lib/$(DEB_HOST_MULTIARCH)/libcheck_pic.a
