#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

## use hardening flags
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

archconfflags := \
	--prefix=/usr \
	--with-pd=/usr/include/pd \
	--with-extension=pd_linux \
	--enable-mmx \
	--without-ALL \
	--with-glew \
	--with-ftgl \
	--with-ImageMagick \
	--with-jpeg \
	--with-tiff \
	--with-lqt \
	--with-libquicktime \
	--with-gmerlin_avdec \
	--with-libmpeg3 \
	--without-v4l \
	--without-libv4l1 \
	--with-v4l2 \
	--with-libv4l2 \
	--with-libdv \
	--with-libdc1394_2 \
	--with-libiec61883 \
	--with-libraw1394 \
	--with-unicap \
	--with-libunicap \
	--with-default-font=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf

%:
	dh --with autoreconf $@

override_dh_auto_configure:
	CXXFLAGS="$(CXXFLAGS)" CFLAGS="$(CFLAGS)" ./configure $(archconfflags)

override_dh_auto_test:
	# no actual 'make test' target

override_dh_install:
	dh_install
	# remove libtool files, they are not needed
	find debian/gem-extra/usr/lib/ -name '*.la'  -delete
	# remove some assets
	if [ -d debian/gem-doc ]; then \
	 find debian/gem-doc/usr/share/ -name '*.ttf' -delete; \
	 find debian/gem-doc/usr/share/ -name '*.avi' -delete; \
	 find debian/gem-doc/usr/share/ -name '*.mov' -delete; \
	 find debian/gem-doc/usr/share/ -name '*.mpg' -delete; \
	fi
	# the following COPYING only contains license information for vera.ttf
	# which is not included in the Debian package
	if [ -d debian/gem-doc ]; then rm debian/gem-doc/usr/share/gem/examples/data/COPYING.txt; fi
	# remove extra LICENSE files for gem-extra
	rm debian/gem-extra/usr/lib/pd/extra/pix_mano/LICENSE.txt
	rm debian/gem-extra/usr/lib/pd/extra/pix_drum/LICENSE.txt

# calculate proper dependencies (for .pd_linux files)
override_dh_shlibdeps:
	dh_shlibdeps
	find debian/gem -name "*.pd_linux" -exec \
		dpkg-shlibdeps -Tdebian/gem.substvars {} +
	find debian/gem-extra -name "*.pd_linux" -exec \
		dpkg-shlibdeps -Tdebian/gem-extra.substvars {} +

override_dh_strip:
	dh_strip
	find debian -name "*.pd_linux" -exec \
		strip --remove-section=.comment --remove-section=.note --strip-unneeded {} +


override_dh_fixperms:
	dh_fixperms -Xpd-gem
	chmod 0755 debian/gem/usr/bin/pd-gem
	find debian -name '*.pd_linux' -exec \
		chmod 0644 {} +

override_dh_compress:
	dh_compress -X.pd -X.TIF -X.obj
