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