net-irc/limnoria: use HTTPS for GitHub and HOMEPAGE
[gentoo.git] / eclass / mozlinguas-v2.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: mozlinguas-v2.eclass
5 # @MAINTAINER:
6 # mozilla@gentoo.org
7 # @AUTHOR:
8 # Nirbheek Chauhan <nirbheek@gentoo.org>
9 # Ian Stakenvicius <axs@gentoo.org>
10 # @BLURB: Handle language packs for mozilla products
11 # @DESCRIPTION:
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.
15
16 inherit mozextension
17
18 case "${EAPI:-0}" in
19         0|1)
20                 die "EAPI ${EAPI:-0} does not support the '->' SRC_URI operator";;
21         2|3|4|5|6)
22                 EXPORT_FUNCTIONS src_unpack src_compile src_install;;
23         *)
24                 die "EAPI ${EAPI} is not supported, contact eclass maintainers";;
25 esac
26
27 # @ECLASS-VARIABLE: MOZ_LANGS
28 # @DESCRIPTION:
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
31 # mozilla overlay.
32 : ${MOZ_LANGS:=()}
33
34 # @ECLASS-VARIABLE: MOZ_PV
35 # @DESCRIPTION:
36 # Ebuild package version converted to equivalent upstream version.
37 # Defaults to ${PV}, and should be overridden for alphas, betas, and RCs
38 : ${MOZ_PV:="${PV}"}
39
40 # @ECLASS-VARIABLE: MOZ_PN
41 # @DESCRIPTION:
42 # Ebuild package name converted to equivalent upstream name.
43 # Defaults to ${PN}, and should be overridden for binary ebuilds.
44 : ${MOZ_PN:="${PN}"}
45
46 # @ECLASS-VARIABLE: MOZ_P
47 # @DESCRIPTION:
48 # Ebuild package name + version converted to upstream equivalent.
49 # Defaults to ${MOZ_PN}-${MOZ_PV}
50 : ${MOZ_P:="${MOZ_PN}-${MOZ_PV}"}
51
52 # @ECLASS-VARIABLE: MOZ_FTP_URI
53 # @DESCRIPTION:
54 # The ftp URI prefix for the release tarballs and language packs.
55 : ${MOZ_FTP_URI:=""}
56
57 # @ECLASS-VARIABLE: MOZ_HTTP_URI
58 # @DESCRIPTION:
59 # The http URI prefix for the release tarballs and language packs.
60 : ${MOZ_HTTP_URI:=""}
61
62 # @ECLASS-VARIABLE: MOZ_LANGPACK_HTTP_URI
63 # @DESCRIPTION:
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}}
67
68 # @ECLASS-VARIABLE: MOZ_LANGPACK_PREFIX
69 # @DESCRIPTION:
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/"}
73
74 # @ECLASS-VARIABLE: MOZ_LANGPACK_SUFFIX
75 # @DESCRIPTION:
76 # The suffix after the lang code in the langpack file URI.
77 # Defaults to '.xpi'
78 : ${MOZ_LANGPACK_SUFFIX:=".xpi"}
79
80 # @ECLASS-VARIABLE: MOZ_LANGPACK_UNOFFICIAL
81 # @DESCRIPTION:
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
87 # suffix.
88 : ${MOZ_LANGPACK_UNOFFICIAL:=""}
89
90 # @ECLASS-VARIABLE: MOZ_GENERATE_LANGPACKS
91 # @DESCRIPTION:
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.
96 # Defaults to empty.
97 : ${MOZ_GENERATE_LANGPACKS:=""}
98
99 # @ECLASS-VARIABLE: MOZ_L10N_SOURCEDIR
100 # @DESCRIPTION:
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"}
104
105 # @ECLASS-VARIABLE: MOZ_L10N_URI_PREFIX
106 # @DESCRIPTION:
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.
111 # Defaults to empty.
112 : ${MOZ_L10N_URI_PREFIX:=""}
113
114 # @ECLASS-VARIABLE: MOZ_L10N_URI_SUFFIX
115 # @DESCRIPTION:
116 # The suffix of l10n source distfiles.
117 # Defaults to '.tar.xz'
118 : ${MOZ_L10N_URI_SUFFIX:=".tar.xz"}
119
120 # @ECLASS-VARIABLE: MOZ_FORCE_UPSTREAM_L10N
121 # @DESCRIPTION:
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:=""}
125
126
127 # @ECLASS-VARIABLE: MOZ_TOO_REGIONALIZED_FOR_L10N
128 # @INTERNAL
129 # @DESCRIPTION:
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 )
132
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
141                         continue
142                 fi
143                 # strip region subtag if $x is in the list
144                 if has ${x} "${MOZ_TOO_REGIONALIZED_FOR_L10N[@]}" ; then
145                         xflag=${x%%-*}
146                 else
147                         xflag=${x}
148                 fi
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"
154                 SRC_URI+=" )"
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.
158         done
159         fi
160 else
161         for x in "${MOZ_LANGS[@]}" ; do
162                 # en and en_US are handled internally
163                 if [[ ${x} == en ]] || [[ ${x} == en-US ]]; then
164                         continue
165                 fi
166                 # strip region subtag if $x is in the list
167                 if has ${x} "${MOZ_TOO_REGIONALIZED_FOR_L10N[@]}" ; then
168                         xflag=${x%%-*}
169                 else
170                         xflag=${x}
171                 fi
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} )"
182                 fi
183                 IUSE+=" l10n_${xflag/[_@]/-}"
184         done
185 fi
186 unset x xflag
187
188 # @FUNCTION: mozlinguas_export
189 # @INTERNAL
190 # @DESCRIPTION:
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
196         else
197                 [[ ${PV} =~ alpha|beta ]] && ! [[ -n ${MOZ_GENERATE_LANGPACKS} ]] && return
198         fi
199         local lingua lflag
200         mozlinguas=()
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
206                         continue
207                 elif has ${lingua} "${MOZ_TOO_REGIONALIZED_FOR_L10N[@]}" ; then
208                         lflag=${lingua%%-*}
209                 else
210                         lflag=${lingua}
211                 fi
212                 use l10n_${lflag/[_@]/-} && mozlinguas+=( ${lingua} )
213         done
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
218                         continue
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"
224                         continue
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.
228                 else
229                         :
230                 fi
231                 ewarn "Sorry, but ${P} does not support the ${lingua} locale"
232         done
233 }
234
235 # @FUNCTION: mozlinguas_src_unpack
236 # @DESCRIPTION:
237 # Unpack xpi language packs according to the user's LINGUAS settings
238 mozlinguas_src_unpack() {
239         local x
240         if ! [[ -n ${MOZ_GENERATE_LANGPACKS} ]]; then
241                 mozlinguas_export
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"
245                 done
246                 if [[ "${mozlinguas[*]}" != "" && "${mozlinguas[*]}" != "en" ]]; then
247                         einfo "Selected language packs (first will be default): ${mozlinguas[*]}"
248                 fi
249         fi
250 }
251 # For the phase function export
252 mozlinguas-v2_src_unpack() {
253         mozlinguas_src_unpack
254 }
255
256
257 # @FUNCTION: mozlinguas_mozconfig
258 # @DESCRIPTION:
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}
267                 else
268                         die "Could not configure l10n-base, mozconfig_annotate not declared -- missing inherit?"
269                 fi
270         fi
271 }
272
273 # @FUNCTION: mozlinguas_src_compile
274 # @DESCRIPTION:
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:-.}"
280                 case ${PN} in
281                         *firefox)
282                                 localedir+="/browser/locales"
283                                 ;;
284                         seamonkey)
285                                 localedir+="/suite/locales"
286                                 ;;
287                         *thunderbird)
288                                 localedir+="/mail/locales"
289                                 targets+=( "calendar-langpack" )
290                                 ;;
291                         *) die "Building locales for ${PN} is not supported."
292                 esac
293                 pushd "${localedir}" > /dev/null || die
294                 mozlinguas_export
295                 for x in "${mozlinguas[@]}"; do for y in "${targets[@]}"; do
296                         emake ${y}-${x} LOCALE_MERGEDIR="./${y}-${x}"
297                 done; done
298                 popd > /dev/null || die
299         fi
300 }
301
302 # For the phase function export
303 mozlinguas-v2_src_compile() {
304         mozlinguas_src_compile
305 }
306
307 # @FUNCTION: mozlinguas_xpistage_langpacks
308 # @DESCRIPTION:
309 # Add extra langpacks to the xpi-stage dir for prebuilt plugins
310 #
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)
315 #
316 # Example - installing extra langpacks for lightning:
317 # src_install() {
318 #       ... # general installation steps
319 #       mozlinguas_xpistage_langpacks \
320 #               "${BUILD_OBJ_DIR}"/dist/xpi-stage/lightning \
321 #               "${WORKDIR}"/lightning \
322 #               lightning calendar
323 #       ... # proceed with installation from the xpi-stage dir
324 # }
325
326 mozlinguas_xpistage_langpacks() {
327         local l c modpath="${1}" srcprefix="${1}" modules=( "${1##*/}" )
328         shift
329         if [[ -n ${1} ]] ; then srcprefix="${1}" ; shift ; fi
330         if [[ -n ${1} ]] ; then modules=( $@ ) ; fi
331
332         mozlinguas_export
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
343                 else
344                         ewarn "Locale ${l} was not found for ${c}, skipping."
345                 fi
346         done; done
347 }
348
349 # @FUNCTION: mozlinguas-v2_src_install
350 # @DESCRIPTION:
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() {
354         local x
355         mozlinguas_export
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"
364                 done
365                 popd > /dev/null || die
366         fi
367         for x in "${mozlinguas[@]}"; do
368                 xpi_install "${WORKDIR}/${MOZ_P}-${x}${MOZ_LANGPACK_UNOFFICIAL:+.unofficial}"
369         done
370 }
371
372 # For the phase function export
373 mozlinguas-v2_src_install() {
374         mozlinguas_src_install
375 }