1 # This eclass 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-2022 Gentoo Authors
5 # Distributed under the terms of the GNU General Public License v2
7 # The modifications are:
9 # * Avoid python eclasses which no longer support python2 (2022-12)
12 # @ECLASS: mozcoreconf-v5.eclass
14 # Mozilla team <mozilla@gentoo.org>
15 # @BLURB: core options and configuration functions for mozilla
18 # inherit mozconfig-v6.* or above for mozilla configuration support
20 # @ECLASS_VARIABLE: MOZILLA_FIVE_HOME
22 # This is an eclass-generated variable that defines the rpath that the mozilla
23 # product will be installed in. Read-only
25 if [[ ! ${_MOZCORECONF} ]]; then
27 inherit multilib toolchain-funcs flag-o-matic versionator
29 IUSE="${IUSE} custom-cflags custom-optimization"
31 DEPEND="virtual/pkgconfig
32 dev-lang/python:2.7[ncurses,sqlite,ssl,threads(+)]"
34 # @FUNCTION: mozconfig_annotate
36 # add an annotated line to .mozconfig
39 # mozconfig_annotate "building on ultrasparc" --enable-js-ultrasparc
40 # => ac_add_options --enable-js-ultrasparc # building on ultrasparc
41 mozconfig_annotate() {
42 declare reason=$1 x ; shift
43 [[ $# -gt 0 ]] || die "mozconfig_annotate missing flags for ${reason}\!"
45 echo "ac_add_options ${x} # ${reason}" >>.mozconfig
49 # @FUNCTION: mozconfig_use_enable
51 # add a line to .mozconfig based on a USE-flag
54 # mozconfig_use_enable truetype freetype2
55 # => ac_add_options --enable-freetype2 # +truetype
56 mozconfig_use_enable() {
57 declare flag=$(use_enable "$@")
58 mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
61 # @FUNCTION: mozconfig_use_with
63 # add a line to .mozconfig based on a USE-flag
66 # mozconfig_use_with kerberos gss-api /usr/$(get_libdir)
67 # => ac_add_options --with-gss-api=/usr/lib # +kerberos
68 mozconfig_use_with() {
69 declare flag=$(use_with "$@")
70 mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
73 # @FUNCTION: mozconfig_use_extension
75 # enable or disable an extension based on a USE-flag
78 # mozconfig_use_extension gnome gnomevfs
79 # => ac_add_options --enable-extensions=gnomevfs
80 mozconfig_use_extension() {
81 declare minus=$(use $1 || echo -)
82 mozconfig_annotate "${minus:-+}$1" --enable-extensions=${minus}${2}
86 # Ensure we use C locale when building
89 export LC_MESSAGES="C"
92 # Ensure we use correct toolchain
93 export HOST_CC="$(tc-getBUILD_CC)"
94 export HOST_CXX="$(tc-getBUILD_CXX)"
95 tc-export CC CXX LD PKG_CONFIG
97 # Ensure that we have a sane build enviroment
98 export MOZILLA_CLIENT=1
100 export NO_STATIC_LIB=1
101 export USE_PTHREADS=1
102 export ALDFLAGS=${LDFLAGS}
103 # ensure MOZCONFIG is not defined
106 # set MOZILLA_FIVE_HOME
107 export MOZILLA_FIVE_HOME="/usr/$(get_libdir)/${PN}"
109 # nested configure scripts in mozilla products generate unrecognized options
110 # false positives when toplevel configure passes downwards.
111 export QA_CONFIGURE_OPTIONS=".*"
113 export PYTHON=python2.7
116 # @FUNCTION: mozconfig_init
118 # Initialize mozilla configuration and populate with core settings.
119 # This should be called in src_configure before any other mozconfig_* functions.
121 declare enable_optimize pango_version myext x
122 declare XUL=$([[ ${PN} == xulrunner ]] && echo true || echo false)
123 declare FF=$([[ ${PN} == firefox ]] && echo true || echo false)
124 declare SM=$([[ ${PN} == seamonkey ]] && echo true || echo false)
125 declare TB=$([[ ${PN} == thunderbird ]] && echo true || echo false)
126 declare WF=$([[ ${PN} == waterfox* ]] && echo true || echo false)
128 ####################################
130 # Setup the initial .mozconfig
131 # See http://www.mozilla.org/build/configure-build.html
133 ####################################
137 cp xulrunner/config/mozconfig .mozconfig \
138 || die "cp xulrunner/config/mozconfig failed" ;;
140 cp browser/config/mozconfig .mozconfig \
141 || die "cp browser/config/mozconfig failed" ;;
143 # Must create the initial mozconfig to enable application
144 : >.mozconfig || die "initial mozconfig creation failed"
145 mozconfig_annotate "" --enable-application=suite ;;
147 # Must create the initial mozconfig to enable application
148 : >.mozconfig || die "initial mozconfig creation failed"
149 mozconfig_annotate "" --enable-application=mail ;;
152 ####################################
154 # CFLAGS setup and ARCH support
156 ####################################
158 # Set optimization level
159 mozconfig_annotate "Workaround known breakage" --enable-optimize=-O2
161 if [[ ${ARCH} == hppa ]]; then
162 mozconfig_annotate "more than -O0 causes a segfault on hppa" --enable-optimize=-O0
163 elif [[ ${ARCH} == x86 ]]; then
164 mozconfig_annotate "less then -O2 causes a segfault on x86" --enable-optimize=-O2
165 elif use custom-optimization || [[ ${ARCH} =~ (alpha|ia64) ]]; then
166 # Set optimization level based on CFLAGS
168 mozconfig_annotate "from CFLAGS" --enable-optimize=-O0
169 elif [[ ${ARCH} == ppc ]] && has_version '>=sys-libs/glibc-2.8'; then
170 mozconfig_annotate "more than -O1 segfaults on ppc with glibc-2.8" --enable-optimize=-O1
171 elif is-flag -O4; then
172 mozconfig_annotate "from CFLAGS" --enable-optimize=-O4
173 elif is-flag -O3; then
174 mozconfig_annotate "from CFLAGS" --enable-optimize=-O3
175 elif is-flag -O1; then
176 mozconfig_annotate "from CFLAGS" --enable-optimize=-O1
177 elif is-flag -Os; then
178 mozconfig_annotate "from CFLAGS" --enable-optimize=-Os
180 mozconfig_annotate "Gentoo's default optimization" --enable-optimize=-O2
183 # Enable Mozilla's default
184 mozconfig_annotate "mozilla default" --enable-optimize
187 # Strip optimization so it does not end up in compile string
190 # Strip over-aggressive CFLAGS
191 use custom-cflags || strip-flags
193 # Additional ARCH support
196 # Reduce the memory requirements for linking
197 append-ldflags -Wl,--no-keep-memory -Wl,--reduce-memory-overheads
200 # Historically we have needed to add -fPIC manually for 64-bit.
201 # Additionally, alpha should *always* build with -mieee for correct math
203 append-flags -fPIC -mieee
206 # Historically we have needed to add this manually for 64-bit
210 append-flags -fPIC -mminimal-toc
211 # Reduce the memory requirements for linking
212 append-ldflags -Wl,--no-keep-memory -Wl,--reduce-memory-overheads
216 # We need to append flags for >= gcc-6 support
217 append-cxxflags -fno-delete-null-pointer-checks -fno-lifetime-dse -fno-schedule-insns2
219 # Use the MOZILLA_FIVE_HOME for the rpath
220 append-ldflags -Wl,-rpath="${MOZILLA_FIVE_HOME}",--enable-new-dtags
221 # Set MOZILLA_FIVE_HOME in mozconfig
222 mozconfig_annotate '' --with-default-mozilla-five-home=${MOZILLA_FIVE_HOME}
224 ####################################
228 ####################################
230 mozconfig_annotate disable_update_strip \
233 --disable-install-strip
235 # jemalloc won't build with older glibc
236 ! has_version ">=sys-libs/glibc-2.4" && mozconfig_annotate "we have old glibc" --disable-jemalloc
239 # @FUNCTION: mozconfig_final
241 # Apply EXTRA_ECONF values to .mozconfig
242 # Display a table describing all configuration options paired
243 # with reasons, then clean up extensions list.
244 # This should be called in src_configure at the end of all other mozconfig_* functions.
246 declare ac opt hash reason
248 # Apply EXTRA_ECONF entries to .mozconfig
249 if [[ -n ${EXTRA_ECONF} ]]; then
250 IFS=\! read -a ac <<<${EXTRA_ECONF// --/\!}
251 for opt in "${ac[@]}"; do
252 mozconfig_annotate "EXTRA_ECONF" --${opt#--}
257 echo "=========================================================="
258 echo "Building ${PF} with the following configuration"
259 grep ^ac_add_options .mozconfig | while read ac opt hash reason; do
260 [[ -z ${hash} || ${hash} == \# ]] \
261 || die "error reading mozconfig: ${ac} ${opt} ${hash} ${reason}"
262 printf " %-30s %s\n" "${opt}" "${reason:-mozilla.org default}"
264 echo "=========================================================="
267 # Resolve multiple --enable-extensions down to one
268 declare exts=$(sed -n 's/^ac_add_options --enable-extensions=\([^ ]*\).*/\1/p' \
270 sed -i '/^ac_add_options --enable-extensions/d' .mozconfig
271 echo "ac_add_options --enable-extensions=${exts// /,}" >> .mozconfig