#!/usr/bin/make -f
# debian/rules						-*- Makefile -*-
#   $Id: rules,v 1.12 1998/10/22 00:50:16 elf Exp $
#
# written by Marc Singer
# 3 July 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=curves
base=$(package)
version=`cat .version`
RELEASE_PATH=${HOME}/release

build:
	$(checkdir)
	./configure --prefix=/usr
	$(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/usr/doc/$(package)
#	install -m 755 debian/{postinst,prerm} debian/tmp/DEBIAN
	$(MAKE) CFLAGS=-O2 LDFLAGS=-s INSTALL='install' \
		prefix=`pwd`/debian/tmp/usr install
#	gzip -9v debian/tmp/usr/info/*
	cp debian/copyright debian/tmp/usr/doc/$(package)/.
	cp debian/changelog debian/tmp/usr/doc/$(package)/changelog.Debian
		# Give them the sources readme
	cp ChangeLog debian/tmp/usr/doc/$(package)/changelog
		# Give them the customized README
	mv curves-$(version).README debian/tmp/usr/doc/$(package)/README
		# Compress all man pages
	find debian/tmp/usr/man -type f -exec gzip -9v \{\} \;
		# Compress changelog files
	gzip -9v debian/tmp/usr/doc/$(package)/changelog{,.Debian}
	dpkg-shlibdeps curves
	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 $(package).cxx -a -f debian/rules
endef

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

.PHONY: package
package: 
	$(checkdir)
	cvs -Q export -rHEAD -d debian/$(package)-$(version) $(base)
	cd debian/$(package)-$(version) ; dpkg-buildpackage -rsudo
	sudo rm -rf debian/$(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
