#!/usr/bin/make -f

VERSION := $(shell head -1 debian/changelog | sed 's/.*(//;s/).*//')

%:
	dh $@ --with apache2

override_dh_auto_build:
	# Minify JavaScript files.
	mkdir --parents build
	uglifyjs -o \
		build/jquery.min.js \
		core/vendor/jquery/jquery.js
	uglifyjs -o \
		build/jquery-migrate.min.js \
		core/vendor/jquery-migrate/jquery-migrate.js
	uglifyjs -o \
		build/bigshot-compressed.js \
		apps/gallery/js/vendor/bigshot/bigshot.js
	uglifyjs -o \
		build/commonmark.min.js \
		apps/gallery/js/vendor/commonmark/dist/commonmark.js
	uglifyjs -o \
		build/image-scale.min.js \
		apps/gallery/js/vendor/image-scale/image-scale.js

	# Fix displayed version
	sed "s/@VERSION@/$(VERSION) (Debian)/" \
		lib/private/util.php > \
		build/util.php

override_dh_auto_clean:
	rm -rf build

override_dh_install:
	# Remove useless licences, documentation, tests, scripts and sources
	dh_install \
		-Xapps/updater \
		-Xbower \
		-Xcomposer.json \
		-Xcomposer.lock \
		-XCOPYING -Xcore/doc \
		-Xdocumentation \
		-Xencryption/vendor \
		-Xfiles_external/3rdparty \
		-Xfiles_videoviewer/src \
		-Xgallery/build \
		-Xignorelist -Ximage-optimization.sh -Ximg/skin \
		-Xjcrop \
		-XLICEN -XLicense.txt \
		-Xvendor/eventsource-polyfill \
		-Xpdfjs \
		-Xphpdoc.xml \
		-XREADME. \
		-Xsample- \
		-Xtests \
		-Xxgettextfiles \
		-X.gitmodules \
		-X.md \
		-X.yml

override_dh_installchangelogs:
	dh_installchangelogs $(CURDIR)/debian/upstream/changelog

get-orig-source:
	uscan --force --verbose --rename
