#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS=hardening=+bindnow future=+lfs

%:
	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
	$(MAKE) samples
endif
	$(MAKE) thbook

override_dh_auto_clean:
	$(MAKE) clean

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-arch:
	# we need to clear out large generated files from samples before putting just source files in main package
	$(MAKE) -C samples clean
	mkdir -p debian/tmp/usr/bin debian/tmp/etc
	dh_auto_install -- PREFIX=$(CURDIR)/debian/tmp/usr SYSCONFDIR=$(CURDIR)/debian/tmp/etc
	rm debian/tmp/etc/*.new
	cd loch/locale && for lang in * ; do \
	  install -D "$$lang/loch.mo" "debian/tmp/therion-viewer/usr/share/locale/$$lang/LC_MESSAGES/loch.mo" ; \
	done
	dh_installexamples -ptherion --exclude=.tcl --exclude=Makefile --exclude=thTMPDIR samples therion.ini
