#!/usr/bin/make -f
# Made with the aid of dh_make, by Craig Small
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# Some lines taken from debmake, by Cristoph Lameter.

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

DEV_DPKG_VERSION := $(shell dpkg -s apache-dev | awk '/Version:/ {print $2}')
DEV_VERSION := $(shell echo $(DEV_DPKG_VERSION) | sed "s/^Version: \(.*\)-.*$$/\1/")
# (From the egcs packaging)
NEXTVERNO := $(shell echo $(DEV_VERSION) | awk -F. '{OFS="."; $$NF = $$NF + 1; print}')

# PERL_VER := $(shell /usr/bin/perl debian/perl_version)
# NEXT_PERL_VER := $(shell /usr/bin/perl debian/perl_version next)

PERL := /usr/bin/perl

# ifeq ($(shell $(PERL) -MConfig -e 'print "$$Config{useshrplib}"'), true)
LIBPERL := -lperl

build: build-stamp
build-stamp:
	dh_testdir

	$(PERL) Makefile.PL USE_APXS=1 WITH_APXS=/usr/bin/apxs \
		PERL_SECTIONS=1 PERL_SSI=1 PERL_METHOD_HANDLERS=1 ALL_HOOKS=1 \
		PERL_TIE_TABLES=1 PERL_DIRECTIVE_HANDLERS=1 PERL_STACKED_HANDLERS=1 \
		PERL_TRACE=0 PERL_LOG_API=1 PERL_URI_API=1 PERL_UTIL_API=1 \
		PERL_TABLE_API=1 PERL_FILE_API=1 \
		INSTALLDIRS=vendor # PERL_DEBUG=1
	$(MAKE) OPTIMIZE="-O2 -g -Wall"
	touch build-stamp

clean:
	dh_testdir
	rm -f build-stamp
	dh_clean

	rm -f lib/Apache/MyConfig.pm t/docs/test.shtml \
		 t/net/config.pl t/net/perl/cgi.pl t/report t/conf/httpd.conf{,.old} \
		 t/httpd.conf apaci/find_source lib/mod_perl_hooks.pm
	find . -name .tmp.\* -exec rm -rf {} \;
	([ -f Makefile ] && touch Makefile && $(MAKE) distclean) || true
	chmod -R u+w .

# Build architecture-independent files here.
binary-indep: build
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build
	dh_testversion
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the files into debian/tmp
	$(MAKE) PREFIX=`pwd`/debian/tmp/usr install_vendor

	find `pwd`/debian/tmp \( -name .packlist -o -name perllocal.pod \) -exec \
	  rm -f '{}' \;
	# Why does this return nonzero?
	-find `pwd`/debian/tmp -type d -print0 | xargs -0 \
	  --no-run-if-empty rmdir -p --ignore-fail-on-non-empty

	mkdir -p debian/tmp/usr/lib/apache/1.3
	cp apaci/libperl.so debian/tmp/usr/lib/apache/1.3/mod_perl.so
	chmod 644 debian/tmp/usr/lib/apache/1.3/mod_perl.so
	cp debian/400mod_perl.info debian/tmp/usr/lib/apache/1.3/400mod_perl.info

	dh_installdocs
	cp -a eg/ debian/tmp/usr/share/doc/libapache-mod-perl/examples
	(cd debian/tmp/usr/share/doc/libapache-mod-perl && mv Changes changelog)

	find `pwd`/debian/tmp -type f \( -name \*.pm -o -name \*.pl \) \
	  -exec chmod a-x '{}' \;

	find `pwd`/debian/tmp -type f -name .cvsignore -exec rm '{}' ';'

	find `pwd`/debian/tmp -type f -name mod_perl.exp -exec rm '{}' ';'

	dh_installmanpages
	dh_installchangelogs
	dh_strip
	dh_compress
	dh_fixperms
	dh_shlibdeps
	dh_installdeb
	dh_perl
	dh_gencontrol -- -VTHISDEV="$(DEV_VERSION)" \
		-VNEXTDEV="$(NEXTVERNO)"
	dh_md5sums
	dh_builddeb

source diff:                                                                  
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

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