#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

srcver=$(shell dpkg-parsechangelog | sed -ne 's/^Version: \(\([0-9]\+\):\)\?\(.*\)-.*/\3/p')

# create .orig.tar.gz file from .xpi file
get-orig-source: ../noscript-$(srcver).xpi
	TARGET=`mktemp -d`/mozilla-noscript-$(srcver); \
	mkdir $${TARGET} && \
	unzip -a $< -d $${TARGET} && \
	unzip -a $${TARGET}/chrome/noscript.jar -d $${TARGET}/chrome && \
	rm -f $${TARGET}/chrome/noscript.jar && \
	tar -czf $@ --transform "s,$${TARGET#/},mozilla-noscript-$(srcver)," $${TARGET}

refresh-patches: 
	rm -rf debian/patches
	mkdir debian/patches
	git format-patch upstream..upstream+patches -o debian/patches
	TMP=`mktemp`; \
	ls debian/patches > $${TMP}; \
	mv $${TMP} debian/patches/series

%:
	dh --with xul-ext --with quilt $@	

override_dh_auto_build:
	sed -i -e s'/jar:chrome\/noscript.jar\!\/\(locale\|content\|skin\)/chrome\/\1/' $(CURDIR)/chrome.manifest
	xpi-pack $(CURDIR) noscript.xpi

override_dh_auto_install:
	install-xpi --remove-license-files -x NoScript_License.txt -x chrome/content/noscript/NoScript_License.txt noscript.xpi

override_dh_auto_clean:
	sed -i -e s'/chrome\/\(locale\|content\|skin\)/jar:chrome\/noscript.jar\!\/\1/' $(CURDIR)/chrome.manifest
	rm -f noscript.xpi
