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

export SHELL=/bin/bash
export MOZ_NOSPAM:=1
export LDFLAGS+=-Wl,--no-keep-memory
export TODAY_DATE=$(shell date +%Y-%m-%d)
export MOZ_SOURCE_CHANGESET=$(shell source debian/tar_stamps && echo "$$RELEASE_TAG")
export SOURCE_REPO=$(shell source debian/tar_stamps && echo "$$RELEASE_REPO")
export source_repo=$(shell source debian/tar_stamps && echo "$$RELEASE_REPO")
export MOZ_SOURCE_REPO=$(shell source debian/tar_stamps && echo "$$RELEASE_REPO")
export MOZ_SOURCE_STAMP=$(shell source debian/tar_stamps && echo "$$RELEASE_TAG")

%:
	dh $@

override_dh_auto_clean:
	rm -f .mozconfig
	dh_auto_clean
	find . -name '*.pyc' -delete

override_dh_auto_configure:
	cp debian/mozconfig mozconfig

override_dh_auto_build:
	# LTO needs more open files
	ulimit -n 4096; xvfb-run -a -n 97 -s "-screen 0 1920x1080x24" ./mach build

override_dh_auto_install:
	chmod +x $$(pwd)/debian/waterfox-current-bin.sh
	DESTDIR=$$(pwd)/debian/waterfox-current-kpe ./mach install
	rm -rf $$(pwd)/debian/waterfox-current-kpe/usr/lib/waterfox-current/dictionaries
	sed -i "s/__DATE__/$$TODAY_DATE/g" $$(pwd)/debian/waterfox-current.appdata.xml.in
	sed -e "s/__VERSION__/$$(<browser/config/version_display.txt)/g" $$(pwd)/debian/waterfox-current.appdata.xml.in > $$(pwd)/debian/waterfox-current-kpe/usr/share/metainfo/waterfox-current.appdata.xml
	mv $$(pwd)/debian/waterfox-current-wayland-bin.sh $$(pwd)/debian/waterfox-current-wayland/usr/bin/waterfox-current-wayland

override_dh_shlibdeps:
	dh_shlibdeps -l /usr/lib/waterfox-current/waterfox-current

override_dh_strip_nondeterminism:
	dh_strip_nondeterminism -Xdebian/waterfox-current-kpe/usr/lib/waterfox-current/browser/features/formautofill@mozilla.org.xpi
