#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#DH_VERBOSE = 1

# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

# see FEATURE AREAS in dpkg-buildflags(1)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

#export DEB_CPPFLAGS_MAINT_STRIP = -D_FORTIFY_SOURCE=2
export DEB_LDFLAGS_MAINT_APPEND = -ldl -Wl,-z,defs -lpthread

export DPKG_GENSYMBOLS_CHECK_LEVEL=4

# Prevent autoreconf from trashing the build:
# Pion's config.hpp.in isn't meant to be processed with autoheader
export AUTOHEADER=/bin/true

DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

# main packaging script based on dh7 syntax
%:
	dh $@ --with autoreconf

override_dh_auto_configure:
	dh_auto_configure -- \
	--prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info --enable-shared --disable-static --with-gnu-ld --with-pic --with-openssl --with-zlib --with-bzlib --with-log4cpp
ifeq (aarch64-linux-gnu,$(DEB_BUILD_GNU_TYPE))
	# Build tests unoptimized on arm64; building optimized on arm64 causes a failure
	sed -i 's/O2/O0/g' tests/Makefile tests/plugins/Makefile
endif

override_dh_auto_build:
	dh_auto_build
	make docs
	# We don't want upstream embedding jquery, which we will link later
	rm -f $(CURDIR)/doc/html/jquery.js

override_dh_auto_install-arch:
	dh_auto_install
	cp $(CURDIR)/services/*.hpp $(CURDIR)/debian/libpion-dev/usr/include/pion/plugins/

override_dh_auto_clean:
	dh_auto_clean
	rm -rf doc/html doc/pion-net.tag

override_dh_strip:
	dh_strip --dbgsym-migration='libpion-5.0-dbg (<< 5.0.7+dfsg-1~), libpion-plugins-dbg (<< 5.0.7+dfsg-1~)' || dh_strip

get-orig-source:
	uscan --watchfile $(CURDIR)/debian/watch.get-orig-source --verbose --force-download --no-symlink --destdir ..

