#!/usr/bin/make -f
#-*- makefile -*-
# 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 Christoph Lameter.

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

# This is the debhelper compatability version to use.
#export DH_COMPAT=1

## edd 16 May 2008  trivial 'orig.tar.gz' creator
##                  technically, this could be a native Debian package as
##                  the debian/ is in upstream SVN but it is easier to have
##                  another degree of freedom for Debian revisions
##                  if we used just the svn rev: version := $(shell svnversion)
## edd 04 Oct 2008  use changelog entry instead
version := $(shell head -1 debian/changelog | perl -nle 'm/\((\S+)-\d\)/ && print $$1')

showversion:
	@echo Version is ${version}

tarball:
	(cd .. && \
		tar czf tarballs/ess_${version}.orig.tar.gz ess \
			--exclude=.svn \
			--exclude=.git \
			--exclude=debian )

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp:
	dh_testdir

	chmod -R u+w *

#	$(MAKE) -C doc ess.dvi
#	$(MAKE) -C doc readme.dvi
	$(MAKE) -C doc

	touch build-stamp

clean:
	dh_testdir
	dh_testroot

	chmod -R u+w *

	rm -f build-stamp install-stamp doc/*.info*

	[ ! -f Makefile ] || $(MAKE) clean

	rm -f doc/*.dvi #README ANNOUNCE doc/html/readme.html doc/html/ess.html
	rm -f doc/refcard/refcard.log doc/refcard/refcard.aux
	dh_clean

install: install-stamp
install-stamp: build-stamp
	dh_testdir
	dh_testroot
	dh_prep 
	dh_installdirs

#	cd doc ; $(MAKE) install PREFIX=`pwd`/debian/ess
	cp lisp/*.el debian/ess/usr/share/emacs/site-lisp/ess
	! [ -e debian/ess/usr/share/emacs/site-lisp/ess/ess-site.el ] || \
		chmod u+w debian/ess/usr/share/emacs/site-lisp/ess/ess-site.el
	cat lisp/ess-site.el | \
		sed -e 's,(defvar ess-etc-directory nil,(defvar ess-etc-directory "/usr/share/ess/etc/",1'\
		    -e 's,(while (and (listp ess-etc,(while (and (not ess-etc-directory) (listp ess-etc,1' \
		> debian/ess/usr/share/emacs/site-lisp/ess/ess-site.el
	mkdir -p debian/ess/usr/share/ess
	cp -a etc debian/ess/usr/share/ess/
	rm -f debian/ess/usr/share/ess/etc/BACKBUGS.BAT
#	rm -f debian/ess/usr/share/ess/etc/ess-sas-sh-command
	chmod 0755 debian/ess/usr/share/ess/etc/ess-sas-sh-command
	rm -f debian/ess/usr/share/ess/etc/backbug5
	rm -f debian/ess/usr/share/ess/etc/backbug5.sparc
	rm -f debian/ess/usr/share/ess/etc/backbugs.sparc

	touch install-stamp

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installemacsen
	dh_installinfo $$(find doc -type f -name "*.info*")
	dh_installchangelogs 
	rm -fv debian/ess/usr/share/doc/ess/ChangeLog
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch: build install

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

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