#!/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

# For the repack: package name, mangled upstream version, non-free files
PACKAGE := libpano13
VERSION := $(shell dpkg-parsechangelog | perl -ne 'print "$$1\n" if (/^Version: (.*?)(?:\+dfsg)?\-.*?$$/)')


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-2 (>=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

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

	# Extract and prune non-free files
	tar xfz ../$(PACKAGE)_$(VERSION).orig.tar.gz
	find $(PACKAGE)-$(VERSION) \( -name '*.rc' -or -name '*.vcproj' \
		-or -name '*.sln' -or -name '*.vsprops' \) -type f -delete

	# Rename, repack and clean
	mv $(PACKAGE)-$(VERSION) $(PACKAGE)-$(VERSION).orig
	tar cfz ../$(PACKAGE)_$(VERSION)+dfsg.orig.tar.gz $(PACKAGE)-$(VERSION).orig
	rm -rf $(PACKAGE)-$(VERSION).orig

%:
	dh $@ --with autoreconf
