#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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


# 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)


config.status: patch configure
	dh_testdir
	# Add here commands to configure the package.
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
	./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs" --enable-debug --disable-klibc-shared --enable-deprecated --enable-fbcondecor --enable-helper --with-gpm --with-mng --with-png --with-ttf --with-ttf-kernel --with-essential-prefix=/ --sysconfdir=/etc


build: build-stamp

build-stamp:  config.status
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE) QUIET=false
	#docbook-to-man debian/splashutils.sgml > splashutils.1

	touch $@

clean: clean-patched unpatch

patch: patch-stamp

patch-stamp:
	dpatch apply-all
	touch patch-stamp

unpatch:
	dpatch deapply-all
	rm -rf patch-stamp debian/patched

clean-patched:
	dh_testdir
	dh_testroot
	rm -f build-stamp 

	# Add here commands to clean up after the build process.
	-$(MAKE) distclean
	# rm -f config.sub config.guess
	# rm -f misc/.dirstamp
	# rm -f libtool
	# rm -f config.status

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

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


# Build architecture-independent files here.
binary-indep: build install
	#
	## Configuration template
	#  ----------------------
	install -m 0644 $(CURDIR)/debian/splash.conf                                  -D $(CURDIR)/debian/tmp/etc/splash/splash
	#
	## Debian's rc splash API
	#  ----------------------
	install -m 0644 $(CURDIR)/debian/lib/init/splash-functions                    -D $(CURDIR)/debian/tmp/lib/init/splash-functions.splashutils
	#
	## Font file
	#  ---------
	# What a !!!PAIN!!! that we cannot include non-text
	# files in here
	install -m 0755                                                               -d $(CURDIR)/debian/tmp/etc/splash
	(cd $(CURDIR)/debian/tmp/etc/splash; rm -f luxisri.ttf; uudecode -o luxisri.ttf ../../../luxisri.ttf.b64)
	#
	## Initramfs script and hook
	#  -------------------------
	install -m 0755 $(CURDIR)/debian/initramfs-tools/scripts/init-top/splashutils -D $(CURDIR)/debian/tmp/etc/initramfs-tools/scripts/init-top/splashutils
	install -m 0755 $(CURDIR)/debian/initramfs-tools/hooks/splashutils            -D $(CURDIR)/debian/tmp/etc/initramfs-tools/hooks/splashutils

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs -s ChangeLog
	dh_installdocs
	dh_installexamples
	dh_install --fail-missing --sourcedir=debian/tmp
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_python
	# Make sure that there is NO /etc/rc*.d/*splashutils
	dh_installinit --noscripts --no-start --no-restart-on-upgrade
#	I know, I know, but for the moment it fails if I uncomment this
#	dh_clean -k
	dh_installinit --no-start --no-restart-on-upgrade --name=splashutilsend -- start 98 2 3 4 5 . stop 01 0 1 6 .
#	dh_installcron
#	dh_installinfo
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_perl
	dh_makeshlibs --package=splashutils
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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