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

CXXFLAGS="-D__DEBIAN__ -O2 -g -Wno-write-strings -DUSE_EXTERNAL_CLUSTALW"

configure: configure-stamp
configure-stamp:
	dh_testdir
	echo "configuring with own configure!"
	dh_autoreconf
	CXXFLAGS=$(CXXFLAGS) ./configure --prefix=/usr 
	for i in help/*.html help/*.css *.db help/*.htm */*.png */*.x[bp]m */*.bmp *.txt */*.txt *.csv; do chmod -x "$$i"; done
	touch $@

build build-arch:	build-stamp
build-stamp: configure-stamp
	dh_testdir
	echo "building with own build!"
	$(MAKE) CXXFLAGS=$(CXXFLAGS) 
	touch $@

build-indep:
	echo "Nothing to do for build-indep"

binary-common:
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	dh_installman
	dh_link
	#dh_strip --dbg-package=gentle-dbg
	dh_strip
	dh_compress -X.pdf
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

install install-arch: build-stamp
	dh_install
	find debian -name "license.txt" | xargs -r rm

install-indep:
	echo Nothing to do for install-indep

binary-indep: 
	#$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
	echo Nothing to do for binary-indep

binary-arch: install-arch
	$(MAKE) -f debian/rules DH_OPTIONS=-s binary-common

binary: binary-arch binary-indep

clean:: 
	dh_testdir
	dh_testroot
	find . -name "*.o"  | xargs -r rm
	rm -f GENtle
	dh_autoreconf_clean
	dh_clean build-arch-stamp build-indep-stamp configure-stamp build-stamp


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