#!/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.
# Also some stuff taken from debmake scripts, by Cristopt Lameter.

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

PACKAGE=xemacs21-packages

# this script moves directories so things can't be on separate
# partitions ( no idea why they would be to begin with, but hey
# doesn't hurt to warn :)
package=xemacs
version = $(shell /bin/sh debian/find-version)
maj_version = $(shell /bin/sh debian/find-major-version)

# any way to do this automatically since we'd like this to be
# easily used with no changes on other architectures, but still
# want to be able to specify.  Does this work OK?
machine_type = $(shell dpkg --print-architecture)
prefix=usr

debianconfig = ${machine_type}-debian-linux
html_file_loc = debian/html
tmp_file_loc = debian/tmp

var_file = ./var_file.pl

debian_config_scripts = debian/makevarfile
topdir = $(shell pwd)

# to make this basically cross portable to
xemacs_ver = xemacs${maj_version}

create-source-tar: pre-build
	cp debian/Local.rules .
	$(MAKE) -f debian/PackagesMakefile create-source-tar

build: build-arch build-indep
build-arch:

build-indep: pre-build build-stamp
build-stamp:
	dh_testdir

	cp debian/Local.rules .
	$(MAKE) all

	$(MAKE) -f debian/PackagesMakefile build

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp install-stamp pre-build-stamp
	# set up the files to not cause problems when trying to use them
	set -e ; cd debian ; $(MAKE) -f ConfigMakefile VAR_FILE=$(var_file)

	#-mv install.old install

	-rm -f debian/substvars
	-rm -f debian/files
	-rm -rf debian/tmp #`find debian/* -type d`
	-rm -f xemacs-packages/auctex/preview/latex/bootstrap.log
	-rm -f xemacs-packages/auctex/preview/latex/preview-mk.ins
	-rm -f xemacs-packages/auctex/preview/latex/preview-mk.log
	-rm -f xemacs-packages/auctex/preview/latex/preview.aux
	-rm -f xemacs-packages/auctex/preview/latex/preview.drv
	-rm -f xemacs-packages/auctex/preview/latex/preview.log
	-rm -f xemacs-packages/auctex/preview/latex/preview.out

	# Add here commands to clean up after the build process.
	[ ! -f Local.rules ] || $(MAKE) distclean

# Remove extra generated files
	-rm -f xemacs-packages/eshell/esh-groups.el \
		xemacs-packages/ess/texi/version.texi \
		xemacs-packages/ess/VERSION \
		xemacs-packages/x-symbol/man/index.html
	if [ -f debian/PackagesMakefile ] ; then \
	  $(MAKE) -f debian/PackagesMakefile clean ; \
	fi

	-rm -f `find . -name "*~"`
	-rm -f `find . -name '*.orig'`
	-rm -f `find . -name '*.elc'`
	-rm -f Local.rules

	dh_clean

	# must be done last because it removes the control file
	set -e ; cd debian ; $(MAKE) -f ConfigMakefile VAR_FILE=$(var_file) clean

debian/PackagesMakefile: pre-build

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

	# Add here commands to install the package into debian/tmp.
	$(MAKE) install

	#touch install-stamp


pre-build: pre-build-stamp
pre-build-stamp:
	$(checkdir)
	chmod +x $(debian_config_scripts)
	debian/makevarfile "debian/$(var_file)" \
	    "MAJVERSION" "$(maj_version)" \
	    "VERSION" "$(version)" \
	    "SUBNAME" "" \
	    "CONF_NAME" "$(debianconfig)" \
	    "ARCH" "$(machine_type)" \
	    "HTML_FILE_LOC" "$(html_file_loc)" \
	    "TMP_FILE_LOC" "$(tmp_file_loc)" \
	    "PREFIX" "$(prefix)" \
	    "TOPDIR" "$(topdir)"
	#set -e ; cd debian ; $(MAKE) -f ConfigMakefile VAR_FILE=$(var_file) clean
	set -e ; cd debian ; $(MAKE) -f ConfigMakefile VAR_FILE=$(var_file)
	# replace all references to (dir) to XEmacs${maj_version} in
	# the info files
	#touch pre-build-stamp




# Build architecture-independent files here.
binary-indep: build install
	#-mv install install.old
	$(MAKE) -f debian/PackagesMakefile binary-indep

# Build architecture-dependent files here.
binary-arch: build install
	#-mv install install.old
	$(MAKE) -f debian/PackagesMakefile binary-arch

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

# Local variables:
# mode: makefile
# End:
