#!/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

PKGSUFFIX := -devel
PKGVERSION := $(shell dpkg-parsechangelog | gawk '/Version/ { print $$2 }' )

%:
	dh $@ --parallel --with bash-completion

override_dh_auto_configure:
	./bootstrap
	hg id -i --debug > revision
	dh_quilt_patch
	# we don't enable any special driver to avoid missing a version for the kernel we are going to build for
	# Drivers will be enabled anyway in the individual dkms-modules later.
	dh_auto_configure -- --enable-eoe-config --enable-generic --enable-debug-if --enable-cycles --enable-hrtimer --disable-e100\
	  --disable-8139too --disable-e1000 --disable-e1000e --disable-r8169 --enable-regalias --enable-mboxframesize

override_dh_testroot:
	find debian/ -name \*.in -exec debian/substitute.py subst '{}' 's/#VERSION#/$(PKGVERSION)/g' \;
	dh_testroot

override_dh_install:
	debian/write-etherlab-modules-install.py $(PKGSUFFIX) $(PKGVERSION)
	echo /opt/etherlab$(PKGSUFFIX)/lib > debian/libetherlab.so.conf
	dh_install

override_dh_installdocs:
	hg log --style=changelog > ChangeLog
	dh_installdocs

override_dh_installinit:
	dh_installinit --onlyscripts -petherlab-config$(PKGSUFFIX) --name=ethercat-config --update-rcd-params="defaults 19 21"
	dh_installinit --onlyscripts -petherlab-config$(PKGSUFFIX) --name=ethercat --error-handler=on_error

#override_dh_strip:
#	dh_strip --dbg-package=libetherlab-dbg

override_dh_auto_clean:
	debian/prepare-clean.sh
	dh_auto_clean -- distclean
	dh_quilt_unpatch

override_dh_clean:
	find debian/ -name \*.in -exec debian/substitute.py del '{}' \;
	find debian/ -maxdepth 1 -type f -name etherlab-core\* -delete
	rm -f debian/libetherlab.so.conf
	rm -f debian/*.debhelper debian/*.log debian/*.dkms
	rm -rf aclocal.m4 configure autoconf ChangeLog revision Makefile.in config.h.in revision
	find . -name Makefile.in -delete
	rm -f m4/libtool.m4 m4/lt~obsolete.m4 m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4
	dh_clean
