#!/usr/bin/make -f
# -*- makefile -*-

export DH_VERBOSE=1

# Set temporary HOME for lazarus primary config directory
export HOME = $(CURDIR)/tmphome

# needed for reproducibility
export BUILD_DATE = $(shell date -d @$(SOURCE_DATE_EPOCH) +'%Y-%m-%d %H:%M:%S')
export LC_ALL = C.UTF-8
export TZ = UTC

%:
	dh $@

override_dh_auto_configure:
	if [ -f winff/presets.xml ] ; then mv winff/presets.xml winff/presets-orig.xml; fi

override_dh_auto_build-arch:
	lazbuild --widgetset=qt5 winff/winff.lpr
	mv winff/winff winff/winff-qt

override_dh_auto_build-indep:
# bug 768733: if $HOME does not exist, soffice fails to build pdf's
	mkdir -p $(CURDIR)/tmpoffice
	export HOME=$(CURDIR)/tmpoffice

	faketime -f '$(BUILD_DATE)' \
	/usr/bin/soffice --headless --convert-to pdf --outdir winff/docs winff/docs/WinFF.*.od?

# winff only searches pdf files for the first two characters of the language code,
# and we don't have a European Spanish or Portuguese translation yet.
	if [ ! -f winff/docs/WinFF.es.pdf ] ; then \
		mv winff/docs/WinFF.es_AR.pdf winff/docs/WinFF.es.pdf ; \
	fi ; true

	if [ ! -f winff/docs/WinFF.pt.pdf ] ; then \
		mv winff/docs/WinFF.pt_BR.pdf winff/docs/WinFF.pt.pdf ; \
	fi ; true

override_dh_compress:
	dh_compress -X.pdf

execute_before_dh_clean:
	if [ -f winff/presets-orig.xml ] ; then mv winff/presets-orig.xml winff/presets.xml; fi
