#!/usr/bin/make -f

# Enable LFS, build system doesn't respect CPPFLAGS.
export DEB_CFLAGS_MAINT_APPEND = -D_LARGEFILE_SUPPORT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 $(shell dpkg-buildflags --get CPPFLAGS)

%:
	dh $@ --with autotools_dev,apache2 --sourcedirectory=native

override_dh_auto_configure:
	# Run buildconf.sh before configure step. Only needed for building SVN
	# snapshots
	cd native && ./buildconf.sh
	dh_auto_configure -- --with-apxs=/usr/bin/apxs2
	#sed -i -e 's/^LIBTOOL = .*$$/LIBTOOL = \/bin\/sh ..\/libtool/' native/common/Makefile

override_dh_auto_build:
	dh_auto_build
	cp conf/httpd-jk.conf conf/jk.conf

override_dh_auto_clean:
	rm -f conf/jk.conf
	# ac_config_files
	rm -f Makefile apache-1.3/Makefile apache-1.3/Makefile.apxs \
	apache-2.0/Makefile apache-2.0/Makefile.apxs common/Makefile \
	common/list.mk common/jk_types.h jni/Makefile
	# MAINTAINERCLEANFILES
	rm -f native/config.status
	rm -f native/config.log
	rm -f native/config.cache
	rm -f native/common/*.o
	rm -f native/common/*.lo
	rm -f native/apache-2.0/mod_jk.a
	rm -f native/apache-2.0/mod_jk.so*
	rm -f native/apache-2.0/mod_jk.o
	rm -f native/apache-2.0/mod_jk.lo
	rm -f native/apache-2.0/mod_jk.la
	rm -rf build/docs/
	rm -rf native/apache-2.0/.libs native/common/.libs
	rm -f native/Makefile
	rm -f native/Makefile.in
	rm -f native/aclocal.m4
	rm -f native/apache-1.3/Makefile
	rm -f native/apache-1.3/Makefile.apxs
	rm -f native/apache-2.0/Makefile
	rm -f native/apache-2.0/Makefile.apxs
	rm -f native/common/Makefile
	rm -f native/common/config.h
	rm -f native/common/config.h.in
	rm -f native/common/jk_types.h
	rm -f native/common/list.mk
	rm -f native/common/stamp-h1
	rm -f native/config.nice
	rm -f native/configure
	rm -f native/libtool
	rm -f native/scripts/build/unix/compile
	rm -f native/scripts/build/unix/install-sh
	rm -f native/scripts/build/unix/ltmain.sh
	rm -f native/scripts/build/unix/missing


override_dh_auto_install:
ifneq (,$(filter libapache-mod-jk-doc, $(shell dh_listpackages)))
	cd xdocs && install -d ../build/docs/ && cp -R * ../build/docs/
	cd build/docs && for i in `find . -name '*.xml'`; do xsltproc style.xsl $$i > `dirname $$i`/`basename $$i .xml`.html; done
	cd build/docs && find . -name '*.xml' -exec rm -f {} \;
	cd build/docs && rm -f style.xsl BUILDING
	cd build/docs/miscellaneous && lynx -dump -nolist changelog.html > ../changelog
endif

override_dh_compress:
	dh_compress -Xchangelog.html

# No check target
override_dh_auto_test:

get-orig-source:
	uscan --force-download --rename
