#!/usr/bin/make -f

#export DH_VERBOSE=1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export QT_SELECT=6

%:
	dh $@

# On ENABLE_DEPRECATED=ON:
#      build system makes deprecations failures if $CI is not empty:
#      force enable of deprecations (e.g. GTK)
override_dh_auto_configure:
	dh_auto_configure --				\
		-DINSTALL_LIB=ON			\
		-DENABLE_CLI=ON				\
		-DENABLE_GTK=ON				\
		-DENABLE_QT=ON				\
		-DUSE_QT_VERSION=$(QT_SELECT)		\
		-DENABLE_DEPRECATED=ON \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo

%.css: %.scss
	rsass $< > $@

WEBUI_SOURCES := $(wildcard web/src/*.js)

.PHONY: webui

webui: web/assets/css/transmission-app.css $(WEBUI_SOURCES)
	mkdir -p web/node_modules
	ln -sf /usr/share/nodejs/lodash.isequal web/node_modules/
	cd web && esbuild \
		--allow-overwrite \
		--bundle \
		--legal-comments=external \
		--loader:.png=dataurl \
		--loader:.svg=dataurl \
		--minify \
		--sourcemap \
		--outfile=public_html/transmission-app.js \
		src/main.js

execute_before_dh_auto_build: webui

override_dh_auto_test:
	@echo "skipping auto test"

execute_after_dh_auto_install:
	@echo "remove extra license file"
	-rm --verbose debian/tmp/usr/share/doc/transmission/COPYING

override_dh_installdocs:
	dh_installdocs --link-doc=transmission-common
