#!/usr/bin/make -f
# -*- makefile -*-
# debian/rules for the Praat

DEBDIR = $(CURDIR)/debian
INSTDIR = $(DEBDIR)/praat

PIXDIR = usr/share/pixmaps
BINDIR = usr/bin
APPDIR = usr/share/applications

SUBSTCMD = sed 's:@BINDIR@:$(BINDIR):g;s:@PIXDIR@:$(PIXDIR):g;	\
		s:@APPDIR@:$(APPDIR):g'

%:
	dh $@

get-upstream-changelog:
	# Get upstream changelog (in HTML format) and replace some characters
	# for correct display in the final ASCII file
	( cd debian ;							    \
	  wget -N http://www.fon.hum.uva.nl/praat/manual/What_s_new_.html ; \
	  perl -pi -e "s/&#712;/'/g;s/&#716;/,/g;" What_s_new_.html )

clean:
	dh clean
	# Fix the lacking cleaning command for the main/ directory
	rm -f makefile.defs $(DEBDIR)/praat.dirs		\
		 $(DEBDIR)/praat.install $(DEBDIR)/praat.menu

override_dh_auto_configure:
	# Generate the debhelper files
	for i in dirs install menu ; do 				\
		$(SUBSTCMD) < $(DEBDIR)/$$i.in > $(DEBDIR)/praat.$$i ;	\
	done
	# Get rid of the
	# dpkg-shlibdeps: warning: dependency on lib??? could be avoided if "debian/praat/usr/bin/praat" were not uselessly linked against it (they use none of its symbols).
	# warnings and useless dependencies
	sed 's/^LIBS = /& -Wl,--as-needed /'	\
		makefiles/makefile.defs.linux > makefile.defs

override_dh_auto_install::
	# Install the upstream changelog
	dh_installchangelogs debian/What_s_new_.html
	rm -f $(INSTDIR)/usr/share/doc/praat/changelog.html
	dh_auto_install

override_dh_auto_clean::
	[ ! -f makefile.defs ] || make -C main clean
