#!/usr/bin/make -f
%:
	dh $@

override_dh_auto_configure:
	# We ship Debian's gnulib as a supplementary tarball, see README.Source
	make -f Smake GNULIB=gnulib
	dh_auto_configure -- --prefix=/usr --sysconfdir=/etc --without-libreadline-prefix

override_dh_auto_build:
	# Commands to compile the package.
	dh_auto_build -- all html pdf

override_dh_auto_test:
	# Post the testsuite results to the build log on failures
	dh_auto_test || { cat $(CURDIR)/tests/testsuite.log; false; }

override_dh_auto_install:
	# Add here commands to install the package into debian/pspp
	dh_auto_install

	# Remove unwanted info dir file if auto-generated
	rm -f $(CURDIR)/debian/pspp/usr/share/info/dir $(CURDIR)/debian/pspp/usr/share/info/dir.*

	# Install Emacsen file
	install -m 644 $(CURDIR)/pspp-mode.el $(CURDIR)/debian/pspp/usr/share/emacs/site-lisp/pspp/pspp-mode.el

	# Install icon files & remove icon cache if present
	cp $(CURDIR)/debian/pspp.svg $(CURDIR)/debian/pspp/usr/share/icons/hicolor/scalable/apps/pspp.svg
	rsvg-convert -a -w 48 -h 48 $(CURDIR)/debian/pspp.svg -o $(CURDIR)/debian/pspp/usr/share/icons/hicolor/48x48/apps/pspp.png
	rsvg-convert -a -w 64 -h 64 $(CURDIR)/debian/pspp.svg -o $(CURDIR)/debian/pspp/usr/share/icons/hicolor/64x64/apps/pspp.png
	rm -f $(CURDIR)/debian/pspp/usr/share/icons/hicolor/icon-theme.cache

	# Empty dependency_libs
	sed -i "/dependency_libs/ s/'.*'/''/" `find . -name '*.la'`

override_dh_compress:
	dh_compress --exclude=.pdf --exclude=.xml
