mail-client/thunderbird: amd64 & x86 stable
[gentoo.git] / mail-client / thunderbird / thunderbird-68.5.0.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5 VIRTUALX_REQUIRED="pgo"
6 WANT_AUTOCONF="2.1"
7 MOZ_ESR=""
8 MOZ_LIGHTNING_VER="6.2.5"
9 MOZ_LIGHTNING_GDATA_VER="4.4.1"
10
11 PYTHON_COMPAT=( python3_{6,7} )
12 PYTHON_REQ_USE='ncurses,sqlite,ssl,threads(+)'
13
14 # This list can be updated using scripts/get_langs.sh from the mozilla overlay
15 MOZ_LANGS=(ar ast be bg br ca cs cy da de el en en-GB en-US es-AR
16 es-ES et eu fi fr fy-NL ga-IE gd gl he hr hsb hu hy-AM id is it
17 ja ko lt nb-NO nl nn-NO pl pt-BR pt-PT rm ro ru si sk sl sq sr
18 sv-SE tr uk vi zh-CN zh-TW )
19
20 # Convert the ebuild version to the upstream mozilla version, used by mozlinguas
21 MOZ_PV="${PV/_beta/b}"
22
23 # Patches
24 PATCHFF="firefox-68.0-patches-12"
25
26 MOZ_HTTP_URI="https://archive.mozilla.org/pub/${PN}/releases"
27
28 # ESR releases have slightly version numbers
29 if [[ ${MOZ_ESR} == 1 ]]; then
30         MOZ_PV="${MOZ_PV}esr"
31 fi
32 MOZ_P="${PN}-${MOZ_PV}"
33
34 LLVM_MAX_SLOT=9
35
36 DESCRIPTION="Thunderbird Mail Client"
37 HOMEPAGE="https://www.mozilla.org/thunderbird"
38
39 KEYWORDS="amd64 ~ppc64 x86 ~amd64-linux ~x86-linux"
40 SLOT="0"
41 LICENSE="MPL-2.0 GPL-2 LGPL-2.1"
42 IUSE="bindist clang cpu_flags_x86_avx2 dbus debug eme-free
43         +gmp-autoupdate hardened jack lightning lto cpu_flags_arm_neon pgo
44         pulseaudio selinux startup-notification +system-av1 +system-harfbuzz
45         +system-icu +system-jpeg +system-libevent +system-sqlite
46         +system-libvpx +system-webp test wayland wifi"
47 RESTRICT="!bindist? ( bindist )
48         !test? ( test )"
49
50 PATCH_URIS=( https://dev.gentoo.org/~{anarchy,axs,polynomial-c,whissi}/mozilla/patchsets/${PATCHFF}.tar.xz )
51 SRC_URI="${SRC_URI}
52         ${MOZ_HTTP_URI}/${MOZ_PV}/source/${MOZ_P}.source.tar.xz
53         https://dev.gentoo.org/~axs/distfiles/lightning-${MOZ_LIGHTNING_VER}.tar.xz
54         lightning? ( https://dev.gentoo.org/~axs/distfiles/gdata-provider-${MOZ_LIGHTNING_GDATA_VER}.tar.xz )
55         ${PATCH_URIS[@]}"
56
57 inherit check-reqs eapi7-ver flag-o-matic toolchain-funcs eutils \
58                 gnome2-utils llvm mozcoreconf-v6 pax-utils xdg-utils \
59                 autotools mozlinguas-v2 virtualx multiprocessing
60
61 CDEPEND="
62         >=dev-libs/nss-3.44.1
63         >=dev-libs/nspr-4.21
64         dev-libs/atk
65         dev-libs/expat
66         >=x11-libs/cairo-1.10[X]
67         >=x11-libs/gtk+-2.18:2
68         >=x11-libs/gtk+-3.4.0:3[X]
69         x11-libs/gdk-pixbuf
70         >=x11-libs/pango-1.22.0
71         >=media-libs/libpng-1.6.35:0=[apng]
72         >=media-libs/mesa-10.2:*
73         media-libs/fontconfig
74         >=media-libs/freetype-2.4.10
75         kernel_linux? ( !pulseaudio? ( media-libs/alsa-lib ) )
76         virtual/freedesktop-icon-theme
77         dbus? ( >=sys-apps/dbus-0.60
78                 >=dev-libs/dbus-glib-0.72 )
79         startup-notification? ( >=x11-libs/startup-notification-0.8 )
80         >=x11-libs/pixman-0.19.2
81         >=dev-libs/glib-2.26:2
82         >=sys-libs/zlib-1.2.3
83         >=virtual/libffi-3.0.10:=
84         virtual/ffmpeg
85         x11-libs/libX11
86         x11-libs/libXcomposite
87         x11-libs/libXdamage
88         x11-libs/libXext
89         x11-libs/libXfixes
90         x11-libs/libXrender
91         x11-libs/libXt
92         system-av1? (
93                 >=media-libs/dav1d-0.3.0:=
94                 >=media-libs/libaom-1.0.0:=
95         )
96         system-harfbuzz? ( >=media-libs/harfbuzz-2.4.0:0= >=media-gfx/graphite2-1.3.13 )
97         system-icu? ( >=dev-libs/icu-63.1:= )
98         system-jpeg? ( >=media-libs/libjpeg-turbo-1.2.1 )
99         system-libevent? ( >=dev-libs/libevent-2.0:0=[threads] )
100         system-libvpx? ( =media-libs/libvpx-1.7*:0=[postproc] )
101         system-sqlite? ( >=dev-db/sqlite-3.28.0:3[secure-delete,debug=] )
102         system-webp? ( >=media-libs/libwebp-1.0.2:0= )
103         wifi? ( kernel_linux? ( >=sys-apps/dbus-0.60
104                         >=dev-libs/dbus-glib-0.72
105                         net-misc/networkmanager ) )
106         jack? ( virtual/jack )
107         selinux? ( sec-policy/selinux-mozilla )"
108
109 RDEPEND="${CDEPEND}
110         jack? ( virtual/jack )
111         pulseaudio? ( || ( media-sound/pulseaudio
112                 >=media-sound/apulse-0.1.9 ) )
113         selinux? ( sec-policy/selinux-mozilla )"
114
115 DEPEND="${CDEPEND}
116         app-arch/zip
117         app-arch/unzip
118         >=dev-util/cbindgen-0.8.7
119         >=net-libs/nodejs-8.11.0
120         >=sys-devel/binutils-2.30
121         sys-apps/findutils
122         || (
123                 (
124                         sys-devel/clang:9
125                         !clang? ( sys-devel/llvm:9 )
126                         clang? (
127                                 =sys-devel/lld-9*
128                                 sys-devel/llvm:9[gold]
129                                 pgo? ( =sys-libs/compiler-rt-sanitizers-9*[profile] )
130                         )
131                 )
132                 (
133                         sys-devel/clang:8
134                         !clang? ( sys-devel/llvm:8 )
135                         clang? (
136                                 =sys-devel/lld-8*
137                                 sys-devel/llvm:8[gold]
138                                 pgo? ( =sys-libs/compiler-rt-sanitizers-8*[profile] )
139                         )
140                 )
141                 (
142                         sys-devel/clang:7
143                         !clang? ( sys-devel/llvm:7 )
144                         clang? (
145                                 =sys-devel/lld-7*
146                                 sys-devel/llvm:7[gold]
147                                 pgo? ( =sys-libs/compiler-rt-sanitizers-7*[profile] )
148                         )
149                 )
150                 (
151                         sys-devel/clang:6
152                         !clang? ( sys-devel/llvm:6 )
153                         clang? (
154                                 =sys-devel/lld-6*
155                                 sys-devel/llvm:6[gold]
156                                 pgo? ( =sys-libs/compiler-rt-sanitizers-6*[profile] )
157                         )
158                 )
159         )
160         pulseaudio? ( media-sound/pulseaudio )
161         >=virtual/rust-1.34.0
162         wayland? ( >=x11-libs/gtk+-3.11:3[wayland] )
163         amd64? ( >=dev-lang/yasm-1.1 virtual/opengl )
164         x86? ( >=dev-lang/yasm-1.1 virtual/opengl )
165         !system-av1? (
166                 amd64? ( >=dev-lang/nasm-2.13 )
167                 x86? ( >=dev-lang/nasm-2.13 )
168         )"
169
170 REQUIRED_USE="wifi? ( dbus )
171         pgo? ( lto )"
172
173 S="${WORKDIR}/${MOZ_P%b[0-9]*}"
174
175 BUILD_OBJ_DIR="${S}/tbird"
176
177 # allow GMP_PLUGIN_LIST to be set in an eclass or
178 # overridden in the enviromnent (advanced hackers only)
179 if [[ -z $GMP_PLUGIN_LIST ]] ; then
180         GMP_PLUGIN_LIST=( gmp-gmpopenh264 gmp-widevinecdm )
181 fi
182
183 llvm_check_deps() {
184         if ! has_version --host-root "sys-devel/clang:${LLVM_SLOT}" ; then
185                 ewarn "sys-devel/clang:${LLVM_SLOT} is missing! Cannot use LLVM slot ${LLVM_SLOT} ..." >&2
186                 return 1
187         fi
188
189         if use clang ; then
190                 if ! has_version --host-root "=sys-devel/lld-${LLVM_SLOT}*" ; then
191                         ewarn "=sys-devel/lld-${LLVM_SLOT}* is missing! Cannot use LLVM slot ${LLVM_SLOT} ..." >&2
192                         return 1
193                 fi
194
195                 if use pgo ; then
196                         if ! has_version --host-root "=sys-libs/compiler-rt-sanitizers-${LLVM_SLOT}*" ; then
197                                 ewarn "=sys-libs/compiler-rt-sanitizers-${LLVM_SLOT}* is missing! Cannot use LLVM slot ${LLVM_SLOT} ..." >&2
198                                 return 1
199                         fi
200                 fi
201         fi
202
203         einfo "Will use LLVM slot ${LLVM_SLOT}!" >&2
204 }
205
206 pkg_setup() {
207         moz_pkgsetup
208
209         if use pgo ; then
210                 if ! has usersandbox $FEATURES ; then
211                         die "You must enable usersandbox as X server can not run as root!"
212                 fi
213         fi
214
215         # Avoid PGO profiling problems due to enviroment leakage
216         # These should *always* be cleaned up anyway
217         unset DBUS_SESSION_BUS_ADDRESS \
218                 DISPLAY \
219                 ORBIT_SOCKETDIR \
220                 SESSION_MANAGER \
221                 XDG_SESSION_COOKIE \
222                 XAUTHORITY
223
224         if ! use bindist ; then
225                 einfo
226                 elog "You are enabling official branding. You may not redistribute this build"
227                 elog "to any users on your network or the internet. Doing so puts yourself into"
228                 elog "a legal problem with Mozilla Foundation."
229                 elog "You can disable it by emerging ${PN} _with_ the bindist USE-flag."
230         fi
231
232         addpredict /proc/self/oom_score_adj
233
234         llvm_pkg_setup
235 }
236
237 pkg_pretend() {
238         # Ensure we have enough disk space to compile
239         if use pgo || use lto || use debug || use test ; then
240                 CHECKREQS_DISK_BUILD="8G"
241         else
242                 CHECKREQS_DISK_BUILD="4G"
243         fi
244
245         check-reqs_pkg_setup
246 }
247
248 src_unpack() {
249         unpack ${A}
250
251         # Unpack language packs
252         mozlinguas_src_unpack
253 }
254
255 src_prepare() {
256         # Apply firefox patchset then apply thunderbird patches
257         rm "${WORKDIR}"/firefox/2013_avoid_noinline_on_GCC_with_skcms.patch || die
258         rm "${WORKDIR}"/firefox/2015_fix_cssparser.patch || die
259         eapply "${WORKDIR}/firefox"
260         pushd "${S}"/comm &>/dev/null || die
261         eapply "${FILESDIR}/1000_fix_gentoo_preferences.patch"
262         popd &>/dev/null || die
263
264         # Allow user to apply any additional patches without modifing ebuild
265         eapply_user
266
267         local n_jobs=$(makeopts_jobs)
268         if [[ ${n_jobs} == 1 ]]; then
269                 einfo "Building with MAKEOPTS=-j1 is known to fail (bug #687028); Forcing MAKEOPTS=-j2 ..."
270                 export MAKEOPTS=-j2
271         fi
272
273         # Enable gnomebreakpad
274         if use debug ; then
275                 sed -i -e "s:GNOME_DISABLE_CRASH_DIALOG=1:GNOME_DISABLE_CRASH_DIALOG=0:g" \
276                         "${S}"/build/unix/run-mozilla.sh || die "sed failed!"
277         fi
278
279         # Drop -Wl,--as-needed related manipulation for ia64 as it causes ld sefgaults, bug #582432
280         if use ia64 ; then
281                 sed -i \
282                 -e '/^OS_LIBS += no_as_needed/d' \
283                 -e '/^OS_LIBS += as_needed/d' \
284                 "${S}"/widget/gtk/mozgtk/gtk2/moz.build \
285                 "${S}"/widget/gtk/mozgtk/gtk3/moz.build \
286                 || die "sed failed to drop --as-needed for ia64"
287         fi
288
289         # Fix sandbox violations during make clean, bug 372817
290         sed -e "s:\(/no-such-file\):${T}\1:g" \
291                 -i "${S}"/config/rules.mk \
292                 -i "${S}"/nsprpub/configure{.in,} \
293                 || die
294
295         # Don't exit with error when some libs are missing which we have in
296         # system.
297         sed '/^MOZ_PKG_FATAL_WARNINGS/s@= 1@= 0@' \
298                 -i "${S}"/comm/mail/installer/Makefile.in || die
299
300         # Don't error out when there's no files to be removed:
301         sed 's@\(xargs rm\)$@\1 -f@' \
302                 -i "${S}"/toolkit/mozapps/installer/packager.mk || die
303
304         # Keep codebase the same even if not using official branding
305         sed '/^MOZ_DEV_EDITION=1/d' \
306                 -i "${S}"/browser/branding/aurora/configure.sh || die
307
308         # rustfmt, a tool to format Rust code, is optional and not required to build Firefox.
309         # However, when available, an unsupported version can cause problems, bug #669548
310         sed -i -e "s@check_prog('RUSTFMT', add_rustup_path('rustfmt')@check_prog('RUSTFMT', add_rustup_path('rustfmt_do_not_use')@" \
311                 "${S}"/build/moz.configure/rust.configure || die
312
313         # Autotools configure is now called old-configure.in
314         # This works because there is still a configure.in that happens to be for the
315         # shell wrapper configure script
316         eautoreconf old-configure.in
317
318         # Must run autoconf in js/src
319         cd "${S}"/js/src || die
320         eautoconf old-configure.in
321 }
322
323 src_configure() {
324         MEXTENSIONS="default"
325         # Google API keys (see http://www.chromium.org/developers/how-tos/api-keys)
326         # Note: These are for Gentoo Linux use ONLY. For your own distribution, please
327         # get your own set of keys.
328         _google_api_key=AIzaSyDEAOvatFo0eTgsV_ZlEzx0ObmepsMzfAc
329
330         # Add information about TERM to output (build.log) to aid debugging
331         # blessings problems
332         if [[ -n "${TERM}" ]] ; then
333                 einfo "TERM is set to: \"${TERM}\""
334         else
335                 einfo "TERM is unset."
336         fi
337
338         if use clang && ! tc-is-clang ; then
339                 # Force clang
340                 einfo "Enforcing the use of clang due to USE=clang ..."
341                 CC=${CHOST}-clang
342                 CXX=${CHOST}-clang++
343                 strip-unsupported-flags
344         elif ! use clang && ! tc-is-gcc ; then
345                 # Force gcc
346                 einfo "Enforcing the use of gcc due to USE=-clang ..."
347                 CC=${CHOST}-gcc
348                 CXX=${CHOST}-g++
349                 strip-unsupported-flags
350         fi
351
352         ####################################
353         #
354         # mozconfig, CFLAGS and CXXFLAGS setup
355         #
356         ####################################
357
358         mozconfig_init
359         # common config components
360         mozconfig_annotate 'system_libs' \
361                 --with-system-zlib \
362                 --with-system-bz2
363
364         # Must pass release in order to properly select linker
365         mozconfig_annotate 'Enable by Gentoo' --enable-release
366
367         if use pgo ; then
368                 if ! has userpriv $FEATURES ; then
369                         eerror "Building firefox with USE=pgo and FEATURES=-userpriv is not supported!"
370                 fi
371         fi
372
373         # Don't let user's LTO flags clash with upstream's flags
374         filter-flags -flto*
375
376         if use lto ; then
377                 local show_old_compiler_warning=
378
379                 if use clang ; then
380                         # At this stage CC is adjusted and the following check will
381                         # will work
382                         if [[ $(clang-major-version) -lt 7 ]] ; then
383                                 show_old_compiler_warning=1
384                         fi
385
386                         # Upstream only supports lld when using clang
387                         mozconfig_annotate "forcing ld=lld due to USE=clang and USE=lto" --enable-linker=lld
388                 else
389                         if [[ $(gcc-major-version) -lt 8 ]] ; then
390                                 show_old_compiler_warning=1
391                         fi
392
393                         # Bug 689358
394                         append-cxxflags -flto
395
396                         if ! use cpu_flags_x86_avx2 ; then
397                                 local _gcc_version_with_ipa_cdtor_fix="8.3"
398                                 local _current_gcc_version="$(gcc-major-version).$(gcc-minor-version)"
399
400                                 if ver_test "${_current_gcc_version}" -lt "${_gcc_version_with_ipa_cdtor_fix}" ; then
401                                         # due to a GCC bug, GCC will produce AVX2 instructions
402                                         # even if the CPU doesn't support AVX2, https://gcc.gnu.org/ml/gcc-patches/2018-12/msg01142.html
403                                         einfo "Disable IPA cdtor due to bug in GCC and missing AVX2 support -- triggered by USE=lto"
404                                         append-ldflags -fdisable-ipa-cdtor
405                                 else
406                                         einfo "No GCC workaround required, GCC version is already patched!"
407                                 fi
408                         else
409                                 einfo "No GCC workaround required, system supports AVX2"
410                         fi
411
412                         # Linking only works when using ld.gold when LTO is enabled
413                         mozconfig_annotate "forcing ld=gold due to USE=lto" --enable-linker=gold
414                 fi
415
416                 if [[ -n "${show_old_compiler_warning}" ]] ; then
417                         # Checking compiler's major version uses CC variable. Because we allow
418                         # user to control used compiler via USE=clang flag, we cannot use
419                         # initial value. So this is the earliest stage where we can do this check
420                         # because pkg_pretend is not called in the main phase function sequence
421                         # environment saving is not guaranteed so we don't know if we will have
422                         # correct compiler until now.
423                         ewarn ""
424                         ewarn "USE=lto requires up-to-date compiler (>=gcc-8 or >=clang-7)."
425                         ewarn "You are on your own -- expect build failures. Don't file bugs using that unsupported configuration!"
426                         ewarn ""
427                         sleep 5
428                 fi
429
430                 mozconfig_annotate '+lto' --enable-lto=thin
431
432                 if use pgo ; then
433                         mozconfig_annotate '+pgo' MOZ_PGO=1
434                 fi
435         else
436                 # Avoid auto-magic on linker
437                 if use clang ; then
438                         # This is upstream's default
439                         mozconfig_annotate "forcing ld=lld due to USE=clang" --enable-linker=lld
440                 elif tc-ld-is-gold ; then
441                         mozconfig_annotate "linker is set to gold" --enable-linker=gold
442                 else
443                         mozconfig_annotate "linker is set to bfd" --enable-linker=bfd
444                 fi
445         fi
446
447         # It doesn't compile on alpha without this LDFLAGS
448         use alpha && append-ldflags "-Wl,--no-relax"
449
450         # Add full relro support for hardened
451         if use hardened ; then
452                 append-ldflags "-Wl,-z,relro,-z,now"
453                 mozconfig_use_enable hardened hardening
454         fi
455
456         # Modifications to better support ARM, bug 553364
457         if use cpu_flags_arm_neon ; then
458                 mozconfig_annotate '' --with-fpu=neon
459
460                 if ! tc-is-clang ; then
461                         # thumb options aren't supported when using clang, bug 666966
462                         mozconfig_annotate '' --with-thumb=yes
463                         mozconfig_annotate '' --with-thumb-interwork=no
464                 fi
465         fi
466
467         if [[ ${CHOST} == armv*h* ]] ; then
468                 mozconfig_annotate '' --with-float-abi=hard
469                 if ! use system-libvpx ; then
470                         sed -i -e "s|softfp|hard|" \
471                                 "${S}"/media/libvpx/moz.build
472                 fi
473         fi
474
475         mozconfig_use_enable !bindist official-branding
476
477         mozconfig_use_enable debug
478         mozconfig_use_enable debug tests
479         if ! use debug ; then
480                 mozconfig_annotate 'disabled by Gentoo' --disable-debug-symbols
481         else
482                 mozconfig_annotate 'enabled by Gentoo' --enable-debug-symbols
483         fi
484         # These are enabled by default in all mozilla applications
485         mozconfig_annotate '' --with-system-nspr --with-nspr-prefix="${SYSROOT}${EPREFIX}"/usr
486         mozconfig_annotate '' --with-system-nss --with-nss-prefix="${SYSROOT}${EPREFIX}"/usr
487         mozconfig_annotate '' --x-includes="${SYSROOT}${EPREFIX}"/usr/include \
488                 --x-libraries="${SYSROOT}${EPREFIX}"/usr/$(get_libdir)
489         mozconfig_annotate '' --prefix="${EPREFIX}"/usr
490         mozconfig_annotate '' --libdir="${EPREFIX}"/usr/$(get_libdir)
491         mozconfig_annotate '' --disable-crashreporter
492         mozconfig_annotate 'Gentoo default' --with-system-png
493         mozconfig_annotate '' --enable-system-ffi
494         mozconfig_annotate '' --disable-gconf
495         mozconfig_annotate '' --with-intl-api
496         mozconfig_annotate '' --enable-system-pixman
497         # Instead of the standard --build= and --host=, mozilla uses --host instead
498         # of --build, and --target intstead of --host.
499         # Note, mozilla also has --build but it does not do what you think it does.
500         # Set both --target and --host as mozilla uses python to guess values otherwise
501         mozconfig_annotate '' --target="${CHOST}"
502         mozconfig_annotate '' --host="${CBUILD:-${CHOST}}"
503         if use system-libevent ; then
504                 mozconfig_annotate '' --with-system-libevent="${SYSROOT}${EPREFIX}"/usr
505         fi
506
507         if ! use x86 && [[ ${CHOST} != armv*h* ]] ; then
508                 mozconfig_annotate '' --enable-rust-simd
509         fi
510
511         # use the gtk3 toolkit (the only one supported at this point)
512         # TODO: Will this result in automagic dependency on x11-libs/gtk+[wayland]?
513         if use wayland ; then
514                 mozconfig_annotate '' --enable-default-toolkit=cairo-gtk3-wayland
515         else
516                 mozconfig_annotate '' --enable-default-toolkit=cairo-gtk3
517         fi
518
519         mozconfig_use_enable startup-notification
520         mozconfig_use_enable system-sqlite
521         mozconfig_use_with system-av1
522         mozconfig_use_with system-harfbuzz
523         mozconfig_use_with system-harfbuzz system-graphite2
524         mozconfig_use_with system-icu
525         mozconfig_use_with system-jpeg
526         mozconfig_use_with system-libvpx
527         mozconfig_use_with system-webp
528         mozconfig_use_enable pulseaudio
529         # force the deprecated alsa sound code if pulseaudio is disabled
530         if use kernel_linux && ! use pulseaudio ; then
531                 mozconfig_annotate '-pulseaudio' --enable-alsa
532         fi
533
534         # Disable built-in ccache support to avoid sandbox violation, #665420
535         # Use FEATURES=ccache instead!
536         mozconfig_annotate '' --without-ccache
537         sed -i -e 's/ccache_stats = None/return None/' \
538                 python/mozbuild/mozbuild/controller/building.py || \
539                 die "Failed to disable ccache stats call"
540
541         mozconfig_use_enable dbus
542
543         mozconfig_use_enable wifi necko-wifi
544
545         # enable JACK, bug 600002
546         mozconfig_use_enable jack
547
548         # Other tb-specific settings
549         mozconfig_annotate '' --with-user-appdir=.thunderbird
550         mozconfig_annotate '' --enable-ldap
551         mozconfig_annotate '' --enable-calendar
552
553         # Enable/Disable eme support
554         use eme-free && mozconfig_annotate '+eme-free' --disable-eme
555
556         # Setup api key for location services and safebrowsing, https://bugzilla.mozilla.org/show_bug.cgi?id=1531176#c34
557         echo -n "${_google_api_key}" > "${S}"/google-api-key
558         mozconfig_annotate '' --with-google-location-service-api-keyfile="${S}/google-api-key"
559         mozconfig_annotate '' --with-google-safebrowsing-api-keyfile="${S}/google-api-key"
560
561         mozconfig_annotate '' --enable-extensions="${MEXTENSIONS}"
562
563         # allow elfhack to work in combination with unstripped binaries
564         # when they would normally be larger than 2GiB.
565         append-ldflags "-Wl,--compress-debug-sections=zlib"
566
567         if use clang ; then
568                 # https://bugzilla.mozilla.org/show_bug.cgi?id=1482204
569                 # https://bugzilla.mozilla.org/show_bug.cgi?id=1483822
570                 mozconfig_annotate 'elf-hack is broken when using Clang' --disable-elf-hack
571         fi
572
573         echo "mk_add_options MOZ_OBJDIR=${BUILD_OBJ_DIR}" >> "${S}"/.mozconfig
574         echo "mk_add_options XARGS=/usr/bin/xargs" >> "${S}"/.mozconfig
575
576         # Finalize and report settings
577         mozconfig_final
578
579         mkdir -p "${S}"/third_party/rust/libloading/.deps
580
581         # workaround for funky/broken upstream configure...
582         SHELL="${SHELL:-${EPREFIX}/bin/bash}" MOZ_NOSPAM=1 \
583         ./mach configure || die
584 }
585
586 src_compile() {
587         local _virtx=
588         if use pgo ; then
589                 _virtx=virtx
590
591                 # Reset and cleanup environment variables used by GNOME/XDG
592                 gnome2_environment_reset
593
594                 addpredict /root
595                 addpredict /etc/gconf
596         fi
597
598         GDK_BACKEND=x11 \
599                 MOZ_MAKE_FLAGS="${MAKEOPTS} -O" \
600                 SHELL="${SHELL:-${EPREFIX}/bin/bash}" \
601                 MOZ_NOSPAM=1 \
602                 ${_virtx} \
603                 ./mach build --verbose \
604                 || die
605 }
606
607 src_install() {
608         MOZILLA_FIVE_HOME="/usr/$(get_libdir)/${PN}"
609         cd "${BUILD_OBJ_DIR}" || die
610
611         # Pax mark xpcshell for hardened support, only used for startupcache creation.
612         pax-mark m "${BUILD_OBJ_DIR}"/dist/bin/xpcshell
613
614         # Copy our preference before omnijar is created.
615         cp "${FILESDIR}"/thunderbird-gentoo-default-prefs.js-2 \
616                 "${BUILD_OBJ_DIR}/dist/bin/defaults/pref/all-gentoo.js" \
617                 || die
618
619         # set dictionary path, to use system hunspell
620         echo "pref(\"spellchecker.dictionary_path\", \"${EPREFIX}/usr/share/myspell\");" \
621                 >>"${BUILD_OBJ_DIR}/dist/bin/defaults/pref/all-gentoo.js" || die
622
623         # force the graphite pref if system-harfbuzz is enabled, since the pref cant disable it
624         if use system-harfbuzz ; then
625                 echo "sticky_pref(\"gfx.font_rendering.graphite.enabled\",true);" \
626                         >>"${BUILD_OBJ_DIR}/dist/bin/defaults/pref/all-gentoo.js" || die
627         fi
628
629         # force cairo as the canvas renderer on platforms without skia support
630         if [[ $(tc-endian) == "big" ]] ; then
631                 echo "sticky_pref(\"gfx.canvas.azure.backends\",\"cairo\");" \
632                         >>"${BUILD_OBJ_DIR}/dist/bin/defaults/pref/all-gentoo.js" || die
633                 echo "sticky_pref(\"gfx.content.azure.backends\",\"cairo\");" \
634                         >>"${BUILD_OBJ_DIR}/dist/bin/defaults/pref/all-gentoo.js" || die
635         fi
636
637         echo "pref(\"extensions.autoDisableScopes\", 3);" >> \
638                 "${BUILD_OBJ_DIR}/dist/bin/defaults/pref/all-gentoo.js" \
639                 || die
640
641         local plugin
642         use gmp-autoupdate || use eme-free || for plugin in "${GMP_PLUGIN_LIST[@]}" ; do
643                 echo "pref(\"media.${plugin}.autoupdate\", false);" >> \
644                         "${BUILD_OBJ_DIR}/dist/bin/defaults/pref/all-gentoo.js" \
645                         || die
646         done
647
648         cd "${S}"
649         MOZ_MAKE_FLAGS="${MAKEOPTS}" SHELL="${SHELL:-${EPREFIX}/bin/bash}" MOZ_NOSPAM=1 \
650         DESTDIR="${D}" ./mach install || die
651
652         # Install language packs
653         MOZ_INSTALL_L10N_XPIFILE="1" mozlinguas_src_install
654
655         local size sizes icon_path icon
656         if ! use bindist; then
657                 icon_path="${S}/comm/mail/branding/thunderbird"
658                 icon="${PN}-icon"
659
660                 domenu "${FILESDIR}"/icon/${PN}.desktop
661         else
662                 icon_path="${S}/comm/mail/branding/nightly"
663                 icon="${PN}-icon-unbranded"
664
665                 newmenu "${FILESDIR}"/icon/${PN}-unbranded.desktop \
666                         ${PN}.desktop
667
668                 sed -i -e "s:Mozilla\ Thunderbird:EarlyBird:g" \
669                         "${ED}"/usr/share/applications/${PN}.desktop
670         fi
671
672         # Install a 48x48 icon into /usr/share/pixmaps for legacy DEs
673         newicon "${icon_path}"/default48.png "${icon}".png
674         # Install icons for menu entry
675         sizes="16 22 24 32 48 256"
676         for size in ${sizes}; do
677                 newicon -s ${size} "${icon_path}/default${size}.png" "${icon}.png"
678         done
679
680         # Disable built-in auto-update because we update firefox through package manager
681         insinto ${MOZILLA_FIVE_HOME}/distribution/
682         newins "${FILESDIR}"/disable-auto-update.policy.json policies.json
683
684         # Add StartupNotify=true bug 237317
685         if use startup-notification ; then
686                 echo "StartupNotify=true"\
687                          >> "${ED}/usr/share/applications/${PN}.desktop" \
688                         || die
689         fi
690
691         # Don't install llvm-symbolizer from sys-devel/llvm package
692         [[ -f "${ED%/}${MOZILLA_FIVE_HOME}/llvm-symbolizer" ]] && \
693                 rm "${ED%/}${MOZILLA_FIVE_HOME}/llvm-symbolizer"
694
695         local emid
696         # stage extra locales for lightning and install over existing
697         emid='{e2fda1a4-762b-4020-b5ad-a41df1933103}'
698         rm -f "${ED}"/${MOZILLA_FIVE_HOME}/distribution/extensions/${emid}.xpi || die
699         mozlinguas_xpistage_langpacks "${BUILD_OBJ_DIR}"/dist/bin/distribution/extensions/${emid} \
700                 "${WORKDIR}"/lightning-${MOZ_LIGHTNING_VER} lightning calendar
701
702         mkdir -p "${T}/${emid}" || die
703         cp -RLp -t "${T}/${emid}" "${BUILD_OBJ_DIR}"/dist/bin/distribution/extensions/${emid}/* || die
704         insinto ${MOZILLA_FIVE_HOME}/distribution/extensions
705         doins -r "${T}/${emid}"
706
707         if use lightning; then
708                 # move lightning out of distribution/extensions and into extensions for app-global install
709                 mkdir -p "${ED}"/${MOZILLA_FIVE_HOME}/extensions
710                 mv "${ED}"/${MOZILLA_FIVE_HOME}/{distribution,}/extensions/${emid} || die
711
712                 # stage extra locales for gdata-provider and install app-global
713                 mozlinguas_xpistage_langpacks "${BUILD_OBJ_DIR}"/dist/xpi-stage/gdata-provider \
714                         "${WORKDIR}"/gdata-provider-${MOZ_LIGHTNING_GDATA_VER}
715                 emid='{a62ef8ec-5fdc-40c2-873c-223b8a6925cc}'
716                 mkdir -p "${T}/${emid}" || die
717                 cp -RLp -t "${T}/${emid}" "${BUILD_OBJ_DIR}"/dist/xpi-stage/gdata-provider/* || die
718
719                 # manifest.json does not allow the addon to load, put install.rdf in place
720                 # note, version number needs to be set properly
721                 cp -RLp -t "${T}/${emid}" "${WORKDIR}"/gdata-provider-${MOZ_LIGHTNING_GDATA_VER}/install.rdf
722                 sed -i -e '/em:version/ s/>[^<]*</>4.1</' "${T}/${emid}"/install.rdf
723
724                 insinto ${MOZILLA_FIVE_HOME}/extensions
725                 doins -r "${T}/${emid}"
726         fi
727
728         # thunderbird and thunderbird-bin are identical
729         rm "${ED%/}"${MOZILLA_FIVE_HOME}/thunderbird-bin || die
730         dosym thunderbird ${MOZILLA_FIVE_HOME}/thunderbird-bin
731
732         # Required in order to use plugins and even run thunderbird on hardened.
733         pax-mark pm "${ED%/}"${MOZILLA_FIVE_HOME}/{thunderbird,plugin-container}
734 }
735
736 pkg_preinst() {
737         # if the apulse libs are available in MOZILLA_FIVE_HOME then apulse
738         # doesn't need to be forced into the LD_LIBRARY_PATH
739         if use pulseaudio && has_version ">=media-sound/apulse-0.1.9" ; then
740                 einfo "APULSE found - Generating library symlinks for sound support"
741                 local lib
742                 pushd "${ED}"${MOZILLA_FIVE_HOME} &>/dev/null || die
743                 for lib in ../apulse/libpulse{.so{,.0},-simple.so{,.0}} ; do
744                         # a quickpkg rolled by hand will grab symlinks as part of the package,
745                         # so we need to avoid creating them if they already exist.
746                         if [[ ! -L ${lib##*/} ]] ; then
747                                 ln -s "${lib}" ${lib##*/} || die
748                         fi
749                 done
750                 popd &>/dev/null || die
751         fi
752 }
753
754 pkg_postinst() {
755         xdg_desktop_database_update
756         xdg_icon_cache_update
757
758         if ! use gmp-autoupdate && ! use eme-free ; then
759                 elog "USE='-gmp-autoupdate' has disabled the following plugins from updating or"
760                 elog "installing into new profiles:"
761                 local plugin
762                 for plugin in "${GMP_PLUGIN_LIST[@]}"; do elog "\t ${plugin}" ; done
763                 elog
764         fi
765
766         if use pulseaudio && has_version ">=media-sound/apulse-0.1.9" ; then
767                 elog "Apulse was detected at merge time on this system and so it will always be"
768                 elog "used for sound.  If you wish to use pulseaudio instead please unmerge"
769                 elog "media-sound/apulse."
770                 elog
771         fi
772 }
773
774 pkg_postrm() {
775         xdg_desktop_database_update
776         xdg_icon_cache_update
777 }