#! /usr/bin/make -f

include /usr/share/dpatch/dpatch.make

#export DH_VERBOSE=1

DEB_BUILD_GNU_TYPE := $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_GNU_TYPE := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)


ifeq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
  CONFIG_OPTS = --build=$(DEB_BUILD_GNU_TYPE)
else
  CONFIG_OPTS = --build=$(DEB_BUILD_GNU_TYPE) --host=$(DEB_HOST_GNU_TYPE)
endif

all build: patch-stamp stamp-build $(extra_build_targets)

stamp-%: %/Makefile
	$(MAKE) -C $*
	touch $@

build/Makefile:
	mkdir -p $(@D)
	cd $(@D); sh ../configure --prefix=/usr $(CONFIG_OPTS)

clean: unpatch
	dh_clean
	rm -rf debian/strace debian/strace-udeb debian/substvars debian/files debian/files~
	rm -rf build stamp-build

binary: binary-indep binary-arch

binary-indep:

binary-arch: build checkroot
	test -f stamp-build || make $(MFLAGS) -f debian/rules build
	
	dh_testdir -s
	dh_testroot -s
	dh_installdirs -s
	dh_installdocs -s
	dh_installman -s
	dh_installexamples -s
	dh_installchangelogs -s ChangeLog
	dh_install -s
	dh_link -s
	dh_strip -s
	dh_compress -s
	dh_fixperms -s
	dh_installdeb -s
	dh_shlibdeps -s
	dh_gencontrol -s
	dh_md5sums -s
	dh_builddeb -s

checkroot:
	test root = "`whoami`"
