#!/usr/bin/make -f

include /usr/share/dpkg/buildtools.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export CC

EXTRA_LFLAGS:="$(shell dpkg-buildflags --get LDFLAGS) -Wl,-soname,libre.so.0"
EXTRA_CFLAGS:="$(shell dpkg-buildflags --get CPPFLAGS)"

# relax symbols check when targeting experimental
EXP_RELEASE = $(filter experimental% UNRELEASED,\
 $(shell dpkg-parsechangelog | grep -Po '^Distribution: \K.*'))
export DPKG_GENSYMBOLS_CHECK_LEVEL=$(if $(EXP_RELEASE),0,1)

override_dh_auto_configure:
	sed -e 's,@\$$(CC),\$$(CC),' \
		-e 's,@\$$(LD),\$$(LD),' \
		-e 's,@\$$(AR),\$$(AR),' \
		-e 's,@rm -rf,rm -rf,' < Makefile > GNUmakefile

override_dh_auto_build:
	dh_auto_build -- info all \
		RELEASE=1 \
		USE_OPENSSL=1 \
		EXTRA_LFLAGS=$(EXTRA_LFLAGS) \
		EXTRA_CFLAGS=$(EXTRA_CFLAGS) \
		LIB_SUFFIX=.so.0

LIBDIR=/usr/lib/$(DEB_TARGET_MULTIARCH)

override_dh_auto_install:
	dh_auto_install -- \
		LIBDIR=$(LIBDIR) \
		LIB_SUFFIX=.so.0
	cd debian/tmp/$(LIBDIR) && \
		ln -s -f libre.so.0 libre.so
	sed -i "s,libdir=\$${prefix}/lib,libdir=\$${prefix}/lib/$(DEB_TARGET_MULTIARCH)," debian/tmp/$(LIBDIR)/pkgconfig/libre.pc

override_dh_auto_clean:
	make clean LIB_SUFFIX=.so.0
	rm -f GNUmakefile

override_dh_auto_test:

%:
	dh $@ --with pkgkde_symbolshelper
