#!/usr/bin/make -f

export DH_VERBOSE = 1

unpack: unpack-stamp
unpack-stamp:
	dh_testdir
	dh_illumos_gate --build \
		usr/src/cmd/modload \
		usr/src/man/man1m/add_drv.1m \
		usr/src/man/man1m/modinfo.1m \
		usr/src/man/man1m/modload.1m \
		usr/src/man/man1m/modunload.1m \
		usr/src/man/man1m/rem_drv.1m \
		usr/src/man/man1m/update_drv.1m \



	# Buggy and unused:
	echo > usr/src/Makefile.msg.targ

	# Use GNU ld, see also the bootadm-use-gnu-ld.patch patch
	#sed -i '/LD_ALTEXEC/d' usr/env.sh
	touch $@

patch: patch-stamp
patch-stamp: unpack-stamp
	dh_testdir
	[ ! -f debian/patches/series ] || QUILT_PATCHES=debian/patches quilt push -a || test $$? = 2
	touch $@

unpatch:
	dh_testdir
	[ ! -f debian/patches/series ] || QUILT_PATCHES=debian/patches quilt pop -a -f || test $$? = 2
	rm -f patch-stamp

dirs-stamp: unpack-stamp
	. usr/env.sh; mkdir -p \
		debian/tmp/usr/bin \
		debian/tmp/usr/sbin
	touch $@

install build build-arch build-indep: build-stamp

build-stamp: dirs-stamp patch-stamp
	# We've patched it, so i386 is suitable for any arch:
	dh_illumos_make --native usr/src/cmd/modload/i386
	touch $@

binary binary-arch binary-indep: binary-stamp
binary-stamp: build-stamp
	dh_testdir
	dh_testroot
	dh_installdirs
	dh_install
	dh_installman
	dh_installdocs
	dh_installexamples
	dh_installchangelogs
	dh_bash-completion
	dh_link
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb
	touch $@

clean: unpatch
	dh_testdir
	dh_testroot
	dh_clean
	rm -rf usr

