#!/usr/bin/make -f
# vim:noet:

%:
	dh  ${@} --with python2

override_dh_auto_install:
	python setup.py install -f --install-layout=deb --root=$(CURDIR)/debian/openerp6.1-core

	: # now move things into a private directory
	mkdir -p debian/openerp6.1-core/usr/share/openerp
	mv debian/openerp6.1-core/usr/openerp/* \
		debian/openerp6.1-core/usr/share/openerp/.
	mv debian/openerp6.1-core/usr/lib/python2.7/dist-packages/*.egg-info \
		debian/openerp6.1-core/usr/share/openerp/.

	mv debian/openerp6.1-core/usr/localedata \
		debian/openerp6.1-core/usr/share/openerp/.

	: # this is not needed, installed twice
	rm -rf debian/openerp6.1-core/usr/lib/python2.7/dist-packages/openerp
	rmdir debian/openerp6.1-core/usr/lib/python2.7/dist-packages
	rmdir debian/openerp6.1-core/usr/lib/python2.7
	rmdir debian/openerp6.1-core/usr/lib
	rm -rf debian/openerp6.1-core/usr/openerp

        # remove extra files
	find debian/openerp6.1-core/ -name 'LICENSE' -delete
	rm debian/openerp6.1-core/usr/share/openerp/addons/web_calendar/static/lib/dhtmlxScheduler/license.txt
	rm debian/openerp6.1-core/usr/share/openerp/addons/web_graph/static/lib/dhtmlxGraph/codebase/thirdparty/excanvas/COPYING
	rm debian/openerp6.1-core/usr/share/openerp/addons/plugin_outlook/static/openerp-outlook-plugin/OpenERPOutlookPlugin.sln
	rm debian/openerp6.1-core/usr/share/openerp/addons/web/static/lib/py.parse/.hg_archival.txt
	rm debian/openerp6.1-core/usr/share/openerp/addons/plugin_thunderbird/static/thunderbird_plugin/chrome/openerp_plugin.jar

override_dh_installinit:
	dh_installinit --update-rcd-params='defaults 21' --name=openerp-server

override_dh_fixperms:
	find debian/openerp6.1-core -name '*.html' -type f -o -name 'input_complete' -type f -o -name '*.dat' -type f -o -name '*.js' -type f -o -name '*.png' -type f -o -name '*.po' -type f -o -name '*.css' -type f -o -name '*.md' -type f -o -name '*.csv' -type f -o -name '*.yml' -type f -o -name '*.v11' -type f -o -name '*.ttf' -type f | xargs -r chmod a-x
	chmod a-x debian/openerp6.1-core/usr/share/openerp/addons/plugin_thunderbird/static/thunderbird_plugin/install.sh
	chmod a-x debian/openerp6.1-core/usr/share/openerp/addons/account_asset/wizard/wizard_asset_compute.py
	chmod a-x debian/openerp6.1-core/usr/share/openerp/addons/account_asset/wizard/account_asset_change_duration.py
	chmod a-x debian/openerp6.1-core/usr/share/openerp/addons/account_asset/wizard/__init__.py
	chmod a-x debian/openerp6.1-core/usr/share/openerp/addons/base_quality_interrogation.py

	dh_fixperms

override_dh_clean:
	rm -f openerp6.1-core.egg-info/SOURCES.txt
	dh_clean

DEB_DEBIAN_DIR=$(dir $(firstword $(MAKEFILE_LIST)))
get-packaged-orig-source:
	# Uscan will read debian/watch, grab the correct version, repack, and leave it in the
	# current directory, given the path to the source package.
	uscan --noconf --force-download --rename --repack --download-current-version --destdir=. $(DEB_DEBIAN_DIR)..
