#!/usr/bin/make -f
# debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
#
#  This version builds architecture-dependent packages only

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

# Get build platform info
export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

include /usr/share/quilt/quilt.make

autogen: autogen.stamp
autogen.stamp: patch
	libtoolize --copy --force --automake
	aclocal
	autoheader || true
	automake --copy --add-missing
	autoconf -f || true
	touch autogen.stamp

configure: configure-stamp
configure-stamp: autogen.stamp
	dh_testdir
	#  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 --disable-gui --prefix=/usr \
	--mandir=\$${prefix}/share/man \
	--infodir=\$${prefix}/share/info \
	--libdir=\$${prefix}/lib \
	--includedir=\$${prefix}/include

	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir
	#  Compile the package.
	$(MAKE)
	touch build-stamp

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp autogen.stamp
	#  Clean up after the build process.
	[ ! -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 m4/libtool.m4
	rm -f m4/lt~obsolete.m4
	rm -f m4/ltversion.m4
	rm -f m4/ltsugar.m4
	rm -f m4/ltoptions.m4
	dh_clean

install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	#  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

# Build architecture-independent files here.
# Pass -i to all debhelper commands in this target to reduce clutter.           
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
# Pass -a to all debhelper commands in this target to reduce clutter.           
binary-arch: build install
	dh_testdir -a
	dh_testroot -a
	dh_installdocs -a
	dh_installexamples -a
	dh_install --sourcedir=debian/tmp
	#  Remove things which are not examples
	find $(CURDIR)/debian/gpsim/usr/share/doc/gpsim/examples -name 'Makefile*' -exec rm -f {} \;
	#  Kill exec perms in example tree
	chmod -x -R $(CURDIR)/debian/gpsim/usr/share/doc/gpsim/examples/*
	dh_installmenu -a
	dh_installman debian/gpsim.1 -a
	dh_installchangelogs ChangeLog -a
	dh_strip -a
	dh_link -a
	dh_compress -a
	dh_fixperms -a
	dh_makeshlibs -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

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

