#!/usr/bin/make -f

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_ARCH_OS    ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -g
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

ifeq (linux,$(DEB_HOST_ARCH_OS))
	EXTRA_CONFIGURE := --enable-capabilities
endif

export DEB_LDFLAGS_MAINT_APPEND=-Wl,--as-needed

%:
	dh $@ --parallel --with autoreconf

override_dh_autoreconf:
	dh_autoreconf --as-needed

override_dh_auto_configure:
	dh_auto_configure -- \
                      --enable-mpg123=/usr/bin/mpg321 \
                      $(EXTRA_CONFIGURE) \
                      gnomedatadir=/usr/share/ \
                      gnomepresent=yes
	find -name '*.xml' -exec perl -i -pe 's,http://www.oasis-open.org/docbook/xml/([^/]+)/docbookx.dtd,/usr/share/sgml/docbook/dtd/xml/\1/docbookx.dtd,' {} \;

override_dh_auto_clean:
	dh_auto_clean
	rm -f src/license.c
	find -name '*.xml' -exec perl -i -pe 's,/usr/share/sgml/docbook/dtd/xml/([^/]+)/docbookx.dtd,http://www.oasis-open.org/docbook/xml/\1/docbookx.dtd,' {} \;

override_dh_auto_install:
	dh_auto_install
	(cd gnome-support && \
	 cp terminatorX-app.xpm $(CURDIR)/debian/terminatorx/usr/share/pixmaps)

override_dh_install:
	dh_install
	mv debian/terminatorx/usr/share/gnome/apps/Multimedia/terminatorX.desktop \
		debian/terminatorx/usr/share/applications/
	find debian/terminatorx -type d -empty -delete
