#!/usr/bin/make -f
#	Rules file for iguanair, requires the debhelper package.
#	Crafted by IguanaWorks Support support@iguanaworks.net, 14 March 2008 

# Comment this to turn off debhelper verbose mode.
export DH_VERBOSE=1

DEB_BUILD_GNU_TYPE = $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_GNU_TYPE = $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
CONFARGS = --host=$(DEB_HOST_GNU_TYPE)
endif

CFLAGS="-g -O2 -Wall" 

configure: configure-stamp
configure-stamp:
	dh_testdir
	CFLAGS=$(CFLAGS) ./configure
	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	-rm -f build-stamp configure-stamp
	make distclean || exit 0
	make -C packaging ../debian
	dh_clean

	# remove the build directories
	rm -rf $(CURDIR)/debian/tmp $(CURDIR)/debian/iguana-python

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	dh_makeshlibs

	# main install
	make install DESTDIR=$(CURDIR)/debian/tmp LIBDIR=lib

	#add symlink for library
	#ln -s libiguanaIR.so libiguanaIR.so.0
	#mv libiguanaIR.so.0 $(CURDIR)/debian/tmp/usr/lib/

	# move the python stuff into it's sub package
	mkdir -p $(CURDIR)/debian/iguanair-python/usr/lib
	mv $(CURDIR)/debian/tmp/usr/lib/python* $(CURDIR)/debian/iguanair-python/usr/lib

	#move the reflasher stuff into it's sub systm
	mkdir -p $(CURDIR)/debian/iguanair-reflasher/usr/bin
	mkdir -p $(CURDIR)/debian/iguanair-reflasher/usr/lib
	mv $(CURDIR)/debian/tmp/usr/lib/iguanaIR-reflasher $(CURDIR)/debian/iguanair-reflasher/usr/lib/
	mv $(CURDIR)/debian/tmp/usr/bin/iguanaIR-reflasher $(CURDIR)/debian/iguanair-reflasher/usr/bin/
	




binary-indep:	build install

binary-arch:	build install
	dh_testdir
	dh_testroot
	dh_installdocs AUTHORS LICENSE LICENSE-LGPL WHY protocols.txt README.txt notes.txt ChangeLog
#	dh_installmanpages
#	dh_installinfo doc/gzip.info
	dh_installchangelogs ChangeLog
	dh_link
#	dh_strip
	dh_compress
#	ln -s gunzip.1.gz debian/gzip/usr/share/man/man1/uncompress.1.gz
#	ln -s zgrep.1.gz debian/gzip/usr/share/man/man1/zegrep.1.gz
#	ln -s zgrep.1.gz debian/gzip/usr/share/man/man1/zfgrep.1.gz
	dh_fixperms
	# You may want to make some executables suid here.
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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

