#!/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

DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)

# Hardened flags
DPKG_EXPORT_BUILDFLAGS = 1
-include /usr/share/dpkg/buildflags.mk

# Don't accidentally build the lorene plug-in
unexport HOME_LORENE

install-arch: build-stamp
	dh_auto_install
	dh_install -a -N yorick-gyoto
	dh_installyorick --no-make-install -pyorick-gyoto
	dh_makeshlibs -a
	dh install-arch

install-indep: doc-stamp
	dh_testdir -i
	dh_testroot -i
	dh_prep -i
	dh_installdirs -i
	dh_install -i
	dh_installdocs -i
	dh_installchangelogs -i
	dh_installexamples -i
	dh_lintian -i
	dh_link -i
	dh_compress -i
	dh_fixperms -i

build: build-arch build-indep
build-arch: build-stamp
build-indep: doc-stamp

override_dh_auto_build:

build-stamp:
	dh_testdir -a
	make COPT_DEFAULT="" \
	     Y_CFLAGS="$(CFLAGS) $(CPPFLAGS)" \
	     Y_LDFLAGS="$(LDFLAGS)"
ifeq (,$(filter nocheck, $(DEB_BUILD_OPTIONS)))
ifeq (,$(filter $(DEB_HOST_ARCH), kfreebsd-i386 kfreebsd-amd64 mips))
# skip the test suite on kfreebsd-any as gyoto package not beeing built
# skip on mips as lucatelli2 fails on it (but the binary works on other boxes)
	make check
endif
endif
	touch build-stamp

doc-stamp:
	dh_testdir -i
	make doc
	touch doc-stamp

binary: binary-indep binary-arch

binary-indep: install-indep
	dh $@

binary-arch: install-arch
	dh $@

clean:
	dh_testdir
	make distclean
	dh_clean doc-stamp build-stamp

override_dh_auto_test:

override_dh_strip:
	dh_strip --dbg-package=gyoto-dbg

%:
	dh $@ 

# maintainer-only rule
git-clean: clean
	debuild clean
	-quilt pop -a
	-rm .pc/.version .pc/.quilt_series .pc/.quilt_patches
	if test -e .pc; then rmdir .pc; fi

.PHONY: clean git-clean override_dh_strip override_dh_auto_test 