#!/usr/bin/make -f

export DEB_CFLAGS_MAINT_APPEND := -Wall
export DEB_CXXFLAGS_MAINT_APPEND := -Wall
export DEB_LDFLAGS_MAINT_APPEND := -Wl,-z,defs -Wl,--as-needed
export DEB_BUILD_MAINT_OPTIONS := hardening=+all
include /usr/share/dpkg/pkg-info.mk

# For the repack: package name, mangled upstream version, non-free files
UVERNODFSG = $(subst +dfsg,,$(DEB_VERSION_UPSTREAM))


override_dh_auto_configure:
	dh_auto_configure --verbose -- \
		--enable-shared --enable-static \
		--with-jpeg --with-png --with-tiff \
		--with-zlib --without-java LIBS="-lm"

#override_dh_makeshlibs:
#	dh_makeshlibs -V 'libpano13-3 (>=2.9.18)'

override_dh_auto_install:
	dh_auto_install --verbose
	# Clear the rpath set on some architectures (e.g. amd64)
	chrpath -d $(CURDIR)/debian/tmp/usr/bin/* \
		$(CURDIR)/debian/tmp/usr/lib/*/*.so
	rm -vf $(CURDIR)/debian/tmp/usr/lib/*/*.la

override_dh_install:
	dh_install --fail-missing

override_dh_autoreconf:
	dh_autoreconf --as-needed

# Build the DFSG-free source tarball
get-orig-source:
	# Download
	uscan --force-download --rename

	# Extract and prune non-free files
	tar xf ../$(DEB_SOURCE)_$(UVERNODFSG).orig.tar.gz
	# Rename, clean and repack.
	mv -v $$(tar tf ../$(DEB_SOURCE)_$(UVERNODFSG).orig.tar.gz | head -n1) \
		$(DEB_SOURCE)-$(UVERNODFSG).orig
	find $(DEB_SOURCE)-$(UVERNODFSG).orig \
		\( -name '*.rc' -or -name '*.vcproj' \
		-or -name '*.sln' -or -name '*.vsprops' -or \
		-name '*.vcxproj' \) -type f -delete
	tar cJf ../$(DEB_SOURCE)_$(UVERNODFSG)+dfsg.orig.tar.xz \
		$(DEB_SOURCE)-$(UVERNODFSG).orig
	rm -rf $(DEB_SOURCE)-$(UVERNODFSG).orig

%:
	dh $@
