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

ifeq (s390,$(shell dpkg --print-architecture))
	JAVA_HOME := /usr/lib/jvm/java-6-cacao
else
	JAVA_HOME	:= /usr/lib/jvm/java-6-openjdk
endif
DEB_JARS  := ant ant-launcher ant-junit commons-cli commons-beanutils js junit4 jmock hamcrest-core

DEB_CLASSPATH = $(shell for jar in $(DEB_JARS:%=/usr/share/java/%.jar); do \
	echo -n $${jar}:; done; \
	echo -n $(JAVA_HOME)/lib/tools.jar)

ANT_ARGS	:= -propertyfile debian/ant.properties
ANT				:= CLASSPATH=$(DEB_CLASSPATH) $(JAVA_HOME)/bin/java org.apache.tools.ant.Main $(ANT_ARGS)


VERSION=$(shell dpkg-parsechangelog | grep Version | awk '{ print $$2 }' | sed 's/-.*//')

ifneq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
  with_check := disabled by DEB_BUILD_OPTIONS.
else
  with_check := yes
endif

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.

	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp  
	dh_testdir

	# Add here commands to compile the package.
	$(ANT) -Drelease=$(VERSION)

	touch $@

clean: 
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	$(ANT) -Drelease=$(VERSION) clean cleanrelease

	dh_clean 

check: build
	dh_testdir
ifeq ($(with_check),yes)
	$(ANT) -Drelease=$(VERSION) p2-tests
else
	@echo "Testsuite not run: $(with_check)."
endif

install: build check
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	# Add here commands to install the package into debian/sat4j.
	rm dist/$(VERSION)/*-src.jar
	#cp debian/sat4j.sh $(CURDIR)/debian/sat4j/usr/bin/sat4j
	#chmod a+x $(CURDIR)/debian/sat4j/usr/bin/sat4j


# We have nothing to do by default.
# Build architecture-dependent files here.
binary-arch:

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs
	dh_installexamples
#	dh_install
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_python
#	dh_installinit
#	dh_installcron
#	dh_installinfo
	dh_installman debian/sat4j.1
	dh_lintian -i
	dh_link -i
	jh_installlibs -i $(CURDIR)/dist/$(VERSION)/*.jar
	jh_exec -i
	jh_depends -i
	dh_strip
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-arch binary-indep

TAG_VERS=org.sat4j.pom-2.2.0
DEB_VERS=2.2.0
get-orig-source:
	svn export svn://svn.forge.objectweb.org/svnroot/sat4j/maven/tags/$(TAG_VERS)/ sat4j-$(DEB_VERS)
	cd sat4j-$(DEB_VERS) ; rm -r org.sat4j.maxsat/ org.sat4j.multicore/ \
		org.sat4j.csp/ org.sat4j.csp.xmlparser/
	for i in `find sat4j-$(DEB_VERS) -name "*.java"` ; do grep -q "Copyright" $$i || echo $$i ; done
	tar cf sat4j_$(DEB_VERS).orig.tar sat4j-$(DEB_VERS)
	rm -rf sat4j-$(DEB_VERS)
	gzip -9n sat4j_$(DEB_VERS).orig.tar

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