#!/usr/bin/make -f
# Sample debian.rules file - for GNU Hello (1.3).
# Copyright 1994,1995 by Ian Jackson.
# I hereby give you perpetual unlimited permission to copy,
# modify and relicense this file, provided that you do not remove
# my name from the file itself.  (I assert my moral right of
# paternity under the Copyright, Designs and Patents Act 1988.)
# This file may have to be extensively modified

package=ppp

build:
	$(checkdir)
	./configure
	make USE_PAM=1 #INCLUDE_DIRS="-I/usr/include -I../include -I.."
	mv pppd/pppd pppd/pppd-pam
	rm pppd/auth.o
	make
	touch build

clean:
	$(checkdir)
	-rm -f build
	-rm -f pppd/pppd-pam
	-make dist-clean
	-rm -rf `find debian/* -type d -prune`
	-rm `find . -name "*~"`
	-rm -f debian/files*

binary-indep:	checkroot build
	$(checkdir)
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

binary-arch:	checkroot build
	$(checkdir)
	install -d debian/tmp/etc/ppp/peers debian/tmp/etc/chatscripts \
		debian/tmp/etc/ppp/ip-up.d  debian/tmp/etc/ppp/ip-down.d \
		debian/tmp/usr/bin \
		debian/tmp/usr/sbin \
		debian/tmp/usr/man/man8 \
		debian/tmp/usr/include/net
	make install DESTDIR=`pwd`/debian/tmp
	chgrp dip debian/tmp/usr/sbin/pppd
	chmod 4754 debian/tmp/usr/sbin/pppd
# pppd setups
	cp debian/options.ttyXX debian/pap-secrets debian/options debian/ip-up debian/ip-down debian/tmp/etc/ppp
	cp debian/provider debian/tmp/etc/ppp/peers
	cp debian/provider.chatscript debian/tmp/etc/chatscripts/provider
	cp include/net/{pppio.h,*compress.h} debian/tmp/usr/include/net
	chmod 644 debian/tmp/usr/include/net/*
	cp debian/no_ppp_on_boot debian/tmp/etc/ppp
	install debian/{poff,plog,pon} debian/tmp/usr/bin

	# populate ppp-pam
	install -d debian/ppp-pam/usr/sbin \
		debian/ppp-pam/etc/pam.d debian/ppp-pam/usr/doc
	install -s -c -m 4754 -o root -g dip pppd/pppd-pam debian/ppp-pam/usr/sbin/pppd
	cp debian/pam.ppp debian/ppp-pam/etc/pam.d/ppp
	ln -s ppp debian/ppp-pam/usr/doc/ppp-pam

	# put the current version in ppp-pam.substvars
	perl -e 'printf "package:Version=%s\n", <> =~ /\((.*)\)/' debian/changelog > debian/ppp-pam.substvars
# And continue with debian control files
	debstd debian/win95.ppp README.linux FAQ README SETUP README.MSCHAP* README.cbcp debian/*.README debian/kernel*
	dpkg-gencontrol -pppp
	chown -R root.root debian/tmp
	chmod -R g-ws debian/tmp
# Special permissions
	chmod 700 debian/tmp/etc/ppp
	chmod 755 debian/tmp/etc/ppp/ip-up debian/tmp/etc/ppp/ip-down
	chmod 600 debian/tmp/etc/ppp/pap-secrets
	chmod 640 debian/tmp/etc/ppp/peers/provider debian/tmp/etc/chatscripts/provider
	chgrp dip debian/tmp/etc/ppp/peers/provider debian/tmp/etc/chatscripts/provider
	chgrp dip debian/tmp/etc/ppp/peers debian/tmp/etc/chatscripts
	chmod 2750 debian/tmp/etc/ppp/peers debian/tmp/etc/chatscripts
	dpkg --build debian/tmp ..
define checkdir
	test -f debian/rules
endef

# Below here is fairly generic really

binary:		binary-indep binary-arch

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

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

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