#!/usr/bin/make -f
# debian/rules makefile for gnuhtml2latex
# Heavily based on the rules for GNU Hello

package = gnuhtml2latex
tmpdir = debian/tmp
debiandir = $(tmpdir)/DEBIAN
docdir = $(tmpdir)/usr/share/doc/$(package)
bindir = $(tmpdir)/usr/bin
mandir = $(tmpdir)/usr/share/man

define checkdir
	test -d debian -a -f debian/control -a -f debian/rules -a -f gnuhtml2latex
endef

build: build-stamp
build-stamp:
	true
# And that's it - Our first stub.

clean: checkroot
	$(checkdir)
	rm -fr debian/tmp debian/files debian/*~

binary-arch: build
	true
# Yup, that was just a stub

binary-indep: clean checkroot build
	$(checkdir)
	install -d $(tmpdir) $(debiandir) $(docdir) $(bindir) $(mandir)/man1
	cp -a gnuhtml2latex $(bindir)
	pod2man gnuhtml2latex > $(mandir)/man1/gnuhtml2latex.1
	cp -a debian/copyright $(docdir)
	cp -a debian/changelog $(docdir)/changelog.Debian
	gzip -9 $(docdir)/changelog.Debian
	for i in `find $(mandir) -type f`; do \
	  gzip -9 $$i; \
	done
	# Fix some permissions that don't comply to the standards...
	for i in `find $(mandir) $(docdir) -type f`;do\
	  chmod 644 $$i; \
	done
	for i in `find $(bindir) -type f`; do \
	  chmod 755 $$i; \
	done
	# Ok, everything is finally in its place... Now make the md5 checksums
	# We make the checksums of every package in $(tmpdir)/usr - Everything
	# outside usr/ is either a conffile or the debian control files, which
	# don't need being md5summed
	for i in `find $(tmpdir)/usr -type f -printf '%P '` ; do \
	  CURRDIR=`pwd`; cd $(tmpdir); \
	  md5sum usr/$$i ; cd $$CURRDIR; \
	done > $(debiandir)/md5sums
	# Enough moving things around - Now build the package!
	dpkg-gencontrol -isp
	chown -R root.root $(tmpdir)
	chmod -R g-ws $(tmpdir)
	dpkg --build $(tmpdir) ..

# Generic targets
binary:		binary-indep binary-arch

checkroot:
	$(checkdir)
	test $$(id -u) = 0

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