#!/usr/bin/make -f

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

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

LC_ALL:=C.UTF-8
export LC_ALL

S:=sed --posix

execute_after_dh_clean:
	rm -rf builddir

icop:=Copyright (c) Frank Wen, Michael Cowgill, and others; see ICMT chunk or Debian source package ${DEB_SOURCE} (= ${DEB_VERSION}) for entire terms and the MIT licence
ieng:=Fluid (R3) Mono GM by Church Organist; based on Fluid (R3) SoundFont by Frank Wen
sfbasename:=FluidR3Mono_GM
sfchangelog:=builddir/changelog.txt
override_dh_auto_build:
	rm -rf builddir
	mkdir builddir
	set -- FluidR3MonoChangeLog.txt; \
	    $S 's/\r$$//g' <"$$1" >${sfchangelog}
	set -- *.[Ss][Ff]2; \
	    cmt=$$($S '1,/^Licence:$$/d' debian/copyright | $S 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
	rm -f builddir/tmp.sf2

override_dh_installchangelogs:
	dh_installchangelogs ${sfchangelog}

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

%:
	dh $@
