#!/usr/bin/make -f

build clean install binary-arch binary-indep binary:
	dh $@

.PHONY: build clean install binary-arch binary-indep binary

override_dh_auto_configure:
	if [ ! -x configure ]; then chmod +x configure; fi # debian.diff fails to +x
	dh_auto_configure

override_dh_auto_build: bits.tar.gz
	$(MAKE) -C texinfo bbdb.info bbdb.pdf
	texi2html --split=chapter --output=texinfo/bbdb texinfo/bbdb.texinfo

override_dh_install:
	dh_install
	@echo Give perl executables to implementation-agnostic filenames
	cd debian/bbdb/usr/bin && \
	for f in *.pl; do \
	  mv $$f $$(basename $$f .pl); \
	done
	@echo Apply Debian patches
	for f in $$(find debian/patches -name '*.patch'); do \
	  echo applying patch: $$f ; \
	  d=debian/bbdb/usr/share/emacs/site-lisp/bbdb ; \
	  patch $$d/$$(echo $$f | sed 's|^debian/patches/\(.*\)[.]patch$$|\1|') $$f; \
	done

bits.tar.gz:
	tar -cf - extern/*/* | tar -C bits -xvf -
	tar -czf bits.tar.gz bits/
