#!/usr/bin/make -f
# -*- makefile -*-
#export DH_VERBOSE=1

DEB_MAKE_FLAVORS = x nox
DEB_BUILDDIR = build
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk

# (Re)create autotools
include /usr/share/cdbs/1/rules/autoreconf.mk
CDBS_BUILD_DEPENDS +=, libltdl-dev, autoconf-archive
DEB_UPSTREAM_CRUFT_MOVE = m4/ax_check_compile_flag.m4 m4/ax_pthread.m4

stem = fontforge
major = 3
lib = lib$(stem)
libpkg =lib$(stem)$(major)
devpkg = lib$(stem)-dev

CDBS_BUILD_DEPENDS +=, autotools-dev, chrpath
CDBS_BUILD_DEPENDS +=, shared-mime-info, desktop-file-utils
CDBS_BUILD_DEPENDS +=, libreadline-dev, dh-python,

export CONFIG_SHELL=/bin/bash
export DEB_BUILD_MAINT_OPTIONS := hardening=+all

# For cross-friendly CC variable
-include /usr/share/dpkg/buildtools.mk

dev-deps = cairo2 freetype gif jpeg pango1.0 png spiro tiff5
dev-deps += uninameslist xml2 xt glib2.0 python3.8 woff gtk-3

CDBS_BUILD_DEPENDS +=, $(patsubst %,$(comma) lib%-dev,$(dev-deps))
CDBS_BUILD_DEPENDS +=, python3, python3-dev, uthash-dev
DEB_CONFIGURE_EXTRA_FLAGS = \
 --prefix=/usr \
 --libdir=\$${prefix}/lib \
 --mandir=\$${prefix}/share/man \
 --enable-tile-path \
 --enable-debug-raw-points \
 --enable-fontforge-extras \
 --enable-python-scripting=3 \
 --enable-python-extension PYTHON_LIBS='$(shell python3-config --ldflags --embed)'

DEB_CONFIGURE_FLAGS_x = --enable-gdk
DEB_CONFIGURE_FLAGS_nox = --without-x

DEB_DH_INSTALL_SOURCEDIR = debian/tmp/x
binary-install/fontforge-nox:: DEB_DH_INSTALL_SOURCEDIR = debian/tmp/nox

binary-install/python3-fontforge::
	find debian/python3-fontforge -name "*.la" -delete
	dh_python3 -ppython3-fontforge

binary-install/fontforge-common::
	find debian/fontforge-common/ -name "*.ttf" -delete

binary-fixup/python-fontforge::
	chmod -x \
		debian/python3-fontforge/usr/share/fontforge/python/simple/*.py

DEB_DH_STRIP_ARGS := '--dbgsym-migration=fontforge-dbg (<< 1:20170731~dfsg-2~)'
CDBS_BUILD_DEPENDS +=, d-shlibs (>= 0.88~)
binary-post-install/$(libpkg) binary-post-install/$(devpkg):: debian/stamp-local-shlibs-$(lib)
debian/stamp-local-shlibs-$(lib): binary-install/$(libpkg) binary-install/$(devpkg)
	d-shlibmove --commit \
		--devunversioned \
		--exclude-la \
		--extralib debian/tmp/x/usr/lib/libgunicode.so \
		--extralib debian/tmp/x/usr/lib/libgutils.so \
		--movedev "debian/tmp/x/usr/include/*" usr/include/ \
		--movedev "debian/tmp/x/usr/lib/pkgconfig/*.pc" usr/lib/${DEB_HOST_MULTIARCH}/pkgconfig \
		--override s/$(lib)$(major)-dev/$(lib)-dev/ \
		--override s/libpython3.8-1.0-dev/libpython3.8-dev/ \
		debian/tmp/x/usr/lib/$(lib).so
	touch $@
clean::
	rm -f debian/stamp-local-shlibs-$(lib)

# track symbols using pkgkde-symbolshelper
include /usr/share/pkg-kde-tools/makefiles/1/cdbs/symbolshelper.mk
CDBS_BUILD_DEPENDS +=, pkg-kde-tools
