#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
PACKAGE=linkchecker
ROOT=$(CURDIR)/debian/$(PACKAGE)
DOCDIR = $(ROOT)/usr/share/doc/$(PACKAGE)
PYTHON=python
CGIDIR=$(ROOT)/usr/lib/cgi-bin/lconline
HTMLDIR=$(ROOT)/var/www/lconline

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

configure: configure-stamp
configure-stamp:
	dh_testdir
	touch configure-stamp


build: configure-stamp build-stamp
build-stamp:
	dh_testdir
	touch build-stamp

clean:
	dh_testdir
	rm -f build-stamp configure-stamp
	$(MAKE) clean
	dh_clean

install: build
	dh_testdir
	dh_clean -k
	dh_installdirs
	$(MAKE) locale
	$(PYTHON) setup.py install --root=$(ROOT) --no-compile
# remove example files, we install them below
	rm -r $(ROOT)/usr/share/linkchecker/examples
# install CGI files
	install -c -m 644 lconline/*.html $(HTMLDIR)
	install -c -m 644 lconline/*.de $(HTMLDIR)
	install -c -m 644 lconline/*.en $(HTMLDIR)
	install -c -m 644 lconline/check.js $(HTMLDIR)
	cat lc.cgi | sed 's#/usr/bin/python#/usr/bin/$(PYTHON)#' > $(CGIDIR)/lc.cgi
	cat lc.fcgi | sed 's#/usr/bin/python#/usr/bin/$(PYTHON)#' > $(CGIDIR)/lc.fcgi
	cat lc.sz_fcgi | sed 's#/usr/bin/python#/usr/bin/$(PYTHON)#' > $(CGIDIR)/lc.sz_fcgi
	chmod 755 $(CGIDIR)/lc.cgi
	chmod 755 $(CGIDIR)/lc.fcgi
	chmod 755 $(CGIDIR)/lc.sz_fcgi
# install system wide configuration file in etc
	install -m644 $(ROOT)/usr/share/linkchecker/linkcheckerrc $(ROOT)/etc
# install bash_completion script
	install -m644 linkchecker-completion $(ROOT)/etc/bash_completion.d
# install lintian overrides
	install -m644 debian/linkchecker.lintian $(ROOT)/usr/share/lintian/overrides/linkchecker

# Build architecture-independent files here.
binary-indep: build install

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installexamples linkcheck-cron.sh
#	dh_installman linkchecker.1
	dh_installchangelogs ChangeLog
	dh_link
	dh_strip
	dh_python
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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