#!/usr/bin/make -f
#-*- makefile -*-
# Made with the aid of dh_make, by Craig Small

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

# If set to a true value then MakeMaker's prompt function will
# always return the default without waiting for user input.
export PERL_MM_USE_DEFAULT=1

PACKAGE=$(shell dh_listpackages)
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

ifndef PERL
PERL = /usr/bin/perl
endif

ifndef DESTDIR
DESTDIR=..
endif
TMP      = `pwd`/debian/tmp

INSTDIR  = $(shell perl -V:archlib | cut -d\' -f2 )

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

build: build-arch build-indep

build-indep:

build-arch:
	dh_testdir
	dh_autotools-dev_updateconfig
	$(PERL) Makefile.PL --with-apache2-apxs=/usr/bin/apxs2 --prefix=/usr --libdir=/usr/lib/$(DEB_HOST_MULTIARCH)
	sed -i -r 's/(hardcode_into_libs)=.*$$/\1=no/' $(CURDIR)/libtool # See http://wiki.debian.org/RpathIssue.
	$(MAKE) OPTIMIZE="$(CFLAGS)" LDDLFLAGS="-shared $(LDFLAGS)" LD_RUN_PATH=""

clean:
	dh_testdir
	dh_testroot
	[ ! -f Makefile ] || $(MAKE) distclean
	$(RM) -r $(TMP)
	$(RM) config.nice glue/perl/Makefile.old glue/perl/t/REPORT glue/perl/t/SMOKE
	dh_autotools-dev_restoreconfig
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep

	# Note: prefix, not PREFIX.
	mkdir $(TMP)
	$(MAKE) install INSTALLDIRS=vendor DESTDIR=$(TMP) prefix=/usr

binary: binary-arch binary-indep

binary-indep: install
	dh_installdirs -i
	dh_install -i --sourcedir=debian/tmp
	install -m 0644 docs/html/* debian/libapreq2-doc/usr/share/doc/libapache2-request-perl/html/ 
	dh_installdocs -i
	dh_installchangelogs -i CHANGES
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i --destdir=$(DESTDIR)

binary-arch: install
	dh_installdirs -a
	dh_install -a --sourcedir=debian/tmp
	dh_installdocs -a README
	dh_apache2 -a
	dh_installchangelogs -a CHANGES
	dh_link -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_perl -a $(INSTDIR)/Apache
	dh_makeshlibs -a -V'libapreq2-3 (>= 2.13-2)'
	dh_shlibdeps -a -L libapreq2 -l debian/libapreq2/usr/lib
	dh_installdeb -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a --destdir=$(DESTDIR)

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