#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

#%:
#	dh  $@
#
# Use override_dh_* targets to customize this.
# ---------------------------------------------------
#
build: build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE)
	/usr/bin/docbook-to-man debian/manloch.sgml > man/loch.1
	ln -sf loch.1 man/therion-viewer.1
	# create therion.ini file:
	#$(MAKE) init
ifeq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
	# create samples HTML documentation
	$(MAKE) samples
endif

	#we should generate html of thbook here too if possible
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	# Add here commands to clean up after the build process.
	rm -f man/therion-viewer.1
	cd samples && $(MAKE) clean
	dh_auto_clean
	dh_clean

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

# Build architecture-dependent files here.
binary-arch: build
	dh_testdir
	dh_testroot
	dh_installdirs

	# Add here commands to install the package into debian/therion.
#this stuff no longer needed from 0.2.14
#but it would be nice to put it back
#	install -d -o root -g root -m 755 debian/therion/usr/share/texmf/metapost/therion
#	install -d -o root -g root -m 755 debian/therion/usr/share/texmf/tex/therion
#	install -p -o root -g root -m 644 mpost/*.mp debian/therion/usr/share/texmf/metapost/therion/
#	install -p -o root -g root -m 644 tex/*.tex debian/therion/usr/share/texmf/tex/therion/
	dh_install
	dh_installdocs README
	dh_installdocs -ptherion-doc  thbook/thbook.pdf
ifeq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
	dh_installdocs -ptherion-doc samples.doc
endif
	dh_installdocs -ptherion-viewer loch/help/en/loch.htm
	#we need to clear out large generated files from samples before putting just source files in main package
	cd samples && $(MAKE) clean
	dh_installexamples --exclude=.tcl --exclude=Makefile samples thconfig therion.ini
	dh_installmenu
	dh_installmime
	dh_installman -ptherion man/therion.1 man/xtherion.1
	dh_installman -ptherion-viewer man/loch.1 man/therion-viewer.1
	dh_installchangelogs CHANGES
	dh_strip
	dh_compress -X.pdf -X.th -X.th2 -Xthconfig
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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

get-orig-source: 
	wget -nc -nd http://therion.speleo.sk/download.php?package=therion 
