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)
12 VIRTUALX_REQUIRED="pgo"
16 # This list can be updated with scripts/get_langs.sh from the mozilla overlay
17 MOZ_LANGS=( ach af an ar as ast az bg bn-BD bn-IN br bs ca cak cs cy da de dsb
18 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
19 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
20 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
21 sr sv-SE ta te th tr uk uz vi xh zh-CN zh-TW )
23 # Convert the ebuild version to the upstream mozilla version, used by mozlinguas
24 MOZ_PV="${PV/_alpha/a}" # Handle alpha for SRC_URI
25 MOZ_PV="${MOZ_PV/_beta/b}" # Handle beta for SRC_URI
26 MOZ_PV="${MOZ_PV/_rc/rc}" # Handle rc for SRC_URI
28 if [[ ${MOZ_ESR} == 1 ]]; then
29 # ESR releases have slightly different version numbers
34 PATCH="${PN}-52.5-patches-02"
35 MOZ_HTTP_URI="https://archive.mozilla.org/pub/${PN}/releases"
37 MOZCONFIG_OPTIONAL_GTK2ONLY=1
38 MOZCONFIG_OPTIONAL_WIFI=1
40 inherit check-reqs flag-o-matic toolchain-funcs eutils gnome2-utils mozconfig-v6.52 pax-utils xdg-utils autotools virtualx mozlinguas-v2
42 DESCRIPTION="Firefox Web Browser"
43 HOMEPAGE="https://www.mozilla.org/firefox"
45 KEYWORDS="~alpha amd64 ~arm ~arm64 ~ia64 ~ppc ~ppc64 x86 ~amd64-linux ~x86-linux"
48 LICENSE="MPL-2.0 GPL-2 LGPL-2.1"
49 IUSE="bindist eme-free +gmp-autoupdate hardened hwaccel jack pgo rust selinux test"
50 RESTRICT="!bindist? ( bindist ) !test? ( test )"
52 PATCH_URIS=( https://dev.gentoo.org/~{anarchy,axs,polynomial-c}/mozilla/patchsets/${PATCH}.tar.xz )
54 ${MOZ_HTTP_URI}/${MOZ_PV}/source/firefox-${MOZ_PV}.source.tar.xz
57 ASM_DEPEND=">=dev-lang/yasm-1.1"
60 jack? ( virtual/jack )
62 >=dev-libs/nspr-4.13.1
63 selinux? ( sec-policy/selinux-mozilla )"
66 pgo? ( >=sys-devel/gcc-4.5 )
67 rust? ( virtual/rust )
68 amd64? ( ${ASM_DEPEND} virtual/opengl )
69 x86? ( ${ASM_DEPEND} virtual/opengl )"
71 S="${WORKDIR}/firefox-${MOZ_PV}"
73 QA_PRESTRIPPED="usr/lib*/${PN}/firefox"
75 BUILD_OBJ_DIR="${S}/ff"
77 # allow GMP_PLUGIN_LIST to be set in an eclass or
78 # overridden in the enviromnent (advanced hackers only)
79 if [[ -z $GMP_PLUGIN_LIST ]]; then
80 GMP_PLUGIN_LIST=( gmp-gmpopenh264 gmp-widevinecdm )
86 # Avoid PGO profiling problems due to enviroment leakage
87 # These should *always* be cleaned up anyway
88 unset DBUS_SESSION_BUS_ADDRESS \
95 if ! use bindist; then
97 elog "You are enabling official branding. You may not redistribute this build"
98 elog "to any users on your network or the internet. Doing so puts yourself into"
99 elog "a legal problem with Mozilla Foundation"
100 elog "You can disable it by emerging ${PN} _with_ the bindist USE-flag"
105 ewarn "You will do a double build for profile guided optimization."
106 ewarn "This will result in your build taking at least twice as long as before."
111 ewarn "This is very experimental, should only be used by those developing firefox."
116 # Ensure we have enough disk space to compile
117 if use pgo || use debug || use test ; then
118 CHECKREQS_DISK_BUILD="8G"
120 CHECKREQS_DISK_BUILD="4G"
128 # Unpack language packs
129 mozlinguas_src_unpack
134 rm -f "${WORKDIR}"/firefox/2007_fix_nvidia_latest.patch
135 eapply "${WORKDIR}/firefox"
137 eapply "${FILESDIR}"/${P}-blessings-TERM.patch # 654316
138 eapply "${FILESDIR}"/${P}-fix-missing-includes.patch
139 eapply "${FILESDIR}"/${P}-fix-idb-name-conflict.patch
140 eapply "${FILESDIR}"/${P}-glibc-2.30.patch
141 eapply "${FILESDIR}"/${P}-glibc-2.36.patch
142 eapply "${FILESDIR}"/${P}-less-werror.patch
143 eapply "${FILESDIR}"/${P}-fix-thebes-templates.patch
145 # Enable gnomebreakpad
147 sed -i -e "s:GNOME_DISABLE_CRASH_DIALOG=1:GNOME_DISABLE_CRASH_DIALOG=0:g" \
148 "${S}"/build/unix/run-mozilla.sh || die "sed failed!"
151 # Drop -Wl,--as-needed related manipulation for ia64 as it causes ld sefgaults, bug #582432
154 -e '/^OS_LIBS += no_as_needed/d' \
155 -e '/^OS_LIBS += as_needed/d' \
156 "${S}"/widget/gtk/mozgtk/gtk2/moz.build \
157 "${S}"/widget/gtk/mozgtk/gtk3/moz.build \
158 || die "sed failed to drop --as-needed for ia64"
161 # Ensure that our plugins dir is enabled as default
162 sed -i -e "s:/usr/lib/mozilla/plugins:/usr/lib/nsbrowser/plugins:" \
163 "${S}"/xpcom/io/nsAppFileLocationProvider.cpp || die "sed failed to replace plugin path for 32bit!"
164 sed -i -e "s:/usr/lib64/mozilla/plugins:/usr/lib64/nsbrowser/plugins:" \
165 "${S}"/xpcom/io/nsAppFileLocationProvider.cpp || die "sed failed to replace plugin path for 64bit!"
167 # Fix sandbox violations during make clean, bug 372817
168 sed -e "s:\(/no-such-file\):${T}\1:g" \
169 -i "${S}"/config/rules.mk \
170 -i "${S}"/nsprpub/configure{.in,} \
173 # Don't exit with error when some libs are missing which we have in
175 sed '/^MOZ_PKG_FATAL_WARNINGS/s@= 1@= 0@' \
176 -i "${S}"/browser/installer/Makefile.in || die
178 # Don't error out when there's no files to be removed:
179 sed 's@\(xargs rm\)$@\1 -f@' \
180 -i "${S}"/toolkit/mozapps/installer/packager.mk || die
182 # Keep codebase the same even if not using official branding
183 sed '/^MOZ_DEV_EDITION=1/d' \
184 -i "${S}"/browser/branding/aurora/configure.sh || die
186 # Allow user to apply any additional patches without modifing ebuild
189 # Autotools configure is now called old-configure.in
190 # This works because there is still a configure.in that happens to be for the
191 # shell wrapper configure script
192 eautoreconf old-configure.in
194 # Must run autoconf in js/src
195 cd "${S}"/js/src || die
196 eautoconf old-configure.in
198 # Need to update jemalloc's configure
199 cd "${S}"/memory/jemalloc/src || die
200 WANT_AUTOCONF= eautoconf
204 MEXTENSIONS="default"
205 # Google API keys (see http://www.chromium.org/developers/how-tos/api-keys)
206 # Note: These are for Gentoo Linux use ONLY. For your own distribution, please
207 # get your own set of keys.
208 _google_api_key=AIzaSyDEAOvatFo0eTgsV_ZlEzx0ObmepsMzfAc
210 ####################################
212 # mozconfig, CFLAGS and CXXFLAGS setup
214 ####################################
219 # enable JACK, bug 600002
220 mozconfig_use_enable jack
222 use eme-free && mozconfig_annotate '+eme-free' --disable-eme
224 # It doesn't compile on alpha without this LDFLAGS
225 use alpha && append-ldflags "-Wl,--no-relax"
227 # Add full relro support for hardened
228 use hardened && append-ldflags "-Wl,-z,relro,-z,now"
230 # Only available on mozilla-overlay for experimentation -- Removed in Gentoo repo per bug 571180
231 #use egl && mozconfig_annotate 'Enable EGL as GL provider' --with-gl-provider=EGL
233 # Setup api key for location services
234 echo -n "${_google_api_key}" > "${S}"/google-api-key
235 mozconfig_annotate '' --with-google-api-keyfile="${S}/google-api-key"
237 mozconfig_annotate '' --enable-extensions="${MEXTENSIONS}"
239 mozconfig_use_enable rust
241 # Allow for a proper pgo build
243 echo "mk_add_options PROFILE_GEN_SCRIPT='EXTRA_TEST_ARGS=10 \$(MAKE) -C \$(MOZ_OBJDIR) pgo-profile-run'" >> "${S}"/.mozconfig
246 echo "mk_add_options MOZ_OBJDIR=${BUILD_OBJ_DIR}" >> "${S}"/.mozconfig
247 echo "mk_add_options XARGS=/usr/bin/xargs" >> "${S}"/.mozconfig
249 # Finalize and report settings
252 if [[ $(gcc-major-version) -lt 4 ]]; then
253 append-cxxflags -fno-stack-protector
255 # append-cxxflags -fpermissive
258 # workaround for funky/broken upstream configure...
259 SHELL="${SHELL:-${EPREFIX}/bin/bash}" \
260 emake -f client.mk configure
266 addpredict /etc/gconf
267 # Reset and cleanup environment variables used by GNOME/XDG
268 gnome2_environment_reset
270 # Firefox tries to use dri stuff when it's run, see bug 380283
272 cards=$(echo -n /dev/dri/card* | sed 's/ /:/g')
273 if test -z "${cards}"; then
274 cards=$(echo -n /dev/ati/card* /dev/nvidiactl* | sed 's/ /:/g')
275 if test -n "${cards}"; then
276 # Binary drivers seem to cause access violations anyway, so
277 # let's use indirect rendering so that the device files aren't
278 # touched at all. See bug 394715.
279 export LIBGL_ALWAYS_INDIRECT=1
283 [[ -n "${cards}" ]] && addpredict "${cards}"
285 MOZ_MAKE_FLAGS="${MAKEOPTS}" SHELL="${SHELL:-${EPREFIX}/bin/bash}" \
286 virtx emake -f client.mk profiledbuild
288 MOZ_MAKE_FLAGS="${MAKEOPTS}" SHELL="${SHELL:-${EPREFIX}/bin/bash}" \
289 emake -f client.mk realbuild
295 cd "${BUILD_OBJ_DIR}" || die
297 # Pax mark xpcshell for hardened support, only used for startupcache creation.
298 pax-mark m "${BUILD_OBJ_DIR}"/dist/bin/xpcshell
300 # Add our default prefs for firefox
301 cp "${FILESDIR}"/gentoo-default-prefs.js-1 \
302 "${BUILD_OBJ_DIR}/dist/bin/browser/defaults/preferences/all-gentoo.js" \
305 mozconfig_install_prefs \
306 "${BUILD_OBJ_DIR}/dist/bin/browser/defaults/preferences/all-gentoo.js"
308 # Augment this with hwaccel prefs
309 if use hwaccel ; then
310 cat "${FILESDIR}"/gentoo-hwaccel-prefs.js-1 >> \
311 "${BUILD_OBJ_DIR}/dist/bin/browser/defaults/preferences/all-gentoo.js" \
315 echo "pref(\"extensions.autoDisableScopes\", 3);" >> \
316 "${BUILD_OBJ_DIR}/dist/bin/browser/defaults/preferences/all-gentoo.js" \
320 use gmp-autoupdate || use eme-free || for plugin in "${GMP_PLUGIN_LIST[@]}" ; do
321 echo "pref(\"media.${plugin}.autoupdate\", false);" >> \
322 "${BUILD_OBJ_DIR}/dist/bin/browser/defaults/preferences/all-gentoo.js" \
326 MOZ_MAKE_FLAGS="${MAKEOPTS}" SHELL="${SHELL:-${EPREFIX}/bin/bash}" \
327 emake DESTDIR="${D}" install
329 # Install language packs
330 mozlinguas_src_install
332 local size sizes icon_path icon name
335 icon_path="${S}/browser/branding/aurora"
336 # Firefox's new rapid release cycle means no more codenames
337 # Let's just stick with this one...
341 # Override preferences to set the MOZ_DEV_EDITION defaults, since we
342 # don't define MOZ_DEV_EDITION to avoid profile debaucles.
343 # (source: browser/app/profile/firefox.js)
344 cat >>"${BUILD_OBJ_DIR}/dist/bin/browser/defaults/preferences/all-gentoo.js" <<PROFILE_EOF
345 pref("app.feedback.baseURL", "https://input.mozilla.org/%LOCALE%/feedback/firefoxdev/%VERSION%/");
346 sticky_pref("lightweightThemes.selectedThemeID", "firefox-devedition@mozilla.org");
347 sticky_pref("browser.devedition.theme.enabled", true);
348 sticky_pref("devtools.theme", "dark");
352 sizes="16 22 24 32 256"
353 icon_path="${S}/browser/branding/official"
355 name="Mozilla Firefox"
358 # Install icons and .desktop for menu entry
359 for size in ${sizes}; do
360 insinto "/usr/share/icons/hicolor/${size}x${size}/apps"
361 newins "${icon_path}/default${size}.png" "${icon}.png"
363 # The 128x128 icon has a different name
364 insinto "/usr/share/icons/hicolor/128x128/apps"
365 newins "${icon_path}/mozicon128.png" "${icon}.png"
366 # Install a 48x48 icon into /usr/share/pixmaps for legacy DEs
367 newicon "${icon_path}/content/icon48.png" "${icon}.png"
368 newmenu "${FILESDIR}/icon/${PN}.desktop" "${PN}.desktop"
369 sed -i -e "s:@NAME@:${name}:" -e "s:@ICON@:${icon}:" \
370 "${ED}/usr/share/applications/${PN}.desktop" || die
372 # Add StartupNotify=true bug 237317
373 if use startup-notification ; then
374 echo "StartupNotify=true"\
375 >> "${ED}/usr/share/applications/${PN}.desktop" \
379 # Required in order to use plugins and even run firefox on hardened.
380 pax-mark m "${ED}"${MOZILLA_FIVE_HOME}/{firefox,firefox-bin,plugin-container}
386 # if the apulse libs are available in MOZILLA_FIVE_HOME then apulse
387 # doesn't need to be forced into the LD_LIBRARY_PATH
388 if use pulseaudio && has_version ">=media-sound/apulse-0.1.9" ; then
389 einfo "APULSE found - Generating library symlinks for sound support"
391 pushd "${ED}"${MOZILLA_FIVE_HOME} &>/dev/null || die
392 for lib in ../apulse/libpulse{.so{,.0},-simple.so{,.0}} ; do
393 # a quickpkg rolled by hand will grab symlinks as part of the package,
394 # so we need to avoid creating them if they already exist.
395 if ! [ -L ${lib##*/} ]; then
396 ln -s "${lib}" ${lib##*/} || die
399 popd &>/dev/null || die
404 # Update mimedb for the new .desktop file
405 xdg_desktop_database_update
406 gnome2_icon_cache_update
408 if ! use gmp-autoupdate && ! use eme-free ; then
409 elog "USE='-gmp-autoupdate' has disabled the following plugins from updating or"
410 elog "installing into new profiles:"
412 for plugin in "${GMP_PLUGIN_LIST[@]}"; do elog "\t ${plugin}" ; done
415 if use pulseaudio && has_version ">=media-sound/apulse-0.1.9" ; then
416 elog "Apulse was detected at merge time on this system and so it will always be"
417 elog "used for sound. If you wish to use pulseaudio instead please unmerge"
418 elog "media-sound/apulse."
423 gnome2_icon_cache_update