#!/usr/bin/make -f
# debian/rules						-*- Makefile -*-
#   $Id: rules,v 1.14 1998/10/26 19:14:52 elf Exp $
#
# written by Marc Singer
# 13 October 1998
#
# Copyright 1998 Marc Singer
#
# These rules provide the glue between Debian and this ${package}.
# The interesting target is binary which builds the binary package by
# configuring, compiling, and installing it in the debian/tmp
# directory and then invoking the Debian packaging tools.
# 

package=buici-clock
base=buici
version=`cat .version`
prefix=/usr/X11R6
doc=/usr/doc
RELEASE_PATH=${HOME}/release

build:
	$(checkdir)
	./configure --prefix=$(prefix)
	$(MAKE) 
# CFLAGS=-O2 LDFLAGS=
	touch build

build-release: build
	$(MAKE) $(package).README

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 build-release
	$(checkdir)
	-rm -rf debian/tmp
	install -d debian/tmp/DEBIAN
	install -d debian/tmp$(doc)/$(package)
#	install -m 755 debian/{postinst,prerm} debian/tmp/DEBIAN
	$(MAKE) CFLAGS=-O2 LDFLAGS=-s INSTALL='install' \
		prefix=`pwd`/debian/tmp$(prefix) install
#	gzip -9v debian/tmp$(prefix)/info/*
	cp debian/copyright debian/tmp$(doc)/$(package)/.
	cp debian/changelog debian/tmp$(doc)/$(package)/changelog.Debian
		# Give them the sources readme
	cp ChangeLog debian/tmp$(doc)/$(package)/changelog
		# Give them the customized README
	mv $(package)-$(version).README debian/tmp$(doc)/$(package)/README
		# Compress all man pages
	find debian/tmp$(prefix)/man -type f -exec gzip -9v \{\} \;
		# Compress changelog files
	gzip -9v debian/tmp$(doc)/$(package)/changelog{,.Debian}
	dpkg-shlibdeps $(package)
	dpkg-gencontrol
	chown -R root.root debian/tmp
	chmod -R g-ws debian/tmp
#	if test -d ${RELEASE_PATH} ; then \
#	  dpkg --build debian/tmp ${RELEASE_PATH} ;\
#	else \

	  dpkg --build debian/tmp .. ;\

#	fi

define checkdir
	test -f $(base).xbm -a -f debian/rules
endef

.PHONY: source
source: 
	$(checkdir)
	-rm -rf debian/$(package)-$(version)
	cvs -Q export -rHEAD -d debian/$(package)-$(version) $(base)
	cvs -Q export -rHEAD -d debian/$(package)-$(version)/xo xo
	dpkg-source -b debian/$(package)-$(version)
	-rm -rf debian/$(package)-$(version)
	mv $(package)_*.dsc $(package)_*.tar.gz ..

.PHONY: package
package: 
	$(checkdir)
	mkdir debian/package
	cvs -Q co -d debian/package/$(package)-$(version) $(base)
	cvs -Q co -d debian/package/$(package)-$(version)/xo xo
	cd debian/package/$(package)-$(version) ; dpkg-buildpackage -rsudo
	sudo rm -rf debian/package/$(package)-$(version)

# Below here is fairly generic really

binary:		binary-indep binary-arch

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

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