#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

%:
	dh $@ --with apache2

DESTDIR = $(CURDIR)/debian/tmp
MAKE    = make -f Makefile.for.debian

override_dh_auto_clean:
	dh_auto_clean
	[ ! -f Makefile.for.debian ] || $(MAKE) clean
	# remove useless files which contain a privacy breach
	# (precisely: third-parties/tablesort-5.0.2/demo/_layouts/default.html,
	# and third-parties/tablesort-5.0.2/test/tape.js)
	rm -rf third-parties/tablesort-5.0.2/demo
	rm -rf third-parties/tablesort-5.0.2/test

override_dh_auto_build-indep:
	$(MAKE) all-indep

override_dh_auto_build-arch:
	$(MAKE) all-arch

override_dh_auto_configure:
	cd wims/src; autoreconf && ./configure --without-units --without-chemeq --without-wimsd $(shell dpkg-buildflags --export=cmdline)
	# those directories seem to be necessary for the build
	mkdir -p wims/lib
	mkdir -p wims/tmp/log


override_dh_auto_install-indep:
	$(MAKE) install-indep DESTDIR=$(DESTDIR)
	for f in $$(grep -l "deny from all" $$(find $(DESTDIR) -name ".htaccess")); do \
	  echo "# syntax for Apache2.4" > $$f; \
	  echo "Require all denied" >> $$f; \
	done

override_dh_auto_install-arch:
	$(MAKE) install-arch DESTDIR=$(DESTDIR)
	for f in $$(grep -l "deny from all" $$(find $(DESTDIR) -name ".htaccess")); do \
	  echo "# syntax for Apache2.4" > $$f; \
	  echo "Require all denied" >> $$f; \
	done
	# create a directory for wims configuration
	mkdir -p $(CURDIR)/debian/wims/etc/wims
