#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

NJOBS := -j$(shell getconf _NPROCESSORS_ONLN)

# No --with autoreconf here on purpose: libxml2 2.15 requires automake
# 1.16.3, which ubuntu16.04 and ubuntu18.04 do not have. The tarball ships
# a usable configure, so regenerating it buys nothing and breaks the old
# targets.
%:
	dh $@

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_MULTIARCH  ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
buildroot = $(CURDIR)/debian/tmp

override_dh_auto_configure:
	dh_testdir
	# xmllint and xmlcatalog need to find our own libxml2.so.16: it is not on
	# the system linker path and, unlike the 2.10.2 stream, there is no system
	# libxml2.so.2 for them to silently fall back to.
	# --with-legacy and --with-sax1 keep the interfaces the older PHP xml
	# extensions still reach for. Docs stay off: since 2.15 the man pages
	# are generated from DocBook through a remote XSL stylesheet.
	CC_FOR_BUILD=cc \
	LDFLAGS="$$LDFLAGS -Wl,-rpath=/opt/alt/libxml215/usr/lib/$(DEB_HOST_MULTIARCH),--enable-new-dtags" \
	./configure \
		--enable-static --enable-shared \
		--host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
		--prefix=/opt/alt/libxml215/usr \
		--datadir=/opt/alt/libxml215/usr/share \
		--libdir=/opt/alt/libxml215/usr/lib/$(DEB_HOST_MULTIARCH) \
		--with-html \
		--with-legacy \
		--with-sax1 \
		--without-python \
		--without-icu

override_dh_auto_build:
	$(MAKE) $(NJOBS) VERBOSE=1

override_dh_auto_install:
	$(MAKE) install DESTDIR=$(buildroot)
	find $(buildroot) -type f -name '*.la' -print -delete
	rm -rf $(buildroot)/opt/alt/libxml215/usr/share/doc

override_dh_auto_clean:
