#!/usr/bin/make -f

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


# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)


CFLAGS = -Wall -g

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

## -------- BUILD TARGETS

build: build-arch build-indep

build-indep:


## -------- BUILD TARGETS
build-arch:
	dh_testdir
	#-$(MAKE) clean
	[ ! -f Makefile ] || $(MAKE) clean
	autoconf
	./configure --without-krb4 APXS=/usr/bin/apxs2 --with-apache=/usr/bin/apache2 CFLAGS="-DGSS_C_DELEG_FLAG"
	make

## -------- INSTALL TARGETS
apache20: build-arch
	mkdir -p $(CURDIR)/debian/libapache2-mod-auth-kerb/usr/share/doc/libapache2-mod-auth-kerb
	install -m 644 $(CURDIR)/README \
		$(CURDIR)/debian/libapache2-mod-auth-kerb/usr/share/doc/libapache2-mod-auth-kerb/

## -------- CLEAN TARGETS

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 
	rm -f config.log config.status

	#-$(MAKE) clean
	[ ! -f Makefile ] || $(MAKE) clean
ifneq "$(wildcard /usr/share/misc/config.sub)" ""
	rm -f config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
	rm -f config.guess
endif
	rm -fr src/.libs spnegokrb5/.libs
	rm -f debian/files
	dh_clean -k

## -------- INSTALL TARGETS

install: install-stamp
intall-stamp:
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

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

# Build architecture-dependent files here.
binary-arch: build-arch apache20
	dh_testdir -a 
	dh_testroot -a
	dh_apache2
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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