#!/usr/bin/make -f

# Enable LFS
CFLAGS = -D_LARGEFILE_SUPPORT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 $(shell dpkg-buildflags --get CFLAGS)

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

override_dh_auto_configure:
	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,log,cache}
	rm -f native/apache-2.0/mod_jk.{o,la,lo,a} native/apache-2.0/mod_jk.so*
	rm -f native/common/*.{lo,o}
	rm -rf native/apache-2.0/.libs native/common/.libs

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
