#!/usr/bin/make -f
# -*- makefile -*-
# debian/rules file - for mxterm
# Copyright 2005 by Greg Schenzel
# Patterned after the rxvt package by Brian Mays.
# Patterned after the hello package by Ian Jackson.

package=mxterm

# Stupid hack dictated by policy wonks
CFLAGS=-O3 -Wall
ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
CFLAGS += -g
endif

build:	build-std
	$(checkdir)
	touch build

build-std: 
	$(checkdir)
	$(MAKE) -f debian/rules Makefile
	$(MAKE) CFLAGS='$(CFLAGS)' all
	touch build-std

clean:
	$(checkdir)
	$(RM) build*
	-[ -f Makefile ] && $(MAKE) -i clean
	-[ -f Makefile ] && rm Makefile
	-[ -f config.cache ] && rm config.cache

binary-indep:	checkroot build
	$(checkdir)

binary-arch:	mxterm-std

mxterm-std:	checkroot build-std
	$(chechdir)
	$(RM) -r debian/tmp
	install -d debian/tmp debian/tmp/DEBIAN
	install -d debian/tmp/usr/share/doc
#	/$(package)
# Install Debian package control information files
	install debian/preinst debian/postinst debian/prerm \
	        debian/postrm debian/tmp/DEBIAN/.
#	install -m644 debian/conffiles debian/tmp/DEBIAN/.
# Install directories
	install -d debian/tmp/usr/bin
	install -d debian/tmp/usr/share/man/man1
#	install -d debian/tmp/usr/share/terminfo/m
# Install files
	$(MAKE) install prefix=$(shell pwd)/debian/tmp/usr
#	$(MAKE) install-ti prefix=$(shell pwd)/debian/tmp/usr
# Use the man page that hasn't been run though tbl
#	$(RM) debian/tmp/usr/share/man/man1/mxterm.1
#	install -m644 doc/mxterm.tbl debian/tmp/usr/share/man/man1/mxterm.1
#	install src/mxterm-xpm debian/tmp/usr/bin/.
	install -d debian/tmp/usr/lib/menu
	install -m644 debian/menu debian/tmp/usr/lib/menu/mxterm
# Strip binaries (including hack by policy wonks)
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	strip -R.note -R.comment debian/tmp/usr/bin/*
endif
# Install documentation
#	install -m644 doc/changelog \
#	  debian/tmp/usr/share/doc/$(package)/changelog
#	install -m644 debian/README \
#	  debian/tmp/usr/share/doc/$(package)/README.Debian
# Install changelog & copyright
	cp -r doc debian/tmp/usr/share/doc/$(package)

	install -m644 debian/changelog \
	  debian/tmp/usr/share/doc/$(package)/changelog.Debian
	
	gzip -9v `find debian/tmp/usr/share/doc/$(package) -type f`
	gzip -9v debian/tmp/usr/share/man/*/*
#	ln -s mxterm.1.gz debian/tmp/usr/share/man/man1/mxterm.1.gz
#	ln -s mxterm-resize.1.gz debian/tmp/usr/share/man/man1/mxterm-resize.1.gz
	install -m644 debian/copyright debian/tmp/usr/share/doc/$(package)/.
# Determine shared library dependencies
	dpkg-shlibdeps mxterm -dSuggests resize
# Genereate deb file
	dpkg-gencontrol -isp -p$(package) -DSuggests='$${shlibs:Suggests}'
	chown -R root.root debian/tmp
	chmod -R g-ws debian/tmp
	chown root.utmp debian/tmp/usr/bin/mxterm
	chmod 2755 debian/tmp/usr/bin/mxterm
	dpkg-deb --build debian/tmp ..

Makefile:
	$(checkdir)
	./configure --prefix=/usr --mandir='$${prefix}/share/man' \
			--with-x

define checkdir
	test -f xterm.h -a -f debian/rules
endef

# Below here is fairly generic really

binary:		binary-indep binary-arch

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

checkroot:
	$(checkdir)
	test root = "`whoami`"

.PHONY: binary binary-arch binary-indep clean checkroot mxterm-std

