#!/usr/bin/make -f

include /usr/share/quilt/quilt.make

# 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

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

configure: configure-stamp
configure-stamp: $(QUILT_STAMPFN)
	[ ! -f config.make ] || mv config.make debian/config.make.bk
	cp -f debian/config.make config.make
	[ ! -f config.h ] || mv config.h debian/config.h.bk
	cp -f debian/config.h config.h
	dh_testdir
	touch $@

build: build-stamp
build-stamp: configure-stamp
	dh_testdir
	$(MAKE) PROGS="netstat"
	touch $@

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	[ ! -f Makefile ] || $(MAKE) clobber
	[ ! -f debian/config.h.bk ] || \
		mv debian/config.h.bk config.h
	[ ! -f debian/config.make.bk ] || \
		mv debian/config.make.bk config.make
	dh_clean

MANPAGES = netstat.8 \
#	arp.8 \
#	ethers.5 \ 
#	ifconfig.8 \
#	mii-tool.8 \
#	nameif.8 \
#	plipconfig.8 \
#	rarp.8 \
#	route.8 \ 
#	slattach.8

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs bin sbin usr/sbin
	dh_install
	$(MAKE) -C po install BASEDIR=$(CURDIR)/debian/netstat
#	dh_installman --language=de \
#		$(wildcard $(addprefix man/de_DE/,$(MANPAGES)))
#	dh_installman --language=C \
#		$(wildcard $(addprefix man/en_US/,$(MANPAGES)))
#	dh_installman --language=fr \
#		$(wildcard $(addprefix man/fr_FR/,$(MANPAGES)))
#	dh_installman --language=pt_BR \
#		$(wildcard $(addprefix man/pt_BR/,$(MANPAGES)))
	rmdir $(CURDIR)/debian/netstat/bin
	rmdir $(CURDIR)/debian/netstat/usr/sbin
	rmdir $(CURDIR)/debian/netstat/sbin

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs README README.ipv6 TODO
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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