#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#DH_VERBOSE=1

-include /usr/share/dpkg/buildtools.mk

export DEB_BUILD_MAINT_OPTIONS=hardening=+all
CFLAGS =`dpkg-buildflags --get CPPFLAGS`
CFLAGS +=`dpkg-buildflags --get CFLAGS`
LDFLAGS = `dpkg-buildflags --get LDFLAGS`

export DEB_CFLAGS_MAINT_APPEND += -Wno-old-style-definition -Wno-implicit-int -Wno-error=implicit-function-declaration
export DEB_CFLAGS_MAINT_APPEND += -std=gnu90 -fcommon

configure: configure-stamp
configure-stamp:
	dh_testdir
	dh_update_autotools_config
	# Add here commands to configure the package.
	CFLAGS="$(CFLAGS) $(LDFLAGS)" dh_auto_configure --sourcedirectory trafshow*
	dh_autoreconf --sourcedirectory netwatch-1.3.1-2
	dh_auto_configure --sourcedirectory netwatch-1.3.1-2
	# dh_autoreconf --sourcedirectory tcpblast-20011111 # dh_autoreconf can be called only once
	cd tcpblast-20011111 && autoreconf -i
	CC="$(CC)" no_libnsl=yes dh_auto_configure --sourcedirectory tcpblast-20011111

	touch configure-stamp


build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp: configure-stamp
	dh_testdir

	# Add here commands to compile the package.
	CFLAGS="$(CFLAGS) $(LDFLAGS)" dh_auto_build --sourcedirectory tcpspray*
	CFLAGS="$(CFLAGS) $(LDFLAGS)" dh_auto_build --sourcedirectory statnet*
	(cd trafshow*; make)
	(cd netwatch*; make)
	(cd tcpblast*; CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" make)
	CFLAGS="$(CFLAGS) $(LDFLAGS)" dh_auto_build --sourcedirectory netload*

	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	(cd tcpspray; make clean)
	(cd statnet*; make clean; rm -f statnet.1 statnet.lsm)
	(cd trafshow*; [ ! -f Makefile ] || make distclean; rm -f config.log)
	(cd netwatch*; make clean; rm -f Makefile Make.common)
	(cd tcpblast*; [ ! -f Makefile ] || make distclean; rm -f confdefs.h)
	(cd netload*; make clean)

	debconf-updatepo

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_installdirs

	# Add here commands to install the package into debian/netdiag.
	dh_install statnet*/statnet	usr/bin
	dh_install statnet*/statnetd	usr/sbin
	(cd tcpspray; \
		make install BINDIR=$(CURDIR)/debian/netdiag/usr/bin)
	dh_install netwatch*/netwatch   usr/sbin
	dh_install netwatch*/netresolv  usr/lib/netdiag
	dh_installman netwatch*/netwatch.1
	dh_install trafshow*/trafshow   usr/sbin
	dh_install trafshow*/.trafshow	etc && mv $(CURDIR)/debian/netdiag/etc/.trafshow $(CURDIR)/debian/netdiag/etc/trafshow
	dh_installman trafshow*/trafshow.1
	(cd tcpblast*; \
		make install prefix=$(CURDIR)/debian/netdiag/usr \
			mandir=$(CURDIR)/debian/netdiag/usr/share/man)
	(cd netload*; \
		make install TARGET=$(CURDIR)/debian/netdiag/usr/bin \
			MANTARGET=$(CURDIR)/debian/netdiag/usr/share/man/man1)

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	dh_installexamples netwatch*/netwatch.conf.eg
	dh_install
	dh_installmenu
	dh_installsystemd
	dh_installdebconf
	dh_installinit
	dh_installman statnet*/statnet.1 tcpspray/tcpspray.1
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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