#!/usr/bin/make -f

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

include /usr/share/quilt/quilt.make

# This has to be exported to make some magic below work.
export DH_OPTION

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

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS = -g
endif

config.status: configure patch
	dh_testdir
	CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) -C --prefix=/usr --with-sdl-includes=/usr/include/SDL/ --with-sdl-libraries=/usr/lib/ --with-libxml-includes=/usr/include/libxml2   --with-xslt-includes=/usr/include/libxslt --disable-corba --disable-qte  --disable-kde
	touch configure-stamp

build: build-stamp
build-stamp: config.status
	dh_testdir
	$(MAKE)  prefix=$(CURDIR)/debian/tmp/usr
	touch build-stamp

clean: unpatch
	dh_testdir
	rm -f build-stamp configure-stamp
	rm -f config.log
	[ ! -f Makefile ] || $(MAKE) distclean 
	rm -f debian/*.files
	rm -Rf `find . -name "*.gambas"`
	rm -Rf `find . -name ".deps"`
	rm -f `find . -name "DISABLED"`
	rm -f examples/examples/Games/RobotFindsKitten/COPYING
	rm -f examples/examples/Sound/CDPlayer/cdromtest
	chmod 644 examples/examples/Printing/Printing/Images/*
	dh_clean

install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	$(MAKE) install prefix=$(CURDIR)/debian/tmp/usr 
	rm -f `find $(CURDIR)/debian/tmp/usr -name "*.la"`	
	
# Build architecture-independent files here.
binary-indep: build install
	dh_testdir -i
	dh_testroot -i
	dh_installdirs -i
	dh_installchangelogs -i
	dh_installdocs -i
	dh_installexamples -i
	dh_install --sourcedir=debian/tmp -i
	dh_installman -i
	dh_link -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir -s
	dh_testroot -s
	dh_installchangelogs -s
	dh_installdocs -s
	dh_installchangelogs -pgambas2 ChangeLog
	dh_install --sourcedir=debian/tmp -s
	dh_installmenu -pgambas2-ide
	dh_installmime -s
	dh_installman debian/gbi2.1 -pgambas2-dev
	dh_installman debian/gbx2.1 -pgambas2-runtime
	dh_installman debian/gbr2.1 -pgambas2-runtime
	dh_installman debian/gambas2.gambas.1 -pgambas2-ide
	dh_installman debian/gba2.1 -pgambas2-dev
	dh_installman debian/gambas2-database-manager.gambas.1 -pgambas2-ide
	dh_installman debian/gbc2.1 -pgambas2-dev
	dh_installman debian/gbs2.1 -pgambas2-script
	dh_strip -s
	dh_link -s
	dh_compress -s
	dh_fixperms -s
	dh_installdeb -s
	dh_shlibdeps -s
	dh_gencontrol -s
	dh_md5sums -s
	dh_builddeb -s

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