#!/usr/bin/make -f

PKG_P_DIR=$(CURDIR)/debian/phatch
PKG_C_DIR=$(CURDIR)/debian/phatch-cli
PKG_D_DIR=$(CURDIR)/debian/phatch-doc
PKG_N_DIR=$(CURDIR)/debian/phatch-nautilus

%:
	dh $@ --with python2 --buildsystem=pybuild 

override_dh_auto_install:
	# install to phatch-cli by default and move files later
	PYBUILD_INSTALL_ARGS="--install-lib=/usr/share/phatch --prefix=/usr --root=$(PKG_C_DIR)" \
	dh_auto_install
	rm -rf $(PKG_C_DIR)/usr/share/phatch/docs # install_data creates it
	find $(PKG_C_DIR) -name '*.py[co]' -delete
	sed -i -e "s|import phatch|sys.path.insert(0,'/usr/share/phatch/');import phatch|" $(PKG_C_DIR)/usr/bin/phatch
	
	mv $(PKG_C_DIR)/usr/share/phatch/phatch/pyWx $(PKG_P_DIR)/usr/share/phatch/phatch
	mv $(PKG_C_DIR)/usr/share/phatch/phatch/lib/pyWx $(PKG_P_DIR)/usr/share/phatch/phatch/lib
	mv $(PKG_C_DIR)/usr/share/applications $(PKG_P_DIR)/usr/share
	cp $(CURDIR)/debian/phatch.lintian $(PKG_P_DIR)/usr/share/lintian/overrides/phatch
	
	mkdir -p $(PKG_N_DIR)/usr/share/phatch/phatch/lib/linux/
	mv $(PKG_C_DIR)/usr/share/phatch/phatch/lib/linux/nautilusExtension.py\
	   $(PKG_N_DIR)/usr/share/phatch/phatch/lib/linux/
	
	cd docs && python update.py
	dh_install -p phatch-doc docs/build/html /usr/share/doc/phatch/
	dh_link -p phatch-doc /usr/share/javascript/jquery/jquery.js \
	    /usr/share/doc/phatch/html/_static/jquery.js
	rm -f $(PKG_D_DIR)/usr/share/doc/phatch/html/.buildinfo
	echo "phatch-doc: extra-license-file usr/share/doc/phatch/html/_sources/data.license.txt" \
		>> $(PKG_D_DIR)/usr/share/lintian/overrides/phatch-doc

override_dh_python2:
	dh_python2
	dh_python2 -p phatch-cli /usr/share/phatch/phatch

override_dh_auto_clean:
	dh_auto_clean
	rm -rf build docs/build debian/phatch-nautilus/
