#!/usr/bin/make -f
# debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

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

TARGETS = console gnome

CFLAGS = -O2 -Wall
# Currently we rely on dh_strip rather than playing with INSTALL variables.
# No strong reason, just reduced verbosity of configure line.
#INSTALL = install
#INSTALL_FILE    = $(INSTALL) -p    -o root -g root  -m  644
#INSTALL_PROGRAM = $(INSTALL) -p    -o root -g root  -m  755
#INSTALL_SCRIPT  = $(INSTALL) -p    -o root -g root  -m  755
#INSTALL_DIR     = $(INSTALL) -p -d -o root -g root  -m  755

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
CFLAGS += -g
endif
#ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
#INSTALL_PROGRAM += -s
#endif

build: build-stamp
build-stamp: $(TARGETS:%=build-%)
	dh_testdir
	touch build-stamp

# Unlike many other debian/rules files, this `configure' target refers to the
# actual file, not a phony target for running configure.
configure: configure.in
	autoconf

build-console/config.status: configure
	dh_testdir
	[ -d build-console ] || mkdir build-console
	cd build-console && \
	CFLAGS="$(CFLAGS)" ../configure --prefix=/usr --mandir=\$${prefix}/share/man \
	  --disable-debugging

build-console/Makefile: build-console/config.status Makefile.in
	dh_testdir
	cd build-console && CONFIG_FILES=Makefile CONFIG_HEADERS=./config.status

build-console: build-console-stamp
build-console-stamp: build-console/Makefile
	dh_testdir
	$(MAKE) -C build-console
	touch build-console-stamp

build-gnome/config.status: configure
	dh_testdir
	[ -d build-gnome ] || mkdir build-gnome
	cd build-gnome && \
	CFLAGS="$(CFLAGS)" ../configure --prefix=/usr --mandir=\$${prefix}/share/man \
	  --without-debugging --enable-gnomefe

build-gnome/Makefile: build-gnome/config.status Makefile.in
	dh_testdir
	cd build-gnome && CONFIG_FILES=Makefile CONFIG_HEADERS=./config.status

build-gnome: build-gnome-stamp
build-gnome-stamp: build-gnome/Makefile
	dh_testdir
	$(MAKE) -C build-gnome
	touch build-gnome-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp build-console-stamp build-gnome-stamp
	rm -f install-stamp install-console-stamp install-gnome-stamp

	# Add here commands to clean up after the build process.
	-$(MAKE) -C build-console distclean
	-$(MAKE) -C build-gnome distclean
	rm -rf build-console build-gnome

	dh_clean

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

install: install-stamp
install-stamp: $(TARGETS:%=install-%)
	dh_testdir
	dh_testroot
	touch install-stamp

install-console: install-console-stamp
install-console-stamp: build-console-stamp
	dh_testdir
	dh_testroot
	dh_clean -psitecopy -k
	dh_installdirs -psitecopy

	# Add here commands to install the package into debian/sitecopy.
	$(MAKE) -C build-console install prefix=$(CURDIR)/debian/sitecopy/usr

	# Remove unnecessary files.
	rm -rf $(CURDIR)/debian/sitecopy/usr/doc
	rm -rf $(CURDIR)/debian/xsitecopy/usr/share/sitecopy

install-gnome: install-gnome-stamp
install-gnome-stamp: build-gnome-stamp
	dh_testdir
	dh_testroot
	dh_clean -pxsitecopy -k
	dh_installdirs -pxsitecopy

	# Add here commands to install the package into debian/xsitecopy.
	$(MAKE) -C build-gnome install prefix=$(CURDIR)/debian/xsitecopy/usr

	# Remove unnecessary files.
	rm -rf $(CURDIR)/debian/xsitecopy/usr/doc
	rm -rf $(CURDIR)/debian/xsitecopy/usr/share/sitecopy
	rm -rf $(CURDIR)/debian/xsitecopy/usr/share/locale

# Build architecture-dependent files here.
binary-arch: install
	dh_testdir
	dh_testroot
#	dh_installdebconf	
	dh_installdocs
	dh_installexamples -psitecopy doc/examplerc doc/changes.awk
	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
	dh_installcron
	dh_installman -psitecopy
	dh_installman -pxsitecopy
	dh_installinfo
#	dh_undocumented
	dh_installchangelogs ChangeLog
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums

	for i in $(TARGETS); do \
		[ $$i = "console" ] && dh_builddeb -psitecopy; \
		[ $$i = "gnome" ] && dh_builddeb -pxsitecopy; \
	done

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