#!/usr/bin/make -f

# Modified from /usr/share/doc/debhelper/examples/rules.multi2,
# incorporating various Hugs bits by
#	Antti-Juhani Kaijanaho <ajk@debian.org>
#	William Irwin <wli@debian.org>
#	Isaac Jones <ijones@syntaxpolice.org>

# Sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess.
#
# This version is for a multibinary package. It also allows you to build any
# of the binary packages independantly, via binary-<package> targets.

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
DEBUG_OPT = --enable-debug
else
DEBUG_OPT =
endif

CONFIG_OPTS = --prefix=/usr $(DEBUG_OPT) --build=$(DEB_BUILD_GNU_TYPE)

build_stamp	= debian/build.stamp
install_stamp	= debian/install.stamp

# A file that should be present in a Hugs source tree
src_file	= src/hugs.c

build: $(build_stamp)
$(build_stamp):
	dh_testdir $(src_file)
	# touch so that patched configure does not trigger autoreconf
	touch configure.ac aclocal.m4 && touch configure
	CFLAGS='-Wall -fPIC' $(MAKE) EXTRA_CONFIGURE_OPTS="$(CONFIG_OPTS)"
	touch $@

clean:
	dh_testdir $(src_file)
	dh_testroot
	# get updated config.sub and config.guess
	cp -f /usr/share/misc/config.sub /usr/share/misc/config.guess .
	# force rerun of autoreconf (for the source distribution)
	$(RM) configure
	$(MAKE) configure
	dh_clean $(install_stamp)
	$(RM) $(build_stamp)
	-$(MAKE) distclean

install: $(install_stamp)
$(install_stamp): DH_OPTIONS=
$(install_stamp): $(build_stamp)
	dh_testdir $(src_file)
	dh_testroot
	dh_clean -k
	dh_installdirs
	$(MAKE) DESTDIR="`pwd`/debian/tmp" install_all_but_docs
	$(RM) debian/tmp/usr/lib/hugs/packages/*/LICENSE
	dh_install --sourcedir=debian/tmp
	touch $@

# This single target is used to build all the packages, all at once, or
# one at a time. So keep in mind: any options passed to commands here will
# affect _all_ packages. Anything you want to only affect one package
# should be put in another target, such as the install target.
binary-common:
	dh_testdir $(src_file)
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	dh_installmenu
#	dh_installdebconf
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installcatalogs
#	dh_installpam
#	dh_installmime
#	dh_installinit
	dh_installman
#	dh_installcron
#	dh_installinfo
#	dh_undocumented
	dh_strip
	dh_link
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_python
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture independant packages using the common target.
binary-indep: $(install_stamp)
# (Uncomment this next line if you have such packages.)
#	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: $(install_stamp)
	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common

# Any other binary targets build just one binary package at a time.
binary-%: $(install_stamp)
	$(MAKE) -f debian/rules DH_OPTIONS='-p$*' binary-common

binary: binary-indep binary-arch

.PHONY: build clean install binary binary-indep binary-arch binary-common update-config
