#!/usr/bin/make -f
# Sample debian/rules that uses debhelper. 
# GNU copyright 1997 by Joey Hess.

export DH_COMPAT=3

BUILDDIR = $(CURDIR)/debian/build
INSTALL = /usr/bin/install -p
STAMP = touch $@
CFLAGS = -O2 -Wall
ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -g
endif

build: config $(BUILDDIR)/build-stamp
$(BUILDDIR)/build-stamp:

	dh_testdir
	$(MAKE) -C $(BUILDDIR)
	$(STAMP)

config: $(BUILDDIR)/config-stamp
$(BUILDDIR)/config-stamp:
	
	$(INSTALL) -d $(BUILDDIR)
	cd $(BUILDDIR); \
	CFLAGS="$(CFLAGS)" $(CURDIR)/configure \
	--prefix=/usr \
	--mandir=/usr/share/man \
	--enable-xim \
	--with-backspace=del \
	--with-delete=execute \
	--enable-share=yes \
	--enable-static=no \
	--enable-mmx=no \
	--enable-multi-charset=unicode 
	$(STAMP)

clean:
	dh_testdir
	rm -rf $(BUILDDIR)
	-$(MAKE) distclean
	dh_clean

install: DH_OPTIONS=
install: install-stamp
install-stamp: build
	$(MAKE) install DESTDIR=$(CURDIR)/debian/eterm -C $(BUILDDIR)
	$(INSTALL) -m 755 -d debian/eterm/usr/share/man/man1/
	$(INSTALL) -m 644 debian/eterm-utils.1 debian/eterm/usr/share/man/man1/
	$(STAMP)

binary-common:
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installmenu
	dh_installchangelogs
	dh_link
	dh_compress
	dh_strip
	dh_fixperms
	dh_installdeb
	dh_shlibdeps 
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-indep: build install

binary-arch: build install
	$(MAKE) -f debian/rules DH_OPTIONS=-peterm binary-common

binary-%: build install
	make -f debian/rules binary-common DH_OPTIONS=-p$*

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






# there is nothing to see here, move along, please
prep:
	# it's not that funny, really
	perl -ni -e '/humor/../^fi$$/ or print' configure.ac configure.in

	# we don't like rpath
	perl -pi -e 's/^(Eterm|Esetroot)_LDFLAGS =.*$$//' \
	   $$(find . -name Makefile.am -o -name Makefile.in)

	# autotools walk through, skip ./configure
	sed '/configure/d' autogen.sh | sh

        # remove non-existant menu pixmap entries
	find $(CURDIR) -name menus.cfg -print | xargs newscan.rb

   	# James Troup keeps beating me about the head and neck over this
	cp -v /usr/share/misc/config.guess $(CURDIR)
	cp -v /usr/share/misc/config.sub $(CURDIR)

	# CVS and autogen cruftola
	find . -name autom4te.cache -o -name CVS -o -name CVS\* -o -name .cvs\* | xargs -r rm -rfv

.PHONY: prep
