#!/usr/bin/make -f

package=userv

build:
	$(checkdir)
	./configure --prefix=/usr
	$(MAKE)
	$(MAKE) spec.html
	touch build

clean:
	$(checkdir)
	-rm -f build
	-$(MAKE) -i distclean || $(MAKE) -f Makefile.in distclean
	-rm -rf *~ debian/tmp debian/*~ debian/files* debian/substvars*

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
	install -d debian/tmp/{DEBIAN,etc/init.d} debian/tmp/usr/{sbin,bin}
	install -d debian/tmp/etc/userv/{override,default}.d
	install -d debian/tmp/usr/doc/$(package)/examples/
	install -d debian/tmp/var/run/$(package)/
	cp debian/{postinst,prerm,postrm,conffiles} debian/tmp/DEBIAN/.
	cp debian/initd debian/tmp/etc/init.d/userv
	chmod +x debian/tmp/DEBIAN/{postinst,prerm,postrm}
	chmod +x debian/tmp/etc/init.d/userv
	$(MAKE) LDFLAGS=-s INSTALL_PROGRAM='install -c -s' \
		prefix=debian/tmp/usr etcdir=debian/tmp/etc install
	cp debian/copyright debian/tmp/usr/doc/$(package)/.
	cp debian/changelog debian/tmp/usr/doc/$(package)/changelog
	cp README debian/tmp/usr/doc/$(package)/README.upstream
	cp system.default system.override debian/tmp/usr/doc/$(package)/examples
	gzip -9v debian/tmp/usr/doc/$(package)/changelog
	ln -s changelog.gz debian/tmp/usr/doc/$(package)/changelog.Debian.gz
	cp -a spec.html debian/tmp/usr/doc/$(package)/
	dpkg-shlibdeps daemon client
	dpkg-gencontrol
	chown -R root.root debian/tmp
	chmod -R g-ws debian/tmp
	chmod 700 debian/tmp/var/run/userv
	dpkg --build debian/tmp ..

define checkdir
	test -f overlord.c -a -f lexer.l.m4 -a -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
