#!/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=mgetty

build:
	$(checkdir)
	make 
	cd doc; make manpages mgetty.info
	make vgetty callback
	cd contrib; make g3toxwd g3tolj;
	cd frontends/X11/viewfax*;make
	touch build

clean:
	$(checkdir)
	-rm -f build
	-make fullclean
	-rm `find . -name "*~"`
	-cd frontends/X11/viewfax*;make clean
	-rm -rf debian/tmp debian/*/tmp debian/files* contrib/g3tolj contrib/g3toxwd

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)
	-rm -rf debian/tmp debian/mgetty-*/tmp
	install -d debian/tmp/usr/bin debian/tmp/usr/sbin \
		debian/tmp/sbin \
		debian/tmp/var/spool \
		debian/tmp/var/log/mgetty \
		debian/tmp/etc/mgetty \
		debian/mgetty-voice/tmp/usr/{bin,sbin} \
		debian/mgetty-voice/tmp/usr/man/man1 \
		debian/mgetty-voice/tmp/etc/mgetty \
		debian/mgetty-docs/tmp/usr/doc/mgetty/voice \
		debian/mgetty-docs/tmp/usr/doc/mgetty/examples/voice \
		debian/mgetty-fax/tmp/usr/man/man1 \
		debian/mgetty-fax/tmp/usr/lib/mgetty+sendfax
# Mgetty install
	make install prefix=`pwd`/debian/tmp/usr spool=`pwd`/debian/tmp/var/spool
# Vgetty install
	make vgetty-install prefix=`pwd`/debian/mgetty-voice/tmp/usr spool=`pwd`/debian/mgetty-voice/tmp/var/spool
# Enforce debian standard for location of getty's
	mv debian/tmp/usr/sbin/?getty debian/tmp/sbin
# And usr/sbin stuff
	install -d debian/mgetty-fax/tmp/usr/sbin
	mv debian/tmp/usr/bin/faxrunq* debian/mgetty-fax/tmp/usr/sbin
# Contrib stuff
	install -d debian/mgetty-fax/tmp/usr/bin
	install -s contrib/g3toxwd contrib/g3tolj debian/mgetty-fax/tmp/usr/bin
	cd frontends/X11/viewfax*;make install DESTDIR=../../../debian/mgetty-fax/tmp
# callback stuff
	install -s callback/callback debian/tmp/usr/sbin
	install -m644 callback/README debian/mgetty-docs/tmp/usr/doc/mgetty/README.callback
	install -d debian/mgetty-docs/tmp/usr/doc/mgetty
	install -m644 frontends/X11/viewfax*/README debian/mgetty-docs/tmp/usr/doc/mgetty/README.viewfax
# Setup a default configuration
	cp *.config debian/faxheader debian/tmp/etc/mgetty
	install debian/new_fax debian/mgetty-fax/tmp/usr/lib/mgetty+sendfax
	cp voice/voice.conf-dist debian/mgetty-voice/tmp/etc/mgetty/voice.conf

	cp -a voice/scripts voice/{Announce,ChangeLog,Credits,Readme,ToDo,magic.voice,voice.conf-dist} \
		debian/mgetty-docs/tmp/usr/doc/mgetty/voice
	cp debian/inittab debian/mgetty-docs/tmp/usr/doc/$(package)/examples/inittab.DEBIAN
	cp voice/voice.conf-dist debian/mgetty-docs/tmp/usr/doc/mgetty/examples/voice/voice.conf
	cp voice/scripts/{demo.sh,events.sh,voice_mail.sh} debian/mgetty-docs/tmp/usr/doc/mgetty/examples/voice
	chmod -R a+r debian/mgetty-docs/tmp/usr/doc/mgetty

# And continue with debian control files
	debmstd mgetty
	chown -R root.root debian/tmp/usr debian/mgetty*/tmp/usr
	chmod -R g-ws debian/tmp/usr debian/mgetty*/tmp/usr
	rm -rf debian/tmp/usr/{info,lib} debian/tmp/var/spool
# Up to the finale
	dpkg-gencontrol -pmgetty
	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
