#!/usr/bin/make -f

## Enable compiler hardening flags.
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

%:
	dh $@ --parallel

override_dh_auto_configure:
	dh_auto_configure -- -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCREDITSDIR=/usr/share/doc/rawtherapee -DLICENCEDIR=/usr/share/doc/rawtherapee

override_dh_install-arch:
	dh_install
	convert -geometry 32x32 rtdata/icons/hi32-app-rawtherapee.png debian/rawtherapee/usr/share/pixmaps/rawtherapee.xpm
	rm debian/rawtherapee/usr/share/doc/rawtherapee/LICENSE.txt

override_dh_install-indep:
	dh_install
	rm debian/rawtherapee-data/usr/share/rawtherapee/languages/LICENSE

SRC_VERSION := $(shell dpkg-parsechangelog | sed -ne 's/^Version: \(.*\)\.*-.*/\1/p')
.PHONY: get-orig-source
get-orig-source:
	rm -rf get-orig-source rawtherapee-$(SRC_VERSION).orig.tar.gz
	mkdir get-orig-source
	hg clone https://rawtherapee.googlecode.com/hg/ get-orig-source/rawtherapee-$(SRC_VERSION).orig
	hg -R get-orig-source/rawtherapee-$(SRC_VERSION).orig checkout $(SRC_VERSION)
    
	# Outdated documentation
	rm -r get-orig-source/rawtherapee-$(SRC_VERSION).orig/doc
	# Stuff we don't need
	rm get-orig-source/rawtherapee-$(SRC_VERSION).orig/languagePack.nsi
	rm -r get-orig-source/rawtherapee-$(SRC_VERSION).orig/tools
	# Mercurial files
	rm -r get-orig-source/rawtherapee-$(SRC_VERSION).orig/.hg
	rm get-orig-source/rawtherapee-$(SRC_VERSION).orig/.hgignore
	rm get-orig-source/rawtherapee-$(SRC_VERSION).orig/.hgtags
    
	tar cJf rawtherapee_$(SRC_VERSION).orig.tar.xz -C get-orig-source rawtherapee-$(SRC_VERSION).orig
	rm -rf get-orig-source
