#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

ifeq (,$(findstring terse,${DEB_BUILD_OPTIONS}))
export DH_VERBOSE=1
export V=1
export VERBOSE=1
endif

LC_ALL:=C
export LC_ALL

override_dh_clean:
	dh_clean
	rm -rf builddir

icop:=Copyright (c) Frank Wen, Michael Cowgill, S. Christian Collins, and others; see ICMT chunk or Debian source package ${DEB_SOURCE} (= ${DEB_VERSION}) for entire terms and the MIT licence
ieng:=MuseScore_General by S. Christian Collins; based on Fluid (R3) Mono by Church Organist
sfbasename:=MuseScore_General_Full
override_dh_auto_build:
	rm -rf builddir
	mkdir builddir
	LC_ALL=C.UTF-8; export LC_ALL; set -- *.sf2; \
	    cmt=$$(sed '1,/^Licence:$$/d' debian/copyright | sed 1d; echo x); \
	    python3 debian/riffedit.py "$$1" builddir/tmp.sf2 \
	    -az 'LIST<INFO>/INAM' '${sfbasename}.sf3' \
	    -az 'LIST<INFO>/ICOP' '${icop}' \
	    -az 'LIST<INFO>/IENG' '${ieng}' \
	    -az 'LIST<INFO>/ICMT' "$${cmt%x}"
	sf3convert -S 0 -q 0.8 -a -1 -z \
	    builddir/tmp.sf2 builddir/${sfbasename}.sf3
	LC_ALL=C.UTF-8; export LC_ALL; python3 debian/riffedit.py \
	    builddir/tmp.sf2 builddir/${sfbasename}.sf2 \
	    -az 'LIST<INFO>/INAM' '${sfbasename}.sf2'
	rm -f builddir/tmp.sf2

override_dh_installchangelogs:
	dh_installchangelogs MuseScore_General-changelog.md

override_dh_builddeb:
	dh_builddeb -- --no-uniform-compression

%:
	dh $@
