#!/usr/bin/make -f

%:
	dh $@

TMP=$(CURDIR)/debian/padre
FAKE_HOME=$(CURDIR)/debian/fake-home

./share/languages/perl5/perlapi_current.yml:
	perl -MPerl::APIReference -MConfig -e 'print Perl::APIReference->new(perl_version => $$Config{version})->as_yaml_calltips() . "\n";' > ./share/languages/perl5/perlapi_current.yml

override_dh_auto_configure: ./share/languages/perl5/perlapi_current.yml
	SKIP_WXWIDGETS_VERSION_CHECK=1 xvfb-run -a dh_auto_configure

override_dh_auto_test:
	[ -d $(FAKE_HOME) ] || mkdir -p $(FAKE_HOME)
	HOME=$(FAKE_HOME) xvfb-run dh_auto_test
	rm -rf $(FAKE_HOME)

PERLOPQUICK := $(TMP)/usr/share/perl5/auto/share/dist/Padre/doc/perlopquick
LOCALE    := $(TMP)/usr/share/perl5/auto/share/dist/Padre/locale/
TIMELINE  := $(TMP)/usr/share/perl5/auto/share/dist/Padre/timeline
DISTPADRE := $(TMP)/usr/share/perl5/auto/share/dist/Padre/
LIB       := $(TMP)/usr/share/perl5/Padre

override_dh_auto_install:
	dh_auto_install
	mkdir -p $(TMP)/usr/share/pixmaps
	convert \
	    $(DISTPADRE)/icons/padre/16x16/logo.png \
	    $(TMP)/usr/share/pixmaps/padre.xpm
	# remove cruft from perlopquick directory
	rm  $(PERLOPQUICK)/Copying  \
	    $(PERLOPQUICK)/Artistic \
	    $(PERLOPQUICK)/README

	# fix permissions
	chmod 0644 $(DISTPADRE)/padre.desktop

	# remove cc-by-nc-sa (non DFSG) splash file (Padre's code
	# gracefully fallack to a DFSG-ok file). See share/README.txt
	# for license details
	rm $(DISTPADRE)/padre-splash-ccnc.png

	# these manuals are empty, only containing stubs
	cat debian/not-real-manual.list | while read size f; do \
	    ff=$${f#lib/} ; \
	    mf=$(TMP)/usr/share/man/man3/`echo $${ff%.pm} | sed s,/,::,g`.3pm ; \
	    fs=`wc -c $$f | cut -d' ' -f1` ; \
	    if [ $$fs = $$size ]; then \
		rm -v $$mf ; \
	    else \
		echo "stale entry in debian/not-real-manual.list: $$f ($$mf) ($$size != $$fs)" ; \
	    fi ; \
	done

.PHONY: get-orig-source
get-orig-source:
	uscan --force
