#!/usr/bin/make -f

PKD   = $(abspath $(dir $(MAKEFILE_LIST)))
PKG   = $(word 2,$(shell dpkg-parsechangelog -l$(PKD)/changelog | grep ^Source))
UVER  = $(shell dpkg-parsechangelog -l$(PKD)/changelog | perl -ne 'print $$1 if m{^Version:\s+(?:\d+:)?(\d.*)(?:\-\d+.*)};')
DTYPE =
VER  ?= $(subst $(DTYPE),,$(UVER))

DHFLAGS=--parallel

%:
	dh $@ $(DHFLAGS)

override_dh_install:
	rm -fv debian/tmp/usr/lib/*/*.la
	rm -rfv debian/tmp/usr/share/omf/
	rm -rfv debian/tmp/usr/share/help/
	rm -rfv debian/tmp/usr/share/MateConf/
	dh_install --fail-missing

override_dh_auto_configure:
	# upstream tarball is without configure. autogen.sh will create it
	NOCONFIGURE=1 ./autogen.sh
	dh_auto_configure $(DHFLAGS) -- \
		--disable-silent-rules \
		--libexecdir=/usr/lib/caja \
		--includedir=/usr/include/$(dpkg-architecture -qDEB_BUILD_MULTIARCH) \
		--disable-update-mimedb \
		--disable-static \
		--localstatedir=/var \
		--enable-unique \
		--enable-introspection

override_dh_auto_test:
	DEB_BUILD_OPTIONS=nocheck dh_auto_test

override_dh_strip:
	dh_strip -pcaja --dbg-package=caja-dbg
	dh_strip -plibcaja-extension1 --dbg-package=libcaja-extension1-dbg

get-orig-source: $(PKG)_$(VER)$(DTYPE).orig.tar.xz $(info I: $(PKG)_$(VER)$(DTYPE))
	@

$(PKG)_$(VER)$(DTYPE).orig.tar.xz:
	@echo "# Downloading..."
	uscan --noconf --verbose --rename --destdir=$(CURDIR) --check-dirname-level=0 --force-download --download-version $(VER) $(PKD)
