summaryrefslogtreecommitdiff
path: root/src/lp-locale-export.mk
blob: f09aaf919dbfffaf6f546710b1ac061ec69eae64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-

# Copyright (c) 2008 Canonical Ltd.
# Author(s): Alexander Sack <asac@ubuntu.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


# arguments: MOZ_TRANSLATION_TARGET_DIRS - application names that this xpi is suitable for
#            MOZ_TRANSLATION_TARGET_IDS  - application IDS that this xpi can be hosted on
#            MOZ_TRANSLATION_TARGET_MAX_VERSION_$(ID) - max version for the target application with ID
#            MOZ_TRANSLATION_TARGET_MIN_VERSION_($ID) - min version for the target application with ID
#
#            MOZ_TRANSLATION_AUTO_XPI_LOCALE - locales you want to generate xpis automatically for
#            MOZ_TRANSLATION_AUTO_XPI_SEARCHDIRS - directories you want to inspect for install manifests
#                                                  and extract locale content from
#            MOZ_TRANSLATION_AUTO_XPI_OUTDIR
#


MOZ_TRANSLATION_AUTO_XPI_LOCALE ?= en-US
MOZ_TRANSLATION_TARGET_IDS ?= {firefox-id}
MOZ_TRANSLATION_TARGET_DIRS ?= firefox-addons
#MOZ_TRANSLATION_TARGET_MAX_VERSION_{firefox-id} = 3.0.*
#MOZ_TRANSLATION_TARGET_MIN_VERSION_{firefox-id} = 3.0b3

# ----  define $(call ...) functions

MOZCALL_all_manifests = \
	$(shell \
		find $(MOZ_TRANSLATION_AUTO_XPI_SEARCHDIRS) -name \*.manifest \
	)

MOZCALL_filter_manifest_locales_by_lang_to_norm = \
	$(shell \
		cat $(1) | grep "^locale " | grep " $(2) " >> $(3) \
	)

MOZCALL_manifest_locale_files_to_outdir = \
	$(shell \
		if test `grep -c ^locale $(1)` -gt 0; then \
			tar -c -C `dirname $(1)`/ -f - \
				`cat $(1) | \
					grep "^locale " | \
					grep " $(2) " | \
					sed -e 's/^.* $(2) jar:\(.*\)!.*$$/\1/' \
				` | \
			tar -C $(3) -x -f -; \
		 fi \
	)


# ---- define generic targets

%.mkdir:
	mkdir -p $*


# create xpi in 3 steps:
#   1. mkdir flat directory
#   2. fill directory with locale files
#   3. generate manifest

$(MOZ_TRANSLATION_AUTO_XPI_OUTDIR)%.xpi: \
	$(MOZ_TRANSLATION_AUTO_XPI_OUTDIR)%.xpi-flat.mkdir

	# extract locale filenames from $$(MOZCALL_all_manifests) and
	# move the files to $$(MOZCALL_manifest_locale_files_to_outdir)
	$(foreach manifest,$(MOZCALL_all_manifests), \
		$(call MOZCALL_manifest_locale_files_to_outdir, \
			$(manifest),$*,$@-flat/))

	# produce chrome.manifest for all locale entries
	$(foreach manifest,$(MOZCALL_all_manifests), \
		$(call MOZCALL_filter_manifest_locales_by_lang_to_norm, \
			$(manifest),$*,$@-flat/chrome.manifest))

	@sh -c "cd $@-flat/; zip -r ../$*.xpi ."


# translate
auto-locale-xpi.mk/translate : \
	$(foreach l,$(MOZ_TRANSLATION_AUTO_XPI_LOCALE),$(MOZ_TRANSLATION_AUTO_XPI_OUTDIR)$(l).xpi)


auto-locale-xpi.mk/clean:
	rm -rf $(MOZ_TRANSLATION_AUTO_XPI_OUTDIR)*.xpi $(MOZ_TRANSLATION_AUTO_XPI_OUTDIR)*.xpi-flat


# ---- hook in cdbs