#!/usr/bin/make -f

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

# defined for most of the code anyway; doing this here helps the PCH
OUR_CPPFLAGS := -DQT_NO_DEBUG
# avoid stray debugging output
OUR_CPPFLAGS += -DNDEBUG
# disable phoning home
OUR_CPPFLAGS += -DMSCORE_NO_UPDATE_CHECKER

export DEB_BUILD_MAINT_OPTIONS := hardening=+all
export DEB_LDFLAGS_MAINT_APPEND := -Wl,--as-needed
export DEB_CPPFLAGS_MAINT_APPEND := ${OUR_CPPFLAGS}

# better debugging if requested
ifneq (,$(findstring optdbg,${DEB_BUILD_OPTIONS}))
export DEB_CFLAGS_MAINT_APPEND := -Og
export DEB_CXXFLAGS_MAINT_APPEND := -Og
endif

DEB_HOST_ARCH_OS?=$(shell dpkg-architecture -qDEB_HOST_ARCH_OS)

%:
	dh $@ --buildsystem=cmake --parallel

CMAKE_DEFS:=	-DCMAKE_SKIP_RPATH=ON
CMAKE_DEFS+=	-DDOWNLOAD_SOUNDFONT=OFF
CMAKE_DEFS+=	-DUSE_SYSTEM_FREETYPE=ON \
		-DFREETYPE_INCLUDE_DIRS=/usr/include/freetype2/

ifneq (linux,${DEB_HOST_ARCH_OS})
CMAKE_DEFS+=	-DBUILD_PORTMIDI=OFF
endif

# disable phoning home
CMAKE_DEFS+=	-DBUILD_WEBKIT=OFF

override_dh_auto_configure:
	dh_auto_configure -- ${CMAKE_DEFS}

override_dh_auto_build:
	env GNUMAKEFLAGS="$$GNUMAKEFLAGS --output-sync" \
	    dh_auto_build -- lrelease all

override_dh_auto_test:
	@echo 'I: tests broken on older than buster, not running for backports'

override_dh_install-indep:
	# move stuff to packages
	dh_install
	# make system-wide soundfonts available
	cd debian/musescore-common/usr/share/mscore-* && \
	    mkdir -p sound && \
	    ln -sf ../../sounds/sf2 ../../sounds/sf3 ../../sounds/sfz sound/
