#!/usr/bin/make -f

NAME := ubiquity
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)

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

	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.*

override_dh_builddeb:
	dh_builddeb -- -Zxz

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=$(shell sed -n '/<version>/s/^.*>\(.*\)<\/.*/\1/p' install.rdf)~pre$(shell date '+%Y%m%d')
TMPDIR=tmp-ubiquity
get-orig-source:
	hg clone https://bitbucket.org/satyr/ubiquity $(TMPDIR)
	cd $(TMPDIR)/ubiquity && rm scripts/jquery.js && \
		tar Jcf ../../../ubiquity-extension_$(VER).orig.tar.xz .
	rm -rf $(TMPDIR) && dch -v $(VER)-1 "Hg snapshot."
