#!/usr/bin/make -f
export DH_VERBOSE = 1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
export DPKG_GENSYMBOLS_CHECK_LEVEL = 4

%:
	dh $@ --buildsystem cmake

override_dh_auto_configure:
	dh_auto_configure -- \
	      -DCMAKE_BUILD_TYPE=RelWithDebInfo \
	      -DCMAKE_LIBRARY_ARCHITECTURE="$(DEB_TARGET_MULTIARCH)" \
	      -DWHISPER_USE_SYSTEM_GGML=ON \
	      -DWHISPER_SDL2=ON \

execute_after_dh_auto_install:
	mkdir -p debian/tmp/usr/share/sounds/debian/samples
	# Convert English sample to lightweight portable WAV
	ffmpeg -acodec libvorbis -i debian/tests/samples/Wikipedia_Ignore_All_Rules.ogx \
	 -acodec pcm_s16le -ac 1 -ar 16000 \
	 debian/tmp/usr/share/sounds/debian/samples/en-Wikipedia-Ignore_All_Rules.wav
	# Shorten and convert Arabic sample to lightweight portable WAV
	ffmpeg -ss 00:00:00 -to 00:00:51 -i debian/tests/samples/ويكيبيديا_الركائز_الخمس.ogx \
	 -acodec pcm_s16le -ac 1 -ar 16000 \
	 debian/tmp/usr/share/sounds/debian/samples/ar-Wikipedia-Five_Pillars.wav
	find debian/tmp -name 'whisper-config.cmake' -exec sed -i \
	  -e 's/^set(WHISPER_BUILD_COMMIT .*$$/set(WHISPER_BUILD_COMMIT "")/' \
	  -e 's/^set(WHISPER_BUILD_NUMBER .*$$/set(WHISPER_BUILD_NUMBER "0")/' {} +

# Disabled for now, needs data with uncertain license
override_dh_auto_test:
	:
