#!/usr/bin/make -f

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

CXXFLAGS="-D__DEBIAN__ -O2 -g -Wno-write-strings -DUSE_EXTERNAL_CLUSTALW"
DEBPKGNAME := $(shell dpkg-parsechangelog | awk '/^Source:/ {print $$2}')

%:
	dh $@ --with autoreconf

override_dh_auto_configure:
	CXXFLAGS=$(CXXFLAGS) dh_auto_configure

override_dh_auto_build:
	$(MAKE) -k CXXFLAGS=$(CXXFLAGS) 

override_dh_install:
	dh_install
	cd debian/$(DEBPKGNAME)/usr/share/$(DEBPKGNAME); for i in help/*.html help/*.css *.db help/*.htm */*.png */*.x[bp]m */*.bmp *.txt */*.txt *.csv; do chmod -x "$$i"; done
	find debian -name "license.txt" | xargs -r rm

override_dh_installdocs:
	dh_installdocs
	cp -a docs/GENtle*en*.pdf    debian/$(DEBPKGNAME)/usr/share/doc/$(DEBPKGNAME)/GENtle_manual.pdf
	cp -a docs/GENtle*Manual.pdf debian/$(DEBPKGNAME)/usr/share/doc/$(DEBPKGNAME)/GENtle_manual_de.pdf

override_dh_auto_clean:
	dh_auto_clean
	find . -name "*.o"  | xargs -r rm
	rm -f GENtle

override_dh_compress:
	dh_compress --exclude=.pdf

COMPRESSION=xz
VERSION=1.9+cvs$(shell date +"%Y%m%d"|tr -d ' \t\n')~dfsg
get-orig-source:
	dh_testdir
	if [ -d GENtle ]; then \
		echo "Previous checkout exists as folder 'GENtle', please remove." ; \
		exit -1 ; \
	fi
	if [ -d "gentle-$(VERSION)" ]; then \
		echo "Previous checkout exists as folder 'gentle-$(VERSION)', please remove." ; \
		exit -1 ; \
	fi
	cvs -z3 -d:pserver:anonymous@gentle-m.cvs.sourceforge.net:/cvsroot/gentle-m co -P GENtle
	mv GENtle "gentle-$(VERSION)"
	find . -name "*.dll" -delete
	find . -name "*.a" -delete
	GZIP="--best --no-name" tar --exclude Makefile.in --exclude Makefile --exclude CVS --exclude tinyxml \
		    --exclude .deps --exclude .cvsignore --exclude Makefile.in --exclude Makefile.linux \
		    --exclude clustalw \
		    -caf "../gentle_$(VERSION).orig.tar.$(COMPRESSION)" "gentle-$(VERSION)"
	rm "gentle-$(VERSION)"
