#!/usr/bin/make -f
# -*- makefile -*-

# defined for most of the code anyway; doing this here helps the PCH
OUR_CPPFLAGS := -DQT_NO_DEBUG
# 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

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

override_dh_auto_configure:
	dh_auto_configure -- ${CMAKE_DEFS}

override_dh_auto_build:
	dh_auto_build -- lrelease all

override_dh_installchangelogs-arch:
	dh_installchangelogs -pmusescore debian/upstream/changelog
	dh_installchangelogs --remaining-packages

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

.PHONY: get-orig-source
## Usage: debian/rules get-orig-source
## Based on: http://wiki.debian.org/onlyjob/get-orig-source
get-orig-source: PKG_DIR:=$(abspath $(dir $(MAKEFILE_LIST)))
get-orig-source:
	# Simply call uscan (changes for DFSG done in debian/watch and debian/repack)
	uscan --noconf --verbose --destdir=$(CURDIR) \
	  --check-dirname-level=0 --force-download $(PKG_DIR)
