#! /usr/bin/make -f
#   -*- mode: makefile; -*-
#
#
# To make the binary distribution package, the ``Debianized'' source package
# and the context diff to the original package, type `./debian.rules dist'.
# Make sure that `debian.rules' is executable before the final distribution
# is made.
#
# Invoke each target with `./debian.rules <target>'.  All targets should be
# invoked with the package root as the current directory.
#
# The `binary' target must be run as root, as it needs to install files with
# specific ownerships.  The `diff' target assumes that you have the original
# source package available, unpacked, in ../$(p)-$(v).orig, or that you have
# the previous revision of the ``Debianized'' source package and context diff
# in the parent directory.

CC = gcc
CFLAGS = -O2 -g
LDFLAGS = -s

# The name of the package (for example, `emacs').
p = pixmap

package=$(p)

build:
# Builds the binary package.
	xmkmf
	rm -f clean
	make Makefiles
	make
	touch stamp-build

clean:
# Undoes the effect of `make -f debian.rules build'.
	-make clean
	touch clean
	rm -f Makefile Makefile.bak SelFile/Makefile dotpixmap .#pixmap
	rm -f stamp-build
	rm -rf debian/tmp

binary-arch:    checkroot build
# Makes a binary package.
	test -f stamp-build || make -f debian.rules build
	install -d -g root -m 755 -o root debian/tmp
	chmod g-s debian/tmp
	install -d -g root -m 755 -o root debian/tmp/DEBIAN
	install -d -g root -m 755 -o root debian/tmp/usr/X11R6/bin
	install -g root -m 755 -o root pixmap debian/tmp/usr/X11R6/bin/pixmap
	install -d -g root -m 755 -o root debian/tmp/usr/X11R6/lib/X11
	install -d -g root -m 755 -o root \
	  debian/tmp/usr/X11R6/lib/X11/app-defaults
	install -g root -m 644 -o root Pixmap.ad \
	  debian/tmp/usr/X11R6/lib/X11/app-defaults/Pixmap
	install -d -g root -m 755 -o root \
	  debian/tmp/usr/X11R6/lib/X11/Pixmap
	for file in Down Excl FlipHoriz FlipVert Fold Left Right RotateLeft \
	            RotateRight Stipple Term Up; \
	do \
	  install -g root -m 644 -o root $$file \
	    debian/tmp/usr/X11R6/lib/X11/Pixmap/$$file; \
	done
	install -d -g root -m 755 -o root debian/tmp/usr/X11R6/man/man1
	install -g root -m 644 -o root pixmap.man \
	  debian/tmp/usr/X11R6/man/man1/pixmap.1x
	install -d -g root -m 755 -o root debian/tmp/usr/doc/$(p)/copyright
	install -g root -m 644 -o root debian/copyright \
	  debian/tmp/usr/doc/$(p)/copyright
	dpkg-shlibdeps pixmap
	dpkg-gencontrol
	chown -R root.root debian/tmp
	chmod -R g-ws debian/tmp
	dpkg --build debian/tmp ..
	rm -f clean

define checkdir
	test -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
