#!/usr/bin/make -f

#export DH_VERBOSE=1

BUILDDIR = $(CURDIR)/debian/build

include $(CURDIR)/debian/lang_config.mk

find_files = $(wildcard $(BUILDDIR)/$(file))

configure: configure-stamp
configure-stamp:
	dh_testdir

	touch configure-stamp

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

	mkdir -p $(BUILDDIR)
	unzip -d $(BUILDDIR) $(CURDIR)/*.xpi

	touch build-stamp

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

	-rm -rf $(BUILDDIR)

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	install -d  $(CURDIR)/debian/mozilla-thunderbird-locale-$(MOZ_LANG)/usr/lib/mozilla-thunderbird/defaults/preferences
	install -d  $(CURDIR)/debian/mozilla-thunderbird-locale-$(MOZ_LANG)/usr/lib/mozilla-thunderbird/defaults/messenger/$(MOZ_LANG_UC)
	install -d  $(CURDIR)/debian/mozilla-thunderbird-locale-$(MOZ_LANG)/usr/lib/mozilla-thunderbird/defaults/profile/$(MOZ_LANG_UC)
	install -d  $(CURDIR)/debian/mozilla-thunderbird-locale-$(MOZ_LANG)/var/lib/mozilla-thunderbird/extensions.d/

	cp -f $(BUILDDIR)/defaults/messenger/KR/mailViews.dat $(CURDIR)/debian/mozilla-thunderbird-locale-$(MOZ_LANG)/usr/lib/mozilla-thunderbird/defaults/messenger/$(MOZ_LANG_UC)/
#	cp -rf $(CURDIR)/debian/50*txt $(CURDIR)/debian/mozilla-thunderbird-locale-$(MOZ_LANG)/var/lib/mozilla-thunderbird/extensions.d/
#	cp -rf $(CURDIR)/debian/extension.part.* $(CURDIR)/debian/mozilla-thunderbird-locale-$(MOZ_LANG)/var/lib/mozilla-thunderbird/extensions.d/
	cp -rf $(BUILDDIR)/defaults/profile/$(MOZ_LANG_UC) $(CURDIR)/debian/mozilla-thunderbird-locale-$(MOZ_LANG)/usr/lib/mozilla-thunderbird/defaults/profile/

	install -m 644 $(foreach file,$(CHROME_FILES),$(find_files)) $(CURDIR)/debian/mozilla-thunderbird-locale-$(MOZ_LANG)/usr/lib/mozilla-thunderbird/chrome/
		
#	cd $(BUILDDIR) && tar chf - defaults | \
#		tar -C $(CURDIR)/debian/mozilla-thunderbird-locale-$(MOZ_LANG)/usr/lib/mozilla-thunderbird/ -xhf -
	install -m 644 $(CURDIR)/debian/$(MOZ_LANG)-$(MOZ_REGION)-chrome.txt $(CURDIR)/debian/mozilla-thunderbird-locale-$(MOZ_LANG)/var/lib/mozilla-thunderbird/chrome.d
#	echo "$(MOZ_LANG):$(MOZ_REGION)" > debian/mozilla-thunderbird-locale-$(MOZ_LANG)/var/lib/mozilla-thunderbird/locales.d/50_locale-$(MOZ_LANG)-$(MOZ_REGION)


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