#!/usr/bin/make -f

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

shellescape='$(subst ','\'',$(1))'
shellexport=$(1)=$(call shellescape,${$(1)})

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

OUR_CPPFLAGS:=
OUR_CFLAGS:=
OUR_CXXFLAGS:=
OUR_LDFLAGS:=

OUR_CFLAGS+=	-Wno-unused-parameter
OUR_CXXFLAGS+=	-Wno-unused-parameter
OUR_CFLAGS+=	-Wno-unused-result
OUR_CXXFLAGS+=	-Wno-unused-result

# unclutter build log; these are upstream’s to fix
OUR_CFLAGS+=	-Wno-deprecated-declarations
OUR_CXXFLAGS+=	-Wno-deprecated-declarations
OUR_CXXFLAGS+=	-Wno-deprecated-copy

CONFIG_ARGS+=	CONFIG+=disable_version_check
# blocked by #686777
#CONFIG_ARGS+=	CONFIG+=opus_shared_lib

dpkgbuildflagsmkescape=$(subst \,\\\,$(1))
export DEB_BUILD_MAINT_OPTIONS:=hardening=+all
export DEB_CPPFLAGS_MAINT_APPEND:=$(call dpkgbuildflagsmkescape,${OUR_CPPFLAGS})
export DEB_CFLAGS_MAINT_APPEND:=$(call dpkgbuildflagsmkescape,${OUR_CFLAGS})
export DEB_CXXFLAGS_MAINT_APPEND:=$(call dpkgbuildflagsmkescape,${OUR_CXXFLAGS})
export DEB_LDFLAGS_MAINT_APPEND:=$(call dpkgbuildflagsmkescape,${OUR_LDFLAGS})
include /usr/share/dpkg/buildflags.mk
include /usr/share/dpkg/buildtools.mk

# work around a bug in /usr/share/perl5/Debian/Debhelper/Buildsystem/qmake.pm
# which correctly merges CPPFLAGS to CFLAGS/CXXFLAGS for the compiler but
# misses adding C{,XX}FLAGS to LDFLAGS for the linker (CCLD/CXXLD)…
LDFLAGS:=${LDFLAGS} ${CXXFLAGS} # as this links with ${CXX}

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- ${CONFIG_ARGS}

execute_after_dh_auto_install:
	# remove “too much” installed files…
	rm -f debian/jamulus/usr/share/applications/jamulus-server.desktop
	# fixup icon mess
	mkdir -p debian/jamulus/usr/share/icons/hicolor/scalable/apps
	rm -rf debian/jamulus/usr/share/icons/hicolor/512x512