#!/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

CFLAGS:=$(shell dpkg-buildflags --get CFLAGS)
CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS)
LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS)

build: build-arch build-indep
build-arch: build-stamp
build-indep:
# Nothing to do here
build-stamp:
	dh_testdir
	./configure --prefix=/usr --with-apxs=/usr/bin/apxs2 --with-apr=/usr/bin/apr-config --with-lua=/usr/include/lua5.1 CPPFLAGS='$(CPPFLAGS)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)'
	cd apache2 && $(MAKE)
	cd mlogc && $(MAKE)
	# since we cannot rename with dh_install, create a copy of the file with the desired name
	cp mlogc/INSTALL mlogc/README.mlogc
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	cd mlogc && [ ! -f Makefile ] || $(MAKE) clean
	rm -f mlogc/README.mlogc
	dh_clean
	rm -f config.log

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	dh_install
	dh_apache2

binary-indep: build install
	dh_testdir -i
	dh_testroot -i
	dh_installdocs -i
	dh_installchangelogs -i
	dh_link -i
	dh_compress -i -Xexample
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir -a
	dh_testroot -a
#	dh_installdebconf -a
	dh_installdocs -a
#	dh_installexamples -a
	cp modsecurity.conf-recommended debian/libapache2-modsecurity/etc/modsecurity
#	dh_installmenu -a
#	dh_installlogrotate -a
#	dh_installemacsen -a
#	dh_installpam -a
#	dh_installmime -a
#	dh_installinit -a
#	dh_installcron -a
#	dh_installman -a
#	dh_installinfo -a
#	dh_undocumented -a
	dh_installchangelogs CHANGES -a
	dh_link -a
	dh_strip -a
	# don't compress examples
	dh_compress -a -Xexample
	dh_fixperms -a
	chown www-data debian/libapache2-modsecurity/var/cache/modsecurity
#	dh_makeshlibs -a
	dh_installdeb -a
#	dh_perl -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 build-arch build-indep
