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

SRC_TMP=$(CURDIR)/SRC_TMP
debtmp := $(CURDIR)/debian/tmp

UVERSION=1_9
VERSION=1.9
get-orig-source:
	rm -rf $(SRC_TMP) && mkdir $(SRC_TMP)
	#[ -f ../cain_$(VERSION).zip ] || wget -O ../cain_$(VERSION).zip http://sf.net/cain/Cain-$(UVERSION).zip # URL did not work
	[ -f ../cain_$(VERSION).zip ] ||  wget -O ../cain_$(VERSION).zip http://qa.debian.org/watch/sf.php/cain/Cain-$(UVERSION).zip
	cd $(SRC_TMP) && unzip ../../cain_$(VERSION).zip
	mv $(SRC_TMP)/Cain $(SRC_TMP)/cain-$(VERSION)
	find $(SRC_TMP) -name __MACOSX -type d | xargs -r rm -rf
	find $(SRC_TMP) -iname .DS_Store -exec rm -f {} +
	find $(SRC_TMP) -iname .scons* -exec rm -f {} +
	rm -f $(SRC_TMP)/cain-$(VERSION)/solvers/*
	rm -rf $(SRC_TMP)/cain-$(VERSION)/src/third-party/*
	cd $(SRC_TMP) && tar cvzf ../../cain_$(VERSION).orig.tar.gz cain-$(VERSION)
	rm -rf $(SRC_TMP)

config.status: configure
	dh_testdir

#build: build-stamp
build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp:
build-stamp:

	# Add here commands to compile the package.
	$(MAKE)

	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	# Add here commands to clean up after the build process.
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f config.sub config.guess
	rm -rf $(debtmp)
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	# Add here commands to install the package into debian/cain
	mkdir -p $(debtmp)/usr/share/applications
	mkdir -p $(debtmp)/usr/bin
	mkdir -p $(debtmp)/usr/share/cain
	mkdir -p $(debtmp)/usr/lib
	mkdir -p $(debtmp)/usr/include/cain
	cp -a examples $(debtmp)/usr/share/cain/
	cp -a gui $(debtmp)/usr/share/cain
	cp -a help $(debtmp)/usr/share/cain/
	rm -f $(debtmp)/usr/share/cain/help/Licen*
	cp -a fio $(debtmp)/usr/share/cain
	cp -a src/* $(debtmp)/usr/include/cain
	cp -a simulation $(debtmp)/usr/share/cain
	cp -a solvers $(debtmp)/usr/lib/
	cp -a state $(debtmp)/usr/share/cain
	cp -a Cain.py $(debtmp)/usr/share/cain/
	cp -a resourcePath.py $(debtmp)/usr/share/cain/
	find $(debtmp)/usr/share/cain/ -type f -executable -exec chmod 644 {} +
	rm -f $(debtmp)/usr/share/cain/help/License.*
	cp -a debian/cain.desktop $(debtmp)/usr/share/applications
	cp -a debian/cain.sh $(debtmp)/usr/bin/cain

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	dh_install
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_python2 --no-guessing-versions
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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