#!/usr/bin/make -f
# debian/rules for mozilla-locale-es
# based on the mozilla-locale-de package
# GNU copyright 1997 to 1999 by Joey Hess.
# (c) 2002, 2003 Javier Fernandez-Sanguino

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

# This is the debhelper compatability version to use.
export DH_COMPAT=3

LOC=ES
LANG=es
mozillalocale=mozilla-locale-es
installed_locale=installed-locale-es
mozilladir=/usr/lib/mozilla

build: build-stamp
build-stamp:
	dh_testdir

	mkdir -p temp-$(LOC) 
	# The global one contains both the locale and registry
	# entries
	unzip -o -d temp-$(LOC) globeses.xpi
	unzip -o -d temp-$(LOC) langeses.xpi
	unzip -o -d temp-$(LOC) reges.xpi

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	-rm -rf temp-*

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	for i in $(LOC); do \
	cd $(CURDIR) ; \
	export loc=`echo $$i | perl -ne 'print lc'`; \
	echo Creating location for $$loc ; \
	cp debian/50$(LANG)$$i-locale debian/$(mozillalocale)-$$loc/var/lib/mozilla/chrome.d ; \
	install -d  $(CURDIR)/debian/$(mozillalocale)-$$loc/$(mozilladir)/chrome/ ; \
	install -d  $(CURDIR)/debian/$(mozillalocale)-$$loc/$(mozilladir)/searchplugins/ ; \
	[ -f temp/bin/chrome/$(LANG)-unix.jar ] && \
	install -m 644 temp/bin/chrome/$(LANG)-unix.jar \
		$(CURDIR)/debian/$(mozillalocale)-$$loc/$(mozilladir)/chrome/ ; \
	[ -f temp/bin/chrome/$(LANG)-$$i.jar ] && \
	install -m 644 temp/bin/chrome/$(LANG)-$$i.jar \
		$(CURDIR)/debian/$(mozillalocale)-$$loc/$(mozilladir)/chrome/ ; \
	[ -f temp/bin/chrome/$$i.jar ] && \
	install -m 644 temp/bin/chrome/$$i.jar \
		$(CURDIR)/debian/$(mozillalocale)-$$loc/$(mozilladir)/chrome/ ; \
	cd temp-$$i/bin && tar chf - chrome  | \
	tar -C $(CURDIR)/debian/$(mozillalocale)-$$loc/$(mozilladir)/ -xhf - ; \
	done

# Where is the defaults dir?
#	cd temp-$$i/bin && tar chf - chrome defaults | \



# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdocs -i 
	dh_installchangelogs -i
	dh_link -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: build install
# We have nothing to do by default.

binary: binary-indep binary-arch

consistency-check: build
# Check if the debian/50esXX files provide all the localize content
# (for update-mozilla-locale to work)
# Check if the items we are providing are available or not
	for i in $(LOC) ; do \
	echo "Checking consistency for $$i."; \
	cd temp-$$i/bin/chrome ;\
	for jarfiles in *.jar ; do \
	echo "Checking $$jarfiles in $$i." ;\
	[ -d locale ] && rm -rf locale ; \
	echo "A" | unzip $$jarfiles >/dev/null 2>&1;\
	echo "The following items are not provided by this jar but are defined" ; \
	for item in `cat $(CURDIR)/debian/50es$$i-locale | grep /$$jarfiles! |cut -d ! -f 2 | sed -e 's/^\///'`; do \
	[ ! -d  $(CURDIR)/temp-$$i/bin/chrome/$$item ]  && echo $$item ; \
	done ; \
	echo "The following items are present but have not been defined:" ; \
	for item in `find $(CURDIR)/temp-$$i/bin/chrome/locale -type d `; do \
	item=`echo $$item | sed -e 's/.*chrome\///'`;  \
	[ -z  "`grep $$item $(CURDIR)/debian/50es$$i-locale`" ] &&  \
	echo "locale,install,url,jar:resource:/chrome/$$jarfiles!/$$item" ; \
	done ; \
	done ; \
	cd $(CURDIR); \
	done

.PHONY: build clean binary-indep binary-arch binary install configure
