#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

# This is the debhelper compatability version to use.
# export DH_COMPAT=3
# set in debian/compat

ifndef PERL
     PERL = /usr/bin/perl
endif

TMP=$(CURDIR)/debian/libnet-dns-perl

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
        CFLAGS += -O2
endif

# dh_strip handles nostrip option. INSTALL_PROGRAMM not used.
#ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
#        INSTALL_PROGRAM += -s
#endif


configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
	

	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.
	#$(MAKE)
	#/usr/bin/docbook-to-man debian/Net-DNS.sgml > Net-DNS.1

	# Debian used to activate online-tests in configuration, but not run them
	# from debian/rules file (to not bother buildds with them), and ask the
	# maintainer to manually run them before uploading.
	# However now the tests are enabled (see make test below) and online
	# tests fail on buildds. To fix that I no longer have --online-tests here:
	$(PERL) Makefile.PL INSTALLDIRS=vendor --IPv6-tests

	# COMPRESS='gzip -9'

	$(MAKE) OPTIMIZE="$(CFLAGS)"

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	$(MAKE) test
endif

	touch build-stamp

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

	# Add here commands to clean up after the build process.
	[ ! -f Makefile ] || $(MAKE) distclean
	
	rm -f Makefile.old

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean
	dh_installdirs

	# Add here commands to install the package into temporary directory.
	#$(MAKE) install DESTDIR=$(TMP) PREFIX=/usr
	$(MAKE) install PREFIX=$(TMP)/usr

	# As this is a architecture dependent package, we are not supposed to install
	# stuff to /usr/share/perl5. MakeMaker creates the dirs, we delete them from 
	# the deb:
	[ ! -d $(TMP)/usr/share/perl5 ] || rmdir --ignore-fail-on-non-empty --parents --verbose $(TMP)/usr/share/perl5

	# add override as .pm files may go to /usr/lib/.. if they accompany binary parts
	# cp debian/lintian-override $(TMP)/usr/share/lintian/overrides/libnet-dns-perl

# Build architecture-independent files here.
binary-indep: build install

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
#	dh_installdebconf	
	dh_installdocs
	dh_installexamples contrib demo
	dh_installmenu
#	dh_installemacsen
#	dh_installpam
#	dh_installinit
	dh_installcron
	dh_installman
	dh_installinfo
#	dh_undocumented
	dh_installchangelogs Changes
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	# You may want to make some executables suid here.
#	dh_suidregister
#	dh_makeshlibs
	dh_installdeb
	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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