1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: mozlinguas-v2.eclass
8 # Nirbheek Chauhan <nirbheek@gentoo.org>
9 # Ian Stakenvicius <axs@gentoo.org>
10 # @BLURB: Handle language packs for mozilla products
12 # Sets IUSE according to MOZ_LANGS (language packs available). Also exports
13 # src_unpack, src_compile and src_install for use in ebuilds, and provides
14 # supporting functions for langpack generation and installation.
20 die "EAPI ${EAPI:-0} does not support the '->' SRC_URI operator";;
22 EXPORT_FUNCTIONS src_unpack src_compile src_install;;
24 die "EAPI ${EAPI} is not supported, contact eclass maintainers";;
27 # @ECLASS-VARIABLE: MOZ_LANGS
29 # Array containing the list of language pack xpis available for
30 # this release. The list can be updated with scripts/get_langs.sh from the
34 # @ECLASS-VARIABLE: MOZ_PV
36 # Ebuild package version converted to equivalent upstream version.
37 # Defaults to ${PV}, and should be overridden for alphas, betas, and RCs
40 # @ECLASS-VARIABLE: MOZ_PN
42 # Ebuild package name converted to equivalent upstream name.
43 # Defaults to ${PN}, and should be overridden for binary ebuilds.
46 # @ECLASS-VARIABLE: MOZ_P
48 # Ebuild package name + version converted to upstream equivalent.
49 # Defaults to ${MOZ_PN}-${MOZ_PV}
50 : ${MOZ_P:="${MOZ_PN}-${MOZ_PV}"}
52 # @ECLASS-VARIABLE: MOZ_FTP_URI
54 # The ftp URI prefix for the release tarballs and language packs.
57 # @ECLASS-VARIABLE: MOZ_HTTP_URI
59 # The http URI prefix for the release tarballs and language packs.
62 # @ECLASS-VARIABLE: MOZ_LANGPACK_HTTP_URI
64 # An alternative http URI if it differs from official mozilla URI.
65 # Defaults to whatever MOZ_HTTP_URI was set to.
66 : ${MOZ_LANGPACK_HTTP_URI:=${MOZ_HTTP_URI}}
68 # @ECLASS-VARIABLE: MOZ_LANGPACK_PREFIX
70 # The relative path till the lang code in the langpack file URI.
71 # Defaults to ${MOZ_PV}/linux-i686/xpi/
72 : ${MOZ_LANGPACK_PREFIX:="${MOZ_PV}/linux-i686/xpi/"}
74 # @ECLASS-VARIABLE: MOZ_LANGPACK_SUFFIX
76 # The suffix after the lang code in the langpack file URI.
78 : ${MOZ_LANGPACK_SUFFIX:=".xpi"}
80 # @ECLASS-VARIABLE: MOZ_LANGPACK_UNOFFICIAL
82 # The status of the langpack, used to differentiate within
83 # Manifests and on Gentoo mirrors as to when the langpacks are
84 # generated officially by Mozilla or if they were generated
85 # unofficially by others (ie the Gentoo mozilla team). When
86 # this var is set, the distfile will have a .unofficial.xpi
88 : ${MOZ_LANGPACK_UNOFFICIAL:=""}
90 # @ECLASS-VARIABLE: MOZ_GENERATE_LANGPACKS
92 # This flag specifies whether or not the langpacks should be
93 # generated directly during the build process, rather than
94 # being downloaded and installed from upstream pre-built
95 # extensions. Primarily it supports pre-release builds.
97 : ${MOZ_GENERATE_LANGPACKS:=""}
99 # @ECLASS-VARIABLE: MOZ_L10N_SOURCEDIR
101 # The path that l10n sources can be found at, once unpacked.
102 # Defaults to ${WORKDIR}/l10n-sources
103 : ${MOZ_L10N_SOURCEDIR:="${WORKDIR}/l10n-sources"}
105 # @ECLASS-VARIABLE: MOZ_L10N_URI_PREFIX
107 # The full URI prefix of the distfile for each l10n locale. The
108 # AB_CD and MOZ_L10N_URI_SUFFIX will be appended to this to complete the
109 # SRC_URI when MOZ_GENERATE_LANGPACKS is set. If empty, nothing will
110 # be added to SRC_URI.
112 : ${MOZ_L10N_URI_PREFIX:=""}
114 # @ECLASS-VARIABLE: MOZ_L10N_URI_SUFFIX
116 # The suffix of l10n source distfiles.
117 # Defaults to '.tar.xz'
118 : ${MOZ_L10N_URI_SUFFIX:=".tar.xz"}
120 # @ECLASS-VARIABLE: MOZ_FORCE_UPSTREAM_L10N
122 # Set this to use upstream langpaks even if the package normally
123 # shouldn't (ie it is an alpha or beta package)
124 : ${MOZ_FORCE_UPSTREAM_L10N:=""}
127 # @ECLASS-VARIABLE: MOZ_TOO_REGIONALIZED_FOR_L10N
130 # Upstream identifiers that should not contain region subtags in L10N
131 MOZ_TOO_REGIONALIZED_FOR_L10N=( fy-NL ga-IE gu-IN hi-IN hy-AM nb-NO nn-NO pa-IN sv-SE )
133 # Add l10n_* to IUSE according to available language packs
134 # No language packs for alphas and betas
135 if ! [[ -n ${MOZ_GENERATE_LANGPACKS} ]] ; then
136 if ! [[ ${PV} =~ alpha|beta ]] || { [[ ${PN} == seamonkey ]] && ! [[ ${PV} =~ alpha ]] ; } || [[ -n ${MOZ_FORCE_UPSTREAM_L10N} ]] ; then
137 [[ -z ${MOZ_FTP_URI} ]] && [[ -z ${MOZ_LANGPACK_HTTP_URI} ]] && die "No URI set to download langpacks, please set one of MOZ_{FTP,HTTP_LANGPACK}_URI"
138 for x in "${MOZ_LANGS[@]}" ; do
139 # en and en_US are handled internally
140 if [[ ${x} == en ]] || [[ ${x} == en-US ]]; then
143 # strip region subtag if $x is in the list
144 if has ${x} "${MOZ_TOO_REGIONALIZED_FOR_L10N[@]}" ; then
149 SRC_URI+=" l10n_${xflag/[_@]/-}? ("
150 [[ -n ${MOZ_FTP_URI} ]] && SRC_URI+="
151 ${MOZ_FTP_URI}/${MOZ_LANGPACK_PREFIX}${x}${MOZ_LANGPACK_SUFFIX} -> ${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}.xpi"
152 [[ -n ${MOZ_LANGPACK_HTTP_URI} ]] && SRC_URI+="
153 ${MOZ_LANGPACK_HTTP_URI}/${MOZ_LANGPACK_PREFIX}${x}${MOZ_LANGPACK_SUFFIX} -> ${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}.xpi"
155 IUSE+=" l10n_${xflag/[_@]/-}"
156 # We used to do some magic if specific/generic locales were missing, but
157 # we stopped doing that due to bug 325195.
161 for x in "${MOZ_LANGS[@]}" ; do
162 # en and en_US are handled internally
163 if [[ ${x} == en ]] || [[ ${x} == en-US ]]; then
166 # strip region subtag if $x is in the list
167 if has ${x} "${MOZ_TOO_REGIONALIZED_FOR_L10N[@]}" ; then
172 # Do NOT grab l10n sources from hg tip at this time, since it is a moving target
173 # if [[ ${PV} =~ alpha ]]; then
174 # # Please note that this URI is not deterministic - digest breakage could occur
175 # SRC_URI+=" l10n_${xflag/[_@]/-}? ( http://hg.mozilla.org/releases/l10n/mozilla-aurora/ach/archive/tip.tar.bz2 -> ${MOZ_P}-l10n-${x}.tar.bz2 )"
176 # elif [[ ${PV} =~ beta ]] && ! [[ ${PN} == seamonkey ]]; then
177 # # Please note that this URI is not deterministic - digest breakage could occur
178 # SRC_URI+=" l10n_${xflag/[_@]/-}? ( http://hg.mozilla.org/releases/l10n/mozilla-beta/ach/archive/tip.tar.bz2 -> ${MOZ_P}-l10n-${x}.tar.bz2 )"
179 # elif [[ -n ${MOZ_L10N_URI_PREFIX} ]]; then
180 if [[ -n ${MOZ_L10N_URI_PREFIX} ]]; then
181 SRC_URI+=" l10n_${xflag/[_@]/-}? ( ${MOZ_L10N_URI_PREFIX}${x}${MOZ_L10N_URI_SUFFIX} )"
183 IUSE+=" l10n_${xflag/[_@]/-}"
188 # @FUNCTION: mozlinguas_export
191 # Generate the list of language packs called "mozlinguas"
192 # This list is used to unpack and install the xpi language packs
193 mozlinguas_export() {
194 if [[ ${PN} == seamonkey ]] ; then
195 [[ ${PV} =~ alpha ]] && ! [[ -n ${MOZ_GENERATE_LANGPACKS} ]] && return
197 [[ ${PV} =~ alpha|beta ]] && ! [[ -n ${MOZ_GENERATE_LANGPACKS} ]] && return
201 # Set mozlinguas based on the enabled l10n_* USE flags.
202 for lingua in "${MOZ_LANGS[@]}"; do
203 # strip region subtag if $x is in the list
204 if has ${lingua} en en-US; then
205 # For mozilla products, en and en_US are handled internally
207 elif has ${lingua} "${MOZ_TOO_REGIONALIZED_FOR_L10N[@]}" ; then
212 use l10n_${lflag/[_@]/-} && mozlinguas+=( ${lingua} )
214 # Compatibility code - Check LINGUAS and warn if anything set there isn't enabled via l10n
215 for lingua in ${LINGUAS}; do
216 if has ${lingua//[_@]/-} en en-US; then
217 # For mozilla products, en and en_US are handled internally
219 # If this language is supported by ${P},
220 elif has ${lingua} "${MOZ_LANGS[@]//-/_}"; then
221 # Warn the language is missing, if it isn't already there
222 has ${lingua//[_@]/-} "${mozlinguas[@]//[_@]/-}" || \
223 ewarn "LINGUAS value ${lingua} is not enabled using L10N use flags"
225 # For each short lingua that isn't in MOZ_LANGS,
226 # We used to add *all* long MOZ_LANGS to the mozlinguas list,
227 # but we stopped doing that due to bug 325195.
231 ewarn "Sorry, but ${P} does not support the ${lingua} locale"
235 # @FUNCTION: mozlinguas_src_unpack
237 # Unpack xpi language packs according to the user's LINGUAS settings
238 mozlinguas_src_unpack() {
240 if ! [[ -n ${MOZ_GENERATE_LANGPACKS} ]]; then
242 for x in "${mozlinguas[@]}"; do
243 # FIXME: Add support for unpacking xpis to portage
244 xpi_unpack "${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}.xpi"
246 if [[ "${mozlinguas[*]}" != "" && "${mozlinguas[*]}" != "en" ]]; then
247 einfo "Selected language packs (first will be default): ${mozlinguas[*]}"
251 # For the phase function export
252 mozlinguas-v2_src_unpack() {
253 mozlinguas_src_unpack
257 # @FUNCTION: mozlinguas_mozconfig
259 # if applicable, add the necessary flag to .mozconfig to support
260 # the generation of locales. Note that this function requires
261 # mozconfig_annontate to already be declared via an inherit of
262 # mozconfig or mozcoreconf.
263 mozlinguas_mozconfig() {
264 if [[ -n ${MOZ_GENERATE_LANGPACKS} ]]; then
265 if declare -f mozconfig_annotate >/dev/null ; then
266 mozconfig_annotate 'for building locales' --with-l10n-base=${MOZ_L10N_SOURCEDIR}
268 die "Could not configure l10n-base, mozconfig_annotate not declared -- missing inherit?"
273 # @FUNCTION: mozlinguas_src_compile
275 # if applicable, build the selected locales.
276 mozlinguas_src_compile() {
277 if [[ -n ${MOZ_GENERATE_LANGPACKS} ]]; then
278 # leverage BUILD_OBJ_DIR if set otherwise assume PWD.
279 local x y targets=( "langpack" ) localedir="${BUILD_OBJ_DIR:-.}"
282 localedir+="/browser/locales"
285 localedir+="/suite/locales"
288 localedir+="/mail/locales"
289 targets+=( "calendar-langpack" )
291 *) die "Building locales for ${PN} is not supported."
293 pushd "${localedir}" > /dev/null || die
295 for x in "${mozlinguas[@]}"; do for y in "${targets[@]}"; do
296 emake ${y}-${x} LOCALE_MERGEDIR="./${y}-${x}"
298 popd > /dev/null || die
302 # For the phase function export
303 mozlinguas-v2_src_compile() {
304 mozlinguas_src_compile
307 # @FUNCTION: mozlinguas_xpistage_langpacks
309 # Add extra langpacks to the xpi-stage dir for prebuilt plugins
311 # First argument is the path to the extension
312 # Second argument is the prefix of the source (same as first if unspecified)
313 # Remaining arguments are the modules in the extension that are localized
314 # (basename of first if unspecified)
316 # Example - installing extra langpacks for lightning:
318 # ... # general installation steps
319 # mozlinguas_xpistage_langpacks \
320 # "${BUILD_OBJ_DIR}"/dist/xpi-stage/lightning \
321 # "${WORKDIR}"/lightning \
323 # ... # proceed with installation from the xpi-stage dir
326 mozlinguas_xpistage_langpacks() {
327 local l c modpath="${1}" srcprefix="${1}" modules=( "${1##*/}" )
329 if [[ -n ${1} ]] ; then srcprefix="${1}" ; shift ; fi
330 if [[ -n ${1} ]] ; then modules=( $@ ) ; fi
333 mkdir -p "${modpath}/chrome" || die
334 for l in "${mozlinguas[@]}"; do for c in "${modules[@]}" ; do
335 if [[ -e "${srcprefix}-${l}/chrome/${c}-${l}" ]]; then
336 cp -RLp -t "${modpath}/chrome" "${srcprefix}-${l}/chrome/${c}-${l}" || die
337 grep "locale ${c} ${l} chrome/" "${srcprefix}-${l}/chrome.manifest" \
338 >>"${modpath}/chrome.manifest" || die
339 elif [[ -e "${srcprefix}/chrome/${c}-${l}" ]]; then
340 cp -RLp -t "${modpath}/chrome" "${srcprefix}/chrome/${c}-${l}" || die
341 grep "locale ${c} ${l} chrome/" "${srcprefix}/chrome.manifest" \
342 >>"${modpath}/chrome.manifest" || die
344 ewarn "Locale ${l} was not found for ${c}, skipping."
349 # @FUNCTION: mozlinguas-v2_src_install
351 # Install xpi language packs according to the user's L10N settings
352 # NOTE - uses ${BUILD_OBJ_DIR} or PWD if unset, for source-generated langpacks
353 mozlinguas_src_install() {
356 if [[ -n ${MOZ_GENERATE_LANGPACKS} ]] && [[ -n ${mozlinguas[*]} ]]; then
357 local repopath="${WORKDIR}/${PN}-generated-langpacks"
358 mkdir -p "${repopath}" || die
359 pushd "${BUILD_OBJ_DIR:-.}"/dist/*/xpi > /dev/null || die
360 for x in "${mozlinguas[@]}"; do
361 cp "${MOZ_P}.${x}.langpack.xpi" \
362 "${repopath}/${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}.xpi" || die
363 xpi_unpack "${repopath}/${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}.xpi"
365 popd > /dev/null || die
367 for x in "${mozlinguas[@]}"; do
368 xpi_install "${WORKDIR}/${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}"
372 # For the phase function export
373 mozlinguas-v2_src_install() {
374 mozlinguas_src_install