#!/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)/
	chmod +x $(BACKEND)/share/update-themes.sh
	sed -e 's#OX_APPSUITE_DEV=.*#OX_APPSUITE_DEV="/opt/open-xchange-appsuite-dev"#' \
	    bin/build-appsuite > tmp/build-appsuite
	chmod +x tmp/build-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 $@
