#!/usr/bin/make -f
#export DH_VERBOSE=1

# TODO: there are a lot of warnings with -Wall on. Fix them.
DEB_CFLAGS = -g -Wall
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
DEB_CFLAGS += -O0
else
DEB_CFLAGS += -O2
endif
ifneq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
INSTALL_PROG = install -m 0755
else
INSTALL_PROG = install -s -m 0755
endif

patch: patch-stamp
patch-stamp:
	QUILT_PATCHES=debian/patches quilt push -a || test $$? = 2
	touch patch-stamp

unpatch:
	QUILT_PATCHES=debian/patches quilt pop -a -R || test $$? = 2
	rm -rf .pc patch-stamp

build: build-stamp
build-stamp: patch-stamp
	dh_testdir
	$(MAKE) linux \
	    CFLAGS='$(DEB_CFLAGS)' STATIC='' \
	    DFLAGS='-DLINUX -DTELNET -DGAPING_SECURITY_HOLE'
	touch build-stamp

clean: unpatch
	dh_testdir
	dh_clean patch-stamp build-stamp
	$(MAKE) clean

install:
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(INSTALL_PROG) nc $(CURDIR)/debian/netcat/bin
	dh_link bin/nc bin/netcat

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs README
	dh_installexamples data scripts debian/contrib
	dh_installman debian/nc.1
	dh_link usr/share/man/man1/nc.1.gz usr/share/man/man1/netcat.1.gz
	dh_installchangelogs Changelog
	dh_link
	dh_strip
	dh_compress -Xexamples
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
