#!/usr/bin/make -f

debian/control:: debian/control.in
DEB_PHONY_RULES += debina/control.in
debian/control.in::
	sed -e 's/__LIBPKGNAME__/$(libpkgname)/g' <debian/control.in.in >debian/control.in


include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/rules/utils.mk
-include /usr/share/cdbs/1/rules/upstream-tarball.mk

include /usr/share/cdbs/1/class/cmake.mk

stem = pugixml
major = $(firstword $(subst .,$(space),$(DEB_UPSTREAM_VERSION)))
libname = lib$(stem)
libpkgname = lib$(stem)$(major)
devpkgname = lib$(stem)-dev

# Handle upstream release
DEB_UPSTREAM_URL = https://github.com/zeux/pugixml/releases/download/v$(DEB_UPSTREAM_VERSION)
DEB_UPSTREAM_TARBALL_MD5 = 7c56c91cfe3ecdee248a8e4892ef5781

# Skip checking some images (in addition to the defaults)
DEB_COPYRIGHT_CHECK_IGNORE_REGEX = ^(docs/images/.*\.png|debian/(changelog|copyright(|_hints|_newhints)))$

# Build the shared library
DEB_CMAKE_EXTRA_FLAGS += -DBUILD_SHARED_LIBS=1

# We need this to build the package
CDBS_BUILD_DEPENDS += cmake, d-shlibs(>= 0.48), pkg-kde-tools

# Supress optional build dependencies
CDBS_BUILD_DEPENDS_rules_upstream_tarball =
CDBS_BUILD_DEPENDS_rules_utils_copyright_check =

# Multiarch quirks (should ideally be resolved automagically)
CDBS_BUILD_DEPENDS_rules_debhelper_buildinfo =
CDBS_BUILD_DEPENDS_rules_buildcore_pkgrel =
CDBS_PREDEPENDS = $(if $(DEB_HOST_MULTIARCH),multiarch-support)

# Fix the cmake invocation path
DEB_SRCDIR = scripts

# Docs installation
DEB_INSTALL_DOCS_$(stem)-doc += docs/manual docs/images docs/manual.html docs/pugixml.css docs/quickstart.html

# Install examples
DEB_INSTALL_EXAMPLES_$(devpkgname) += docs/samples

# Use only upstream version for dpkg-gensymbols
DEB_DH_MAKESHLIBS_ARGS_$(libpkgname) += -- -v$(DEB_UPSTREAM_VERSION)

# avoid unneeded .la file
binary-post-install/$(libpkgname):: debian/stamp-local-strip-la
debian/stamp-local-strip-la: binary-install/$(libpkgname)
	find debian -type f -name '*.la' -delete
	touch $@
clean::
	rm -f debian/stamp-local-strip-la

# Let d-shlibs calculate development package dependencies
#  and handle shared library install
binary-post-install/$(libpkgname) binary-post-install/$(devpkgname):: debian/stamp-local-shlibs-$(libname)
debian/stamp-local-shlibs-$(libname): binary-install/$(libpkgname) binary-install/$(devpkgname) debian/stamp-local-strip-la
	d-shlibmove --commit \
		--devunversioned \
		--multiarch \
		--override s/$(libname)$(major)-dev/$(libname)-dev/ \
		--movedev "debian/tmp/usr/include/*" usr/include/ \
		debian/tmp/usr/lib/$(libname).so
		touch $@
clean::
	rm -f debian/stamp-local-shlibs-$(libname)
