#!/usr/bin/make -f

INST_BASE = $(CURDIR)/debian/ojs
ADODB = $(INST_BASE)/usr/share/ojs/www/lib/adodb
SMARTY = $(INST_BASE)/usr/share/ojs/www/lib/smarty
SIMPLEPIE = $(INST_BASE)/usr/share/ojs/www/plugins/generic/externalFeed/simplepie/SimplePie.inc.php
TINYMCE = $(INST_BASE)/usr/share/ojs/www/lib/tinymce/jscripts/tiny_mce

%:
	dh $@

override_dh_installchangelogs:
	dh_installchangelogs docs/ChangeLog

override_dh_install:
	dh_install
	# Fix wrong permissions all over
	find $(INST_BASE) -type f -exec chmod 0644 {} +
	# Prepare the symlinks to be used for our components
	ln -s /var/cache/ojs/cache $(INST_BASE)/usr/share/ojs/www/cache
	ln -s /var/lib/ojs/public $(INST_BASE)/usr/share/ojs/www/public
	ln -s /etc/ojs/config.inc.php $(INST_BASE)/usr/share/ojs/www/config.inc.php
	# Replace the PHP/JS libraries shipped as embedded copies
	rm -rf $(ADODB)
	ln -s ../../../php/adodb $(ADODB)
	rm -rf $(SMARTY)
	ln -s ../../../php/smarty/libs $(SMARTY)
	rm $(SIMPLEPIE)
	ln -s ../../../../../../php/simplepie/simplepie.inc $(SIMPLEPIE)
	# Some files in the tinymce directory are not provided by the
	# package, we have to be more selective...
	rm $(TINYMCE)/license.txt
	for FILE in langs plugins themes utils tiny_mce.js tiny_mce_src.js \
		tiny_mce_popup.js; do \
		rm -rf $(TINYMCE)/$$FILE; \
		ln -s ../../../../../../tinymce2/www/$$FILE $(TINYMCE)/$$FILE; \
	done
