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

export DEB_BUILD_HARDENING=1

%:
	dh $@

INSTALL_PROGRAM = install

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

override_dh_auto_configure:
	libtoolize --copy --force --automake
	aclocal
	autoheader || true
	automake --copy --add-missing
	autoconf -f || true
	# Update our config.sub, config.guess files
	-test -r /usr/share/misc/config.sub && \
	cp -f /usr/share/misc/config.sub config.sub
	-test -r /usr/share/misc/config.guess && \
	cp -f /usr/share/misc/config.guess config.guess
	#  Configure the package.
	./configure --build=$(DEB_BUILD_GNU_TYPE) --host=$(DEB_HOST_GNU_TYPE) \
	--enable-static=no $(GUI_SWITCH) --prefix=/usr \
	--mandir=\$${prefix}/share/man \
	--infodir=\$${prefix}/share/info \
	--libdir=\$${prefix}/lib \
	--includedir=\$${prefix}/include


# GUI_SWITCH = --disable-gui
GUI_SWITCH = --enable-gui

override_dh_auto_clean:
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f config.log config.sub config.guess 
	rm -f Makefile.in
	rm -f aclocal.m4
	rm -f cli/Makefile.in
	rm -f config.h.in configure
	rm -f doc/Makefile.in
	rm -f eXdbm/Makefile.in
	rm -f examples/Makefile.in
	rm -f examples/modules/Makefile.in
	rm -f examples/projects/Makefile.in
	rm -f gpsim/Makefile.in
	rm -f gui/Makefile.in
	rm -f ltmain.sh
	rm -f modules/Makefile.in
	rm -f regression/Makefile.in
	rm -f src/Makefile.in
	rm -f src/dspic/Makefile.in
	rm -f xpms/Makefile.in
	rm -f extras/Makefile.in
	rm -f extras/lcd/Makefile.in
	rm -f extras/lcd/examples/Makefile.in
	rm -f extras/graphic_lcd/Makefile.in
	rm -f extras/graphic_lcd/src/Makefile.in
	rm -f extras/ds1307/Makefile.in
	rm -f extras/ds1307/examples/Makefile.in
	rm -f examples/12bit/Makefile.in
	rm -f examples/14bit/Makefile.in
	rm -f examples/16bit/Makefile.in
	rm -f extras/dht11/Makefile.in
	rm -f extras/dht11/examples/Makefile.in
	rm -f extras/i2c2par/Makefile.in
	rm -f extras/i2c2par/examples/Makefile.in
	rm -f m4/libtool.m4
	rm -f m4/lt~obsolete.m4
	rm -f m4/ltversion.m4
	rm -f m4/ltsugar.m4
	rm -f m4/ltoptions.m4
	rm -f compile
	rm -f extras/ds1820/Makefile.in
	rm -f extras/ds1820/Makefile
	rm -f extras/ds1820/examples/Makefile.in
	rm -f extras/ds1820/examples/Makefile
	dh_clean


override_dh_auto_install:
	#  Install the package into debian/tmp.
	$(MAKE) install prefix=$(CURDIR)/debian/tmp/usr
	libtool --finish $(CURDIR)/debian/tmp/usr/lib
	cp $(CURDIR)/debian/gpsim.lintian $(CURDIR)/debian/gpsim/usr/share/lintian/overrides/gpsim
	chrpath -d $(CURDIR)/debian/tmp/usr/bin/gpsim
	chrpath -d $(CURDIR)/debian/tmp/usr/lib/libgpsim.so.0.0.0
	chrpath -d $(CURDIR)/debian/tmp/usr/lib/libgpsim_dspic.so.0.0.0 
	chrpath -d $(CURDIR)/debian/tmp/usr/lib/libgpsim_eXdbm.so.0.0.0 
	chrpath -d $(CURDIR)/debian/tmp/usr/lib/libgpsim_modules.so.0.0.0 
	chrpath -d $(CURDIR)/debian/tmp/usr/lib/libgpsimcli.so.0.0.0 
	chrpath -d $(CURDIR)/debian/tmp/usr/lib/libgpsimgui.so.0.0.0
	#  Remove things which are not examples; do not fail
	find $(CURDIR)/debian/gpsim/usr/share/doc/gpsim/examples \
	  -name 'Makefile*' -exec rm -f {} \; || true
	#  Kill exec perms in example tree; do not fail
	chmod -x -R $(CURDIR)/debian/gpsim/usr/share/doc/gpsim/examples/* || true

