#!/usr/bin/make -f
# 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.
#
# This file contains parts of maintainer scripts by Randall Donald 
# <rdonald@debian.org>
# 
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# Get Variables

PKG_NAME=$(pkgName)
PKG_VERSION=$(pkgVersion)
PKG_REVISION=$(pkgRelease)
DPKG_PATH=$(dpkgPath)
BIOS_CHANGE_LOG=$(biosChangeLog)

configure: configure-stamp
configure-stamp:
	touch configure-stamp


build: build-stamp
build-stamp: configure-stamp 
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	dh_clean 

install: build
	cd $(DPKG_PATH)
	sed -e 's/#NAME#/$(PKG_NAME)/' debian/control.template > $(DPKG_PATH)/debian/control

	sed -e 's/#NAME#/$(PKG_NAME)/' debian/dirs.template > $(DPKG_PATH)/debian/dirs
	
	sed -e 's/#NAME#/$(PKG_NAME)/;s/#VERSION#/$(PKG_VERSION)/;s/#REVISION#/$(PKG_REVISION)/' \
	 debian/changelog.template > $(DPKG_PATH)/debian/changelog

	sed -e 's/#NAME#/$(PKG_NAME)/;s/#VERSION#/$(PKG_VERSION)/' debian/postinst.template > \
	$(DPKG_PATH)/debian/postinst

	sed -e 's/#NAME#/$(PKG_NAME)/;s/#VERSION#/$(PKG_VERSION)/' debian/postrm.template > \
	$(DPKG_PATH)/debian/postrm

	sed -e 's/#NAME#/$(PKG_NAME)/' $(DPKG_PATH)/debian/copyright.template > \
	$(DPKG_PATH)/debian/copyright
	
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs
	dh_link '/usr/lib/syslinux/memdisk' 'boot/vmlinuz-'$(PKG_VERSION)'-'$(PKG_NAME)
	dh_install 'initrd.img-'$(PKG_VERSION)'-'$(PKG_NAME) boot	

binary-arch: build install
	dh_testdir
	dh_testroot
	if [ "$(BIOS_CHANGE_LOG)" != "" ]; then \
	    dh_installchangelogs $(BIOS_CHANGE_LOG); \
	else \
	    dh_installchangelogs; \
	fi
	dh_installdocs
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol -- -v$(PKG_VERSION)-$(PKG_REVISION)
	dh_md5sums
	dh_builddeb --destdir=$(DPKG_PATH)

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