#!/usr/bin/make -f

NAME := ubiquity
VERS := $(shell dpkg-parsechangelog|sed -n '/^Version/{s/Version: \(.*\)-[0-9]*$$/\1/p}')
PKGNAME := xul-ext-$(NAME).xpi
USRSHARE := debian/$(basename $(PKGNAME))/usr/share/xul-ext/$(NAME)

%:
	dh $@ --with xul-ext --buildsystem=xul_ext

override_dh_auto_configure:
	dh_auto_configure
	cp debian/debian.html debian/debian.js standard-feeds

override_dh_auto_install:
	install-xpi -i /usr/share/xul-ext/$(NAME) $(PKGNAME)

	rm $(USRSHARE)/scripts/jquery.js
	ln -s /usr/share/javascript/jquery/jquery.js \
		$(USRSHARE)/scripts/jquery.js
	rm -v $(USRSHARE)/scripts/gettext/[CR]*

	rm $(USRSHARE)/standard-feeds/scripts/jquery.js
	ln -s /usr/share/javascript/jquery/jquery.js \
		$(USRSHARE)/standard-feeds/scripts/jquery.js
	rm -v $(USRSHARE)/standard-feeds/scripts/gettext/[CR]*

	find $(USRSHARE) -type d -empty -print -delete

override_dh_auto_clean:
	dh_auto_clean
	rm -f standard-feeds/debian.*

baseurl="http://git.debian.org/?p=users/filippo/ubiquity-commands.git;a=blob_plain;f="

get-ubi-commands:
	wget -O debian/debian.js   $(baseurl)debian.js
	wget -O debian/debian.html $(baseurl)ubiquity-commands.html

VER=0.6.1~pre$(shell date '+%Y%m%d')
TMPDIR=tmp-ubiquity
get-orig-source:
	hg clone https://ubiquity.mozilla.com/hg/ubiquity-firefox $(TMPDIR)
	cd $(TMPDIR)/ubiquity && tar jcf ../../../ubiquity-extension_$(VER).orig.tar.bz2 .
	rm -rf $(TMPDIR) && dch -v $(VER)-1 "Hg snapshot."
