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

BACKEND := debian/open-xchange-appsuite-manifest/opt/open-xchange/appsuite
FRONTEND := debian/open-xchange-appsuite/var/www/appsuite

override_dh_auto_install:
	sh build.sh skipLess=1 builddir=$(FRONTEND) manifestDir=$(BACKEND) \
	    l10nDir=debian/open-xchange-appsuite-l10n-@lang@/opt/open-xchange/appsuite \
	    helpDir=debian/open-xchange-appsuite-help-@lang@/var/www/appsuite \
	    $(FLAGS) --trace
	for i in i18n/*.properties; do \
	    j=$${i#i18n/}; pkgname=$${j%.properties}; \
	    mkdir -p debian/$$pkgname/opt/open-xchange/etc/languages/appsuite/; \
	    cp $$i debian/$$pkgname/opt/open-xchange/etc/languages/appsuite/; \
	done
	cp -r $(FRONTEND)/apps $(BACKEND)/
	mv $(FRONTEND)/share $(BACKEND)/
	mkdir -p debian/open-xchange-appsuite/opt/open-xchange/sbin
	sed -e "s:## cd ##:cd /var/www/appsuite:" bin/touch-appsuite > \
	    debian/open-xchange-appsuite/opt/open-xchange/sbin/touch-appsuite
	chmod +x debian/open-xchange-appsuite/opt/open-xchange/sbin/touch-appsuite

override_dh_auto_clean:
	sh build.sh clean skipLess=1 builddir=$(FRONTEND) manifestDir=$(BACKEND) \
	    l10nDir=debian/open-xchange-appsuite-l10n-@lang@/opt/open-xchange/appsuite \
        helpDir=debian/open-xchange-appsuite-help-@lang@/var/www/appsuite \
	    $(FLAGS) --trace

%:
	dh $@
