#!/usr/bin/make -f

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

ifneq (,$(or $(filter noopt,$(DEB_BUILD_OPTIONS)),$(filter nostrip,$(DEB_BUILD_OPTIONS))))
	FLAGS += debug=1
endif

# Apache docroot was changed starting with Debian Jessie
NEW_DOCROOT = $(shell lsb_release -rs | awk '{print ($$1 >= 8)}')
ifeq (0,$(NEW_DOCROOT))
    HTDOC := var/www
else
    HTDOC := var/www/html
endif

PKGNAME := $(strip $(shell egrep '^Source: ' debian/control | cut -f 2 -d ':'))
ROOT := $(CURDIR)/debian/$(PKGNAME)

override_dh_auto_install:
	ant -Dbasedir=build -DdestDir=$(ROOT)-common -DpackageName=$(PKGNAME) -Dhtdoc=/$(HTDOC)/ -Dlanguages=false -DkeepCache=true -f build/build.xml build
	for LANG in de_DE en_GB en_US es_ES es_MX fr_FR it_IT ja_JP nl_NL pl_PL zh_CN zh_TW; do \
		PACKAGE_EXTENSION=$$(echo $${LANG} | tr '[:upper:]_' '[:lower:]-'); \
		ant -Dbasedir=build -DdestDir=$(ROOT)-$${PACKAGE_EXTENSION} -DpackageName=$(PKGNAME) -Dhtdoc=/$(HTDOC) -DinstallTarget=$${LANG} -DkeepCache=true -Dnoclean=true -f build/build.xml build; \
	done

override_dh_auto_clean:
	ant -Dbasedir=build -f build/build.xml clean

%:
	dh $@
