#!/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

TEX__GIF = $(DESTDIR)/var/lib/wims/public_html/bin/tex..gif
override_dh_fixperms:
	dh_fixperms
	# tex..gif is wrongly considered as an image, it must be executable
	[ ! -f $(TEX__GIF) ] || chmod +x $(TEX__GIF)

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


override_dh_auto_install-indep:
	# for some reason, dh_installdirs does not work as expected !
	mkdir -p $(DESTDIR)
	for d in $$(cat debian/*.dirs); do \
	  if echo $$d | grep -q "#"; then \
	    true; \
	  else \
	    mkdir -p $(DESTDIR)/$$d; \
	  fi; \
	done
	$(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:
	# for some reason, dh_installdirs does not work as expected !
	mkdir -p $(DESTDIR)
	for d in $$(cat debian/*.dirs); do \
	  if echo $$d | grep -q "#"; then \
	    true; \
	  else \
	    mkdir -p $(DESTDIR)/$$d; \
	  fi; \
	done
	$(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
