#!/usr/bin/make -f
# -*- makefile -*-

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

%:
	dh $@

override_dh_auto_configure:
	find -type f \( -name missing -o -name install-sh -o -name mkinstalldirs \
		-o -name depcomp -o -name ltmain.sh -o -name configure \
		-o -name config.log -o -name config.status \
		-o -name Makefile.in -o -name aclocal.m4 -o -name compile \) \
	    -print0 | xargs -0 rm -f
	rm -f config.sub config.guess
	rm -f doc/texinfo.tex
	autoreconf --force --install
	rm -f config.sub config.guess
	ln -s /usr/share/misc/config.sub .
	ln -s /usr/share/misc/config.guess .
	dh_auto_configure

override_dh_auto_install:
	dh_auto_install
	-rm -rf $(CURDIR)/debian/epix/usr/share/doc/epix/notes
	-rm -rf $(CURDIR)/debian/epix/usr/share/doc/epix/config
	-rm -f $(CURDIR)/debian/epix/usr/share/doc/epix/sample_src.tar.gz

override_dh_installexamples:
	dh_installexamples
	-rm -f $(CURDIR)/debian/epix/usr/share/doc/epix/examples/sample_src.tar.gz
	-rm -f $(CURDIR)/debian/epix/usr/share/doc/epix/examples/sample-stamp
	-rm -f $(CURDIR)/debian/epix/usr/share/doc/epix/examples/Makefile*

override_dh_install:
	dh_install
	install -m644 bash_completions debian/epix/etc/bash_completion.d/epix

override_dh_compress:
	dh_compress -a -X examples

override_dh_auto_clean:
	[ ! -f Makefile ] || $(MAKE) distclean
	find -type d -name autom4te.cache -print0 | xargs -0 -r rm -rf \;
	find -type f \( -name missing -o -name install-sh -o -name mkinstalldirs \
		-o -name depcomp -o -name ltmain.sh -o -name configure \
		-o -name config.log -o -name config.status -o -name INSTALL \
		-o -name Makefile.in -o -name aclocal.m4 -o -name compile \) \
	    -print0 | xargs -0 rm -f
	rm -f config.sub config.guess
	rm -f configure-stamp build-stamp configure
	rm -f doc/epix.info doc/texinfo.tex
	dh_auto_clean

# What follows is the old rules version
# CXXFLAGS = -Wall -g
# export CXXFLAGS
# 
# ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
# 	CXXFLAGS += -O0
# else
# 	CXXFLAGS += -O2
# endif
# 
# export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
# export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
# 
# ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
#   confflags += --build $(DEB_HOST_GNU_TYPE)
# else
#   confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
# endif
# 
# configure:
# 	@echo Cleaning autotools files...
# 	find -type d -name autom4te.cache -print0 | xargs -0 rm -rf \;
# 	find -type f \( -name missing -o -name install-sh -o -name mkinstalldirs \
# 		-o -name depcomp -o -name ltmain.sh -o -name configure \
# 		-o -name config.sub -o -name config.guess \
# 		-o -name config.log -o -name config.status \
# 		-o -name Makefile.in -o -name aclocal.m4 \) -print0 | \
# 		xargs -0 rm -f
# 	autoreconf --force --install
# 	rm -f config.sub config.guess
# 	ln -s /usr/share/misc/config.sub .
# 	ln -s /usr/share/misc/config.guess .
# 
# configure-stamp: configure
# 	dh_testdir
# 
# 	./configure $(confflags) \
# 	    --prefix=/usr \
# 	    --mandir=\$${prefix}/share/man
# 	touch configure-stamp
# 
# build-arch: build-stamp
# build-stamp: configure-stamp
# 	dh_testdir
# 	$(MAKE)
# 	touch build-stamp
# 
# build-indep:
# 	# Now't to do for build-indep
# 
# build: build-arch build-indep
# 
# clean:
# 	dh_testdir
# 	dh_testroot
# 	rm -f configure-stamp build-stamp configure
# 	[ ! -f Makefile ] || $(MAKE) distclean
# 	find -type d -name autom4te.cache -print0 | xargs -0 -r rm -rf \;
# 	find \( -name config.sub -o -name config.guess -o -name config.log \
# 		-o -name config.status \) -print0 | xargs -0 -r rm -f \;
# 	dh_clean
# 
# install: build
# 	dh_testdir
# 	dh_testroot
# 	dh_prep
# 	dh_installdirs
# 	$(MAKE) DESTDIR=$(CURDIR)/debian/epix install
# 	-rm -rf $(CURDIR)/debian/epix/usr/share/doc/epix/notes
# 	-rm -rf $(CURDIR)/debian/epix/usr/share/doc/epix/config
# 	# delete sample_src.tar.gz files
# 	-rm -rf $(CURDIR)/debian/epix/usr/share/doc/epix/sample_src.tar.gz
# 	# install example files
# 	install -d $(CURDIR)/debian/epix/usr/share/doc/epix/examples
# 	install -m644 samples/* $(CURDIR)/debian/epix/usr/share/doc/epix/examples
# 	-rm -f $(CURDIR)/debian/epix/usr/share/doc/epix/examples/sample_src.tar.gz
# 	-rm -f $(CURDIR)/debian/epix/usr/share/doc/epix/examples/sample-stamp
# 	-rm -f $(CURDIR)/debian/epix/usr/share/doc/epix/examples/Makefile*
# 	install -m644 epix.el debian/epix/usr/share/emacs/site-lisp/epix
# 	install -m644 bash_completions debian/epix/etc/bash_completion.d/epix
# 	# delete info files; they will be reinstalled properly by dh_installinfo
# 	-rm -f $(CURDIR)/debian/epix/usr/share/info/*
# 
# binary-indep:
# 	# Nothing to do
# 
# # Build package:
# binary-arch: build install
# 	dh_testdir -a
# 	dh_testroot -a
# 	dh_installchangelogs -a ChangeLog
# 	dh_installdocs -a
# #	dh_installexamples -a
# #	dh_install -a
# #	dh_installmenu -a
# #	dh_installdebconf -a	
# #	dh_installlogrotate -a
# 	dh_installemacsen -a
# #	dh_installpam -a
# #	dh_installmime -a
# #	dh_installinit -a
# #	dh_installcron -a
# 	dh_installinfo -a
# #	dh_installman -a
# #	dh_link -a
# 	dh_strip -a
# #	only three examples are marginally larger than 4k; it is a pain to
# #	have to decompress them before compiling
# 	dh_compress -a -X examples
# 	dh_fixperms -a
# #	dh_perl -a
# #	dh_python -a
# #	dh_makeshlibs -a
# 	dh_installdeb -a
# 	dh_shlibdeps -a
# 	dh_gencontrol -a
# 	dh_md5sums -a
# 	dh_builddeb -a
# 
# binary: binary-indep binary-arch
# .PHONY: build-indep build-arch build clean binary-indep binary-arch binary install
