#!/usr/bin/make -f
# 
# debian/rules file

# 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)

CXXFLAGS = -Wall -g
CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	OPTFLAGS += -O0
else
	OPTFLAGS += -O3
endif

export CXXFLAGS CFLAGS OPTFLAGS

# Include quilt patch system
include /usr/share/quilt/quilt.make

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

build: patch build-stamp
build-stamp: configure
	
	# Add here commands to compile the arch part of the package.
	$(MAKE) LUA=1
	
	touch build-stamp

clean: clean1 unpatch
clean1:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	
	# Add here commands to clean up after the build process.
	rm -rf dep *.o *~ pdns_recursor pdns_hw rec_control optional/*.o optional
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	
	# Install the stuff
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp
	
	dh_install

# Build architecture (in)dependant packages.
binary-indep:
binary-arch: build install
	dh_testdir -a
	dh_testroot -a
	dh_installchangelogs -a
	dh_installdocs -a
	dh_installman -a
	dh_installlogcheck -a
	dh_installinit -a --error-handler=initscript_error -- defaults 19 85
	dh_link -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

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