#!/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
#export DH_COMPAT=4
#export DEB_BUILD_OPTIONS=nostrip

PACKAGE=xemacs21

# 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-architecture -qDEB_HOST_GNU_CPU)
prefix=usr

debianconfig = $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
tmp_file_loc = debian/tmp

var_file = var_file.pl

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

XEMACS_TYPES = nomule mule mule-canna-wnn

# these things should really not be here if this is to become a more
# general packaging method.
support_bins = b2m etags gnuclient gnuattach gnudoit rcs-checkin ellcc
xemacs_ver = xemacs${maj_version}
html_file_loc = debian/html

build-arch: build
build-indep: build

build: pre-build build-stamp
build-stamp: debian/PackagesMakefile
	dh_testdir

	$(MAKE) -f debian/PackagesMakefile build

	touch build-stamp

clean: debian/${var_file}
	dh_testdir
	dh_testroot
	rm -f build-stamp install-stamp pre-build-stamp

	-mv install.old install
	-rm -f install

	-rm -f debian/substvars
	-rm -f debian/files
	-rm -rf debian/tmp # `find debian/* -type d`
	-rm -f lisp/custom-load.el
	-rm -f configure

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

	if [ -f debian/PackagesMakefile ] ; then \
	  $(MAKE) -f debian/PackagesMakefile clean ; \
	fi

	if [ -f lisp/auto-autoloads.el.orig ]; then \
	  cp lisp/auto-autoloads.el.orig lisp/auto-autoloads.el ; \
	fi

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

	dh_clean

	# must be done last because it removes some utility scripts
	set -e ; cd debian ; \
	$(MAKE) -f ConfigMakefile \
	  VAR_FILE=$(var_file) \
	  XEMACS_TYPES="$(XEMACS_TYPES)" \
	  clean
	rm -f debian/$(var_file)

install: install-stamp
install-stamp: build
	dh_testdir
	dh_testroot
	dh_prep
	${MAKE} -f debian/PackagesMakefile installit

	touch install-stamp

debian/${var_file}:
	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)" \
	    "SUPPORT_BINS" "$(support_bins)"

debian/PackagesMakefile: debian/PackagesMakefile.in debian/${var_file}
	set -e ; cd debian ; \
	$(MAKE) -f ConfigMakefile \
	  VAR_FILE=$(var_file) \
	  XEMACS_TYPES="$(XEMACS_TYPES)"

pre-build: pre-build-stamp
pre-build-stamp: debian/${var_file} debian/PackagesMakefile
	$(checkdir)

	touch pre-build-stamp
	cp lisp/auto-autoloads.el lisp/auto-autoloads.el.orig

# 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 install binary-indep binary-arch binary

# Local variables:
# mode: makefile
# End:

