#! /usr/bin/make -f
#
# debian/rules	We all know Debian rules.
#

SHELL	= /bin/bash -e
PATH	:= $(PATH):/usr/bin/ssl

# Name.
pkg	= libapache-auth-radius
tmp	= $(shell pwd)/debian/tmp

define checkdir
	test -f radius.c
endef

# Builds the binary package.
build:
	$(checkdir)
	make
	touch build

# Architecture independant files.
binary-indep:   build checkroot

# Make a binary package (.deb file)
binary-arch:    build checkroot
	-rm -rf $(tmp)
	#
	#	libapache-auth-radius
	#
	install -d -g root -m 755 -o root $(tmp)
	install -d -g root -m 755 -o root $(tmp)/DEBIAN
	install -d -g root -m 755 -o root $(tmp)/usr
	install -d -g root -m 755 -o root $(tmp)/usr/doc
	install -d -g root -m 755 -o root $(tmp)/usr/share
	install -d -g root -m 755 -o root $(tmp)/usr/share/doc
	install -d -g root -m 755 -o root $(tmp)/usr/share/doc/$(pkg)
	install -d -g root -m 755 -o root $(tmp)/usr/lib/apache
	install -d -g root -m 755 -o root $(tmp)/usr/lib/apache/1.3
	# Docs
	install -g root -m 644 debian/changelog \
		$(tmp)/usr/share/doc/$(pkg)/changelog.Debian
	install -g root -m 644 ChangeLog $(tmp)/usr/share/doc/$(pkg)/changelog
	install -g root -m 644 README $(tmp)/usr/share/doc/$(pkg)/README
	gzip -9f $(tmp)/usr/share/doc/$(pkg)/*
	#
	install -g root -m 644 debian/copyright $(tmp)/usr/share/doc/$(pkg)
	cat LICENSE >> $(tmp)/usr/share/doc/$(pkg)/copyright
	#
	# Libs/Binaries
	install -g root -m 644 -s mod_auth_radius.so \
		$(tmp)/usr/lib/apache/1.3
	install -g root -m 644 debian/225mod_auth_radius.info \
		$(tmp)/usr/lib/apache/1.3
	# Debian
	install -g root -m 755 debian/postinst $(tmp)/DEBIAN/postinst
	install -g root -m 755 debian/prerm $(tmp)/DEBIAN/prerm
	install -g root -m 755 debian/postrm $(tmp)/DEBIAN/postrm
	dpkg-shlibdeps ./mod_auth_radius.so
	perl debian/apachedeps >> debian/substvars
	dpkg-gencontrol -isp -p$(pkg) -P$(tmp)
	dpkg --build $(tmp) ..

clean:	checkroot
	make clean
	rm -f build debian/files debian/substvars
	rm -rf $(tmp)

binary: binary-arch binary-indep

checkroot:
	$(checkdir)
	test root = "`whoami`"

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