#!/usr/bin/make -f
#
# Copyright 2006 Tim Dijstra <tim@famdijkstra.org>
# Upgraded by Rodolfo García Peñas (kix) <kix@kix.es>

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

DEB_HOST_GNU_TYPE	?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE	?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

#CFLAGS += `pkg-config --cflags glib-2.0`
#SPLASHY_LIBS = -L/lib -lsplashy -lgcc_s
SPLASHY_LIBS = -L/lib -lgcc_s
DB2MAN=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl
XP=xsltproc -''-nonet

%:
	dh $@

override_dh_auto_configure:
	dh_testdir
ifneq "$(wildcard /usr/share/misc/config.sub)" ""
	cp -f /usr/share/misc/config.sub config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
	cp -f /usr/share/misc/config.guess config.guess
endif
	dh_auto_configure -- --host=$(DEB_HOST_GNU_TYPE) \
		--build=$(DEB_BUILD_GNU_TYPE) \
		-prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--docdir=\$${prefix}/share/doc/uswsusp \
		--with-initramfsdir=/usr/lib/uswsusp \
		--disable-resume-static \
		--disable-create-device \
		--enable-compress \
		--enable-encrypt \
		CFLAGS="$(CFLAGS)" SPLASHY_LIBS="$(SPLASHY_LIBS)"

override_dh_clean:
	dh_clean
	rm -f config.sub config.guess

#build-stamp: patch config.status
#	dh_testdir
#
#	# Add here commands to compile the package.
#	$(MAKE)
#
#	chmod 755 debian/initramfs-tools/scripts/local-premount/* \
#			debian/initramfs-tools/hooks/*
#	
#	touch $@
#
#clean-source:
#	dh_testdir
#	dh_testroot
#	rm -f build-stamp
#
#	# Add here commands to clean up after the build process.
#	[ ! -f Makefile ] || $(MAKE) distclean
#
#	debconf-updatepo
#
#	dh_clean 

override_dh_install:
	dh_install
#install: build
#	dh_testdir
#	dh_testroot
#	dh_prep
#	dh_installdirs
#
#	# Add here commands to install the package into debian/uswsusp.
#	$(MAKE) install DESTDIR=$(CURDIR)/debian/uswsusp
#
#	# We don't want upstreams config file. 
#	# Remove it here so I don't forget to patch the Makefile
	rm -f $(CURDIR)/debian/uswsusp/etc/suspend.conf
	rm -f $(CURDIR)/debian/uswsusp/usr/share/doc/uswsusp/COPYING*
	rm -rf $(CURDIR)/debian/uswsusp/dev


override_dh_auto_build:
	$(XP) -o debian/ \
	--param make.year.ranges 1 \
	--param make.single.year.ranges 1 \
	--param man.charmap.use.subset 0 \
	$(DB2MAN) \
	debian/s2disk.8.xml debian/s2ram.8.xml \
	debian/swap-offset.8.xml debian/suspend-keygen.8.xml \
	debian/uswsusp.conf.5.xml
	dh_auto_build

