#!/usr/bin/make -f
# Made with the aid of dh_make, by Craig Small
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# Some lines taken from debmake, by Cristoph Lameter.

# Uncomment this to turn on verbose mode.
# export DH_VERBOSE=1

pkg		:= cl-odcl
prefix		:= debian/$(pkg)

INSTALL		:= install
INSTALLFLAGS	:= -g root -o root -m 0644
INSTALLDIRFLAGS	:= -d -g root -o root -m 0755

srcs            := $(shell find * -type f -name '*.lisp')
SOURCESDEST	:= $(prefix)/usr/share/common-lisp/source/odcl
SYSDIR		:= $(prefix)/usr/share/common-lisp/systems

INSTALLSOURCES	:= $(shell find . -type f -name '*.lisp' | grep -v ^./debian)

debian/copyright:	COPYING debian/copyright.in
	cat $^ > $@

test:
	sh -n debian/postinst
	sh -n debian/prerm

build:		debian/copyright test

clean:
	$(checkdir)
	-$(MAKE) clean
	dh_clean
#	 be clever and try to grab a CVS changelog
	[ -f ChangeLog ] || [ ! -f ../$(pkg)/ChangeLog ] || cp ../$(pkg)/ChangeLog .
	[ -f ChangeLog ] || [ ! -f ../$(subst cl-,,$(pkg))/ChangeLog ] || cp ../$(subst cl-,,$(pkg))/ChangeLog .
#	 if we're building clean (exported?) there should be no .cvsignore file in debian diff
	[ -d CVS ] || find . -type f -name .cvsignore | xargs rm -f

binary-indep:	build
	$(checkdir)
	dh_testroot
	dh_clean -k

#	 install sources
	$(INSTALL) $(INSTALLDIRFLAGS) $(SOURCESDEST)
	for src in $(srcs); do \
	    [ -d $(SOURCESDEST)/`dirname $$src` ] || \
		$(INSTALL) $(INSTALLDIRFLAGS) $(SOURCESDEST)/`dirname $$src` ;\
	    $(INSTALL) $(INSTALLFLAGS) $$src $(SOURCESDEST)/$$src ;\
	done

#	 install system files
	$(INSTALL) $(INSTALLDIRFLAGS) $(SYSDIR)
	$(INSTALL) $(INSTALLFLAGS) odcl.system $(SYSDIR)
	$(INSTALL) $(INSTALLFLAGS) odcl.asd $(SOURCESDEST)
	ln -sf ../source/odcl/odcl.asd $(SYSDIR)/odcl.asd

	dh_installdocs NEWS README
	dh_installexamples

	[ ! -f ChangeLog ] || dh_installchangelogs ChangeLog
	[ -f ChangeLog ] || dh_installchangelogs

	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-arch:	build
	@echo "nothing to be done for $@"

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

binary: binary-indep binary-arch
.PHONY: test build clean binary-indep binary-arch binary

define checkdir
	test -f debian/rules
	test -f VERSION
endef
