#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

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

MOZLANG=ko
LOC=KR
mozillalocale=mozilla-locale-ko
installed_locale=installed-locale-ko
mozilladir=/usr/lib/mozilla
navigator_ddt=locale/$(MOZLANG)/navigator/navigator-title.dtd
region_properties=locale/$(LOC)/navigator-region/region.properties

configure: configure-stamp
configure-stamp:
	dh_testdir

	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	mkdir -p temp
	unzip -d temp *.xpi

	cd temp/bin/chrome/ && \
	rm -rf locale [a-z][a-z]-mac.jar [a-z][a-z]-win.jar

	cd temp/bin/chrome/ && \
	unzip $(LOC).jar && \
	sed -e 's!homePageDefault.*!homePageDefault=http://www.debian.org/!g' \
	    -e 's!browser\.startup\.homepage.*!browser.startup.homepage=http://www.debian.org/!g' \
	    -e 's!browser\.throbber\.url.*!browser.throbber.url=http://www.debian.org/!g' \
	    -e 's!startup.homepage_override_url.*!startup.homepage_override_url=http://www.debian.org/!g' \
	$(region_properties) > \
	$(region_properties).$(LOC) && \
	mv $(region_properties).$(LOC) \
	   $(region_properties) && \
	rm -r $(LOC).jar && \
	zip -r $(LOC).jar locale && rm -r locale

	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

	install -d  $(CURDIR)/debian/$(mozillalocale)/$(mozilladir)/chrome/
	install -d  $(CURDIR)/debian/$(mozillalocale)/$(mozilladir)/searchplugins/

	install -m 644 temp/bin/chrome/ko-unix.jar \
		$(CURDIR)/debian/$(mozillalocale)/$(mozilladir)/chrome/
	install -m 644 temp/bin/chrome/$(LOC).jar \
		$(CURDIR)/debian/$(mozillalocale)/$(mozilladir)/chrome/

	cd temp && cd bin && tar chf - chrome defaults | \
		tar -C $(CURDIR)/debian/$(mozillalocale)/$(mozilladir)/ -xhf -
	chmod 644 $(CURDIR)/debian/$(mozillalocale)/$(mozilladir)/defaults/profile/$(LOC)/*.rdf
	cd temp/bin/searchplugins/ && tar chf - * | \
		tar -C $(CURDIR)/debian/$(mozillalocale)/$(mozilladir)/searchplugins/ -xhf -

	cp debian/50ko-locale debian/$(mozillalocale)/var/lib/mozilla/chrome.d


# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs -i
	dh_installdocs
	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
.PHONY: build clean binary-indep binary-arch binary install configure
