1 # This ebuild is a modified version of the work originally distributed with
2 # Gentoo GNU/Linux, covered by the following copyright and permission notice:
4 # Copyright 1999-2020 Gentoo Authors
5 # Distributed under the terms of the GNU General Public License v2
7 # The modifications are:
9 # * Apply patches to build on modern systems (2022-12)
10 # * Update to EAPI 8 (2023-04)
13 VIRTUALX_REQUIRED="pgo"
17 # This list can be updated with scripts/get_langs.sh from the mozilla overlay
18 MOZ_LANGS=( ach af an ar as ast az bg bn-BD bn-IN br bs ca cak cs cy da de dsb
19 el en en-GB en-US en-ZA eo es-AR es-CL es-ES es-MX et eu fa ff fi fr fy-NL ga-IE
20 gd gl gn gu-IN he hi-IN hr hsb hu hy-AM id is it ja ka kab kk km kn ko lij lt lv
21 mai mk ml mr ms nb-NO nl nn-NO or pa-IN pl pt-BR pt-PT rm ro ru si sk sl son sq
22 sr sv-SE ta te th tr uk uz vi xh zh-CN zh-TW )
24 # Convert the ebuild version to the upstream mozilla version, used by mozlinguas
25 MOZ_PV="${PV/_alpha/a}" # Handle alpha for SRC_URI
26 MOZ_PV="${MOZ_PV/_beta/b}" # Handle beta for SRC_URI
27 MOZ_PV="${MOZ_PV/_rc/rc}" # Handle rc for SRC_URI
29 if [[ ${MOZ_ESR} == 1 ]]; then
30 # ESR releases have slightly different version numbers
35 PATCH="${PN}-52.5-patches-02"
36 MOZ_HTTP_URI="https://archive.mozilla.org/pub/${PN}/releases"
38 MOZCONFIG_OPTIONAL_GTK2ONLY=1
39 MOZCONFIG_OPTIONAL_WIFI=1
41 inherit check-reqs flag-o-matic toolchain-funcs desktop mozconfig-v6.52 pax-utils xdg-utils autotools virtualx mozlinguas-v2
43 DESCRIPTION="Firefox Web Browser"
44 HOMEPAGE="https://www.mozilla.org/firefox"
46 KEYWORDS="~alpha amd64 ~arm ~arm64 ~ia64 ~ppc ~ppc64 x86 ~amd64-linux ~x86-linux"
49 LICENSE="MPL-2.0 GPL-2 LGPL-2.1"
50 IUSE="bindist eme-free +gmp-autoupdate hardened hwaccel jack pgo rust selinux test"
51 RESTRICT="!bindist? ( bindist ) !test? ( test )"
53 PATCH_URIS=( https://dev.gentoo.org/~{anarchy,axs,polynomial-c}/mozilla/patchsets/${PATCH}.tar.xz )
55 ${MOZ_HTTP_URI}/${MOZ_PV}/source/firefox-${MOZ_PV}.source.tar.xz
58 ASM_DEPEND=">=dev-lang/yasm-1.1"
61 jack? ( virtual/jack )
63 >=dev-libs/nspr-4.13.1
64 selinux? ( sec-policy/selinux-mozilla )"
67 pgo? ( >=sys-devel/gcc-4.5 )
68 rust? ( virtual/rust )
69 amd64? ( ${ASM_DEPEND} virtual/opengl )
70 x86? ( ${ASM_DEPEND} virtual/opengl )"
72 S="${WORKDIR}/firefox-${MOZ_PV}"
74 QA_PRESTRIPPED="usr/lib*/${PN}/firefox"
76 BUILD_OBJ_DIR="${S}/ff"
78 # allow GMP_PLUGIN_LIST to be set in an eclass or
79 # overridden in the enviromnent (advanced hackers only)
80 if [[ -z $GMP_PLUGIN_LIST ]]; then
81 GMP_PLUGIN_LIST=( gmp-gmpopenh264 gmp-widevinecdm )
87 # Avoid PGO profiling problems due to enviroment leakage
88 # These should *always* be cleaned up anyway
89 unset DBUS_SESSION_BUS_ADDRESS \
96 if ! use bindist; then
98 elog "You are enabling official branding. You may not redistribute this build"
99 elog "to any users on your network or the internet. Doing so puts yourself into"
100 elog "a legal problem with Mozilla Foundation"
101 elog "You can disable it by emerging ${PN} _with_ the bindist USE-flag"
106 ewarn "You will do a double build for profile guided optimization."
107 ewarn "This will result in your build taking at least twice as long as before."
112 ewarn "This is very experimental, should only be used by those developing firefox."
117 # Ensure we have enough disk space to compile
118 if use pgo || use debug || use test ; then
119 CHECKREQS_DISK_BUILD="8G"
121 CHECKREQS_DISK_BUILD="4G"
129 # Unpack language packs
130 mozlinguas_src_unpack
134 xdg_environment_reset
137 rm -f "${WORKDIR}"/firefox/2007_fix_nvidia_latest.patch
138 eapply "${WORKDIR}/firefox"
140 eapply "${FILESDIR}"/${P}-blessings-TERM.patch # 654316
141 eapply "${FILESDIR}"/${P}-fix-missing-includes.patch
142 eapply "${FILESDIR}"/${P}-fix-idb-name-conflict.patch
143 eapply "${FILESDIR}"/${P}-glibc-2.30.patch
144 eapply "${FILESDIR}"/${P}-glibc-2.36.patch
145 eapply "${FILESDIR}"/${P}-less-werror.patch
146 eapply "${FILESDIR}"/${P}-fix-thebes-templates.patch
148 # Enable gnomebreakpad
150 sed -i -e "s:GNOME_DISABLE_CRASH_DIALOG=1:GNOME_DISABLE_CRASH_DIALOG=0:g" \
151 "${S}"/build/unix/run-mozilla.sh || die "sed failed!"
154 # Drop -Wl,--as-needed related manipulation for ia64 as it causes ld sefgaults, bug #582432
157 -e '/^OS_LIBS += no_as_needed/d' \
158 -e '/^OS_LIBS += as_needed/d' \
159 "${S}"/widget/gtk/mozgtk/gtk2/moz.build \
160 "${S}"/widget/gtk/mozgtk/gtk3/moz.build \
161 || die "sed failed to drop --as-needed for ia64"
164 # Ensure that our plugins dir is enabled as default
165 sed -i -e "s:/usr/lib/mozilla/plugins:/usr/lib/nsbrowser/plugins:" \
166 "${S}"/xpcom/io/nsAppFileLocationProvider.cpp || die "sed failed to replace plugin path for 32bit!"
167 sed -i -e "s:/usr/lib64/mozilla/plugins:/usr/lib64/nsbrowser/plugins:" \
168 "${S}"/xpcom/io/nsAppFileLocationProvider.cpp || die "sed failed to replace plugin path for 64bit!"
170 # Fix sandbox violations during make clean, bug 372817
171 sed -e "s:\(/no-such-file\):${T}\1:g" \
172 -i "${S}"/config/rules.mk \
173 -i "${S}"/nsprpub/configure{.in,} \
176 # Don't exit with error when some libs are missing which we have in
178 sed '/^MOZ_PKG_FATAL_WARNINGS/s@= 1@= 0@' \
179 -i "${S}"/browser/installer/Makefile.in || die
181 # Don't error out when there's no files to be removed:
182 sed 's@\(xargs rm\)$@\1 -f@' \
183 -i "${S}"/toolkit/mozapps/installer/packager.mk || die
185 # Keep codebase the same even if not using official branding
186 sed '/^MOZ_DEV_EDITION=1/d' \
187 -i "${S}"/browser/branding/aurora/configure.sh || die
189 # Allow user to apply any additional patches without modifing ebuild
192 # Autotools configure is now called old-configure.in
193 # This works because there is still a configure.in that happens to be for the
194 # shell wrapper configure script
195 eautoreconf old-configure.in
197 # Must run autoconf in js/src
198 cd "${S}"/js/src || die
199 eautoconf old-configure.in
201 # Need to update jemalloc's configure
202 cd "${S}"/memory/jemalloc/src || die
203 WANT_AUTOCONF= eautoconf
207 MEXTENSIONS="default"
208 # Google API keys (see http://www.chromium.org/developers/how-tos/api-keys)
209 # Note: These are for Gentoo Linux use ONLY. For your own distribution, please
210 # get your own set of keys.
211 _google_api_key=AIzaSyDEAOvatFo0eTgsV_ZlEzx0ObmepsMzfAc
213 ####################################
215 # mozconfig, CFLAGS and CXXFLAGS setup
217 ####################################
222 # enable JACK, bug 600002
223 mozconfig_use_enable jack
225 use eme-free && mozconfig_annotate '+eme-free' --disable-eme
227 # It doesn't compile on alpha without this LDFLAGS
228 use alpha && append-ldflags "-Wl,--no-relax"
230 # Add full relro support for hardened
231 use hardened && append-ldflags "-Wl,-z,relro,-z,now"
233 # Only available on mozilla-overlay for experimentation -- Removed in Gentoo repo per bug 571180
234 #use egl && mozconfig_annotate 'Enable EGL as GL provider' --with-gl-provider=EGL
236 # Setup api key for location services
237 echo -n "${_google_api_key}" > "${S}"/google-api-key
238 mozconfig_annotate '' --with-google-api-keyfile="${S}/google-api-key"
240 mozconfig_annotate '' --enable-extensions="${MEXTENSIONS}"
242 mozconfig_use_enable rust
244 # Allow for a proper pgo build
246 echo "mk_add_options PROFILE_GEN_SCRIPT='EXTRA_TEST_ARGS=10 \$(MAKE) -C \$(MOZ_OBJDIR) pgo-profile-run'" >> "${S}"/.mozconfig
249 echo "mk_add_options MOZ_OBJDIR=${BUILD_OBJ_DIR}" >> "${S}"/.mozconfig
250 echo "mk_add_options XARGS=/usr/bin/xargs" >> "${S}"/.mozconfig
252 # Finalize and report settings
255 if [[ $(gcc-major-version) -lt 4 ]]; then
256 append-cxxflags -fno-stack-protector
258 # append-cxxflags -fpermissive
261 # workaround for funky/broken upstream configure...
262 SHELL="${SHELL:-${EPREFIX}/bin/bash}" \
263 emake -f client.mk configure
269 addpredict /etc/gconf
271 # Firefox tries to use dri stuff when it's run, see bug 380283
273 cards=$(echo -n /dev/dri/card* | sed 's/ /:/g')
274 if test -z "${cards}"; then
275 cards=$(echo -n /dev/ati/card* /dev/nvidiactl* | sed 's/ /:/g')
276 if test -n "${cards}"; then
277 # Binary drivers seem to cause access violations anyway, so
278 # let's use indirect rendering so that the device files aren't
279 # touched at all. See bug 394715.
280 export LIBGL_ALWAYS_INDIRECT=1
284 [[ -n "${cards}" ]] && addpredict "${cards}"
286 MOZ_MAKE_FLAGS="${MAKEOPTS}" SHELL="${SHELL:-${EPREFIX}/bin/bash}" \
287 virtx emake -f client.mk profiledbuild
289 MOZ_MAKE_FLAGS="${MAKEOPTS}" SHELL="${SHELL:-${EPREFIX}/bin/bash}" \
290 emake -f client.mk realbuild
296 cd "${BUILD_OBJ_DIR}" || die
298 # Pax mark xpcshell for hardened support, only used for startupcache creation.
299 pax-mark m "${BUILD_OBJ_DIR}"/dist/bin/xpcshell
301 # Add our default prefs for firefox
302 cp "${FILESDIR}"/gentoo-default-prefs.js-1 \
303 "${BUILD_OBJ_DIR}/dist/bin/browser/defaults/preferences/all-gentoo.js" \
306 mozconfig_install_prefs \
307 "${BUILD_OBJ_DIR}/dist/bin/browser/defaults/preferences/all-gentoo.js"
309 # Augment this with hwaccel prefs
310 if use hwaccel ; then
311 cat "${FILESDIR}"/gentoo-hwaccel-prefs.js-1 >> \
312 "${BUILD_OBJ_DIR}/dist/bin/browser/defaults/preferences/all-gentoo.js" \
316 echo "pref(\"extensions.autoDisableScopes\", 3);" >> \
317 "${BUILD_OBJ_DIR}/dist/bin/browser/defaults/preferences/all-gentoo.js" \
321 use gmp-autoupdate || use eme-free || for plugin in "${GMP_PLUGIN_LIST[@]}" ; do
322 echo "pref(\"media.${plugin}.autoupdate\", false);" >> \
323 "${BUILD_OBJ_DIR}/dist/bin/browser/defaults/preferences/all-gentoo.js" \
327 MOZ_MAKE_FLAGS="${MAKEOPTS}" SHELL="${SHELL:-${EPREFIX}/bin/bash}" \
328 emake DESTDIR="${D}" install
330 # Install language packs
331 mozlinguas_src_install
333 local size sizes icon_path icon name
336 icon_path="${S}/browser/branding/aurora"
337 # Firefox's new rapid release cycle means no more codenames
338 # Let's just stick with this one...
342 # Override preferences to set the MOZ_DEV_EDITION defaults, since we
343 # don't define MOZ_DEV_EDITION to avoid profile debaucles.
344 # (source: browser/app/profile/firefox.js)
345 cat >>"${BUILD_OBJ_DIR}/dist/bin/browser/defaults/preferences/all-gentoo.js" <<PROFILE_EOF
346 pref("app.feedback.baseURL", "https://input.mozilla.org/%LOCALE%/feedback/firefoxdev/%VERSION%/");
347 sticky_pref("lightweightThemes.selectedThemeID", "firefox-devedition@mozilla.org");
348 sticky_pref("browser.devedition.theme.enabled", true);
349 sticky_pref("devtools.theme", "dark");
353 sizes="16 22 24 32 256"
354 icon_path="${S}/browser/branding/official"
356 name="Mozilla Firefox"
359 # Install icons and .desktop for menu entry
360 for size in ${sizes}; do
361 insinto "/usr/share/icons/hicolor/${size}x${size}/apps"
362 newins "${icon_path}/default${size}.png" "${icon}.png"
364 # The 128x128 icon has a different name
365 insinto "/usr/share/icons/hicolor/128x128/apps"
366 newins "${icon_path}/mozicon128.png" "${icon}.png"
367 # Install a 48x48 icon into /usr/share/pixmaps for legacy DEs
368 newicon "${icon_path}/content/icon48.png" "${icon}.png"
369 newmenu "${FILESDIR}/icon/${PN}.desktop" "${PN}.desktop"
370 sed -i -e "s:@NAME@:${name}:" -e "s:@ICON@:${icon}:" \
371 "${ED}/usr/share/applications/${PN}.desktop" || die
373 # Add StartupNotify=true bug 237317
374 if use startup-notification ; then
375 echo "StartupNotify=true"\
376 >> "${ED}/usr/share/applications/${PN}.desktop" \
380 # Required in order to use plugins and even run firefox on hardened.
381 pax-mark m "${ED}"${MOZILLA_FIVE_HOME}/{firefox,firefox-bin,plugin-container}
385 # if the apulse libs are available in MOZILLA_FIVE_HOME then apulse
386 # doesn't need to be forced into the LD_LIBRARY_PATH
387 if use pulseaudio && has_version ">=media-sound/apulse-0.1.9" ; then
388 einfo "APULSE found - Generating library symlinks for sound support"
390 pushd "${ED}"${MOZILLA_FIVE_HOME} &>/dev/null || die
391 for lib in ../apulse/libpulse{.so{,.0},-simple.so{,.0}} ; do
392 # a quickpkg rolled by hand will grab symlinks as part of the package,
393 # so we need to avoid creating them if they already exist.
394 if ! [ -L ${lib##*/} ]; then
395 ln -s "${lib}" ${lib##*/} || die
398 popd &>/dev/null || die
403 # Update mimedb for the new .desktop file
404 xdg_desktop_database_update
405 xdg_icon_cache_update
407 if ! use gmp-autoupdate && ! use eme-free ; then
408 elog "USE='-gmp-autoupdate' has disabled the following plugins from updating or"
409 elog "installing into new profiles:"
411 for plugin in "${GMP_PLUGIN_LIST[@]}"; do elog "\t ${plugin}" ; done
414 if use pulseaudio && has_version ">=media-sound/apulse-0.1.9" ; then
415 elog "Apulse was detected at merge time on this system and so it will always be"
416 elog "used for sound. If you wish to use pulseaudio instead please unmerge"
417 elog "media-sound/apulse."
422 xdg_desktop_database_update
423 xdg_icon_cache_update