#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export DEB_LDFLAGS_MAINT_APPEND=-Wl,--as-needed
export DEB_BUILD_MAINT_OPTIONS=hardening=+bindnow

# Disable ffmpeg-based codecs on i386, see https://github.com/Xpra-org/xpra/issues/3198
ifneq (,$(filter i386,$(DEB_HOST_ARCH)))
EXTRA_BUILDOPTS := --without-ffmpeg --without-csc_swscale --without-enc_ffmpeg --without-dec_avcodec2
endif
BUILDOPTS= --with-verbose --with-Xdummy --without-Xdummy_wrapper --with-vpx --with-ffmpeg --without-enc_ffmpeg $(EXTRA_BUILDOPTS)

export PYBUILD_CONFIG_ARGS=$(BUILDOPTS)
export PYBUILD_BUILD_ARGS=$(BUILDOPTS)
export PYBUILD_INSTALL_ARGS=$(BUILDOPTS) --root=$(CURDIR)/debian/tmp
export PYBUILD_DISABLE=test

%:
	dh $@ --buildsystem=pybuild

override_dh_auto_build:
	sh html5/build-vendor.sh
	dh_auto_build

override_dh_auto_clean:
	sh html5/clean-vendor.sh
	dh_auto_clean

override_dh_installchangelogs:
	dh_installchangelogs docs/CHANGELOG.md

override_dh_auto_install:
	dh_auto_install
	# Keep build metadata from the default interpreter when merging Python modules.
	set -e; default_python=$$(py3versions -d); \
	    test -f debian/tmp/usr/lib/$$default_python/dist-packages/xpra/build_info.py; \
	    for python in $$(py3versions -s); do \
	        if [ "$$python" != "$$default_python" ]; then \
	            rm -f debian/tmp/usr/lib/$$python/dist-packages/xpra/build_info.py; \
	        fi; \
	    done
	install -d debian/tmp/usr/share/xpra/www
	cp -a html5/html5/. debian/tmp/usr/share/xpra/www/
	# Normalize source-only component timestamps without following system links.
	find debian/tmp/usr/share/xpra/www \( -type f -o -type d \) -exec touch --date="@$(SOURCE_DATE_EPOCH)" {} +
	# Post-install clean-up
	$(RM) -v debian/tmp/usr/share/xpra/COPYING debian/tmp/usr/bin/xpra_Xdummy debian/tmp/usr/share/xpra/README.md
	
	@-printf "~~~~ Generated contents of conf.d/55_server_x11.conf\n"
	-grep -v ^# debian/tmp/etc/xpra/conf.d/55_server_x11.conf
	@-printf "~~~~\n"

override_dh_installinit:
	dh_installinit -v --no-enable --no-start

override_dh_installsystemd:
	dh_installsystemd -v --no-enable --no-start

override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3
	dh_python3 --shebang=/usr/bin/python3 /usr/lib/cups/backend
