#!/usr/bin/make -f

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


DOCDIR=$(CURDIR)/debian/sawfish-themes/usr/share/doc/sawfish-themes
THEMEDIR=$(CURDIR)/debian/sawfish-themes/usr/share/sawfish/themes
THEMES=2YearsToNever absolute-metal Anonymous Aquiline BWM Big \
	Blackwindow Bubbles_Exact CoolClean Derivative DoubleHeliX Elberg \
	FinalStep Empire gorilla Greene2.0 Hacksaw HeliX Klarth \
	Microtene OrangeJuice SawLook SawthenaForever Strap Studio \
	Titanium T-16-blue T-16-red T-16-yellow V bluefoo gorillaz \
	mxflat typo

%:
	dh $@

override_dh_auto_build:
	# arrange the upstream documentation to dh_installdocs' liking
	for t in $(THEMES) ; do \
		for f in $$t/README* ; do \
			[ -e "$$f" ] || continue ; \
			rn=`basename $$f|sed "s/README/README.$$t/"` ; \
			install -D "$$f" $(CURDIR)/debian/doc/$$rn ; \
		done ; \
		for f in $$t/TODO* ; do \
			[ -e "$$f" ] || continue ; \
			rn=`basename $$f|sed "s/TODO/TODO.$$t/"` ; \
			install -D "$$f" $(CURDIR)/debian/doc/$$rn ; \
		done ; \
		for f in changelog ChangeLog CHANGES CHANGELOG ; do \
			[ -e "$$t/$$f" ] || continue ; \
			install -D "$$t/$$f" \
			$(CURDIR)/debian/doc/changelog.$$t ; \
		done \
	done

execute_after_dh_clean:
	rm -rf $(CURDIR)/debian/doc

override_dh_auto_install:
	for t in $(THEMES) ; do \
		mkdir -p $(THEMEDIR)/$$t ; \
		find $$t/* ! -path '*.xvpics*' -a \
			\( -name \*.png \
			  -o -name \*.jl \
			  -o -name \*.xpm \) | \
		  xargs -i install -m 0644 -D {} $(THEMEDIR)/{} ;\
	done

override_dh_installchangelogs:
	dh_installchangelogs debian/changelog-stub

override_dh_installdocs:
	dh_installdocs $(CURDIR)/debian/doc/*
