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

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

SHELL=bash
CHANGELOG=CHANGES

package=jsboard
installdir=debian/tmp/usr/share/${package}/
docdir=debian/tmp/usr/share/doc/${package}/
configdir=debian/tmp/etc/${package}/

INSTALL=install
INSTALL_FILE=$(INSTALL) -p -o root -g root -m 644
INSTALL_PROGRAM=$(INSTALL) -p -o root -g root -m 755
INSTALL_SCRIPT=$(INSTALL) -p -o root -g root -m 755
INSTALL_DIR=$(INSTALL) -d -o root -g root -m 755


build: 
# nothing to do

checkdir:
	@test -f debian/rules || { echo "Error: not source tree"; exit 1; }

checkroot: checkdir
	@test 0 = `id -u` || { echo "Error: not super-user"; exit 1; }


clean: checkroot
	rm -rf debian/tmp
	rm -f debian/files debian/substvars

binary-arch: build
# nothing to do

# Build architecture-independent files here.
binary-indep: build clean
	$(INSTALL_DIR) `cat debian/dirs | sed 's/^/debian\/tmp\//g'`

	cp -a jsboard/* ${installdir}
	rm -rf ${installdir}doc
	rm -f ${installdir}COPYING*

	$(INSTALL_FILE) debian/etc/apache.conf ${configdir}
	cp -a jsboard/config/* ${configdir}
	rm -f ${installdir}config/*

	cp -a jsboard/doc/* ${docdir}
	gzip -9 ${docdir}en/*
	gzip -9 ${docdir}ko/*
	$(INSTALL_FILE) debian/changelog ${docdir}changelog.Debian
#	$(INSTALL_FILE) $(CHANGELOG) ${docdir}changelog
	$(INSTALL_FILE) debian/copyright ${docdir}
	gzip -9 ${docdir}changelog.Debian

	po2debconf debian/templates > debian/templates.merged
	$(INSTALL_DIR) debian/tmp/DEBIAN
#	$(INSTALL_SCRIPT) debian/postinst debian/postrm debian/tmp/DEBIAN/
	$(INSTALL_SCRIPT) debian/postinst debian/postrm debian/config debian/tmp/DEBIAN/
	$(INSTALL_FILE) debian/conffiles debian/tmp/DEBIAN/
	$(INSTALL_FILE) debian/templates.merged debian/tmp/DEBIAN/templates

	dpkg-gencontrol -isp
	cd debian/tmp > /dev/null ; find * -type f ! -regex '^DEBIAN/.*' -print0 | xargs -r0 md5sum > DEBIAN/md5sums ; cd $(BDIR) > /dev/null
	dpkg --build debian/tmp ..


binary: binary-indep binary-arch

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