#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS=hardening=+bindnow future=+lfs
export DH_VERBOSE=1
%:
	dh $@

override_dh_auto_build-indep:
	# just build the -doc package
ifeq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
	# We need therion itself to build the samples
	$(MAKE) therion
	# create HTML documentation for samples
	-faketime "$(dpkg-parsechangelog -S Date)" $(MAKE) samples
endif
	$(MAKE) thbook

override_dh_compress:
	dh_compress -X.pdf -X.th -X.th2 -Xthconfig

override_dh_auto_build-arch:
	# Compile the binaries
	$(MAKE) therion xtherion/xtherion loch/loch
	ln -sf loch.1 man/therion-viewer.7

override_dh_auto_install-indep:
	dh_auto_install -- PREFIX=/usr SYSCONFDIR=/etc

override_dh_auto_install-arch:
	# we need to clear out large generated files from samples before putting just source files in main package
	# .3d files in samples have timestamps - keep them reproducible
	$(MAKE) -C samples clean
	dh_auto_install -- PREFIX=/usr SYSCONFDIR=/etc
	rm debian/tmp/etc/*.new
	# upstream has cz locale when it should be cs
	(cd loch/locale && for lang in * ; do \
	  install -D -m 644 "$$lang/loch.mo" "$(CURDIR)/debian/therion-viewer/usr/share/locale/$$lang/LC_MESSAGES/loch.mo" ; \
	done)
	dh_installexamples -ptherion --exclude=.tcl --exclude=Makefile --exclude=thTMPDIR samples therion.ini
