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)
10 # * Remove versionator inherit which seems unused (2023-04)
11 # * Update to EAPI 8 (2023-04)
14 # @ECLASS: mozcoreconf-v5.eclass
16 # Mozilla team <mozilla@gentoo.org>
17 # @BLURB: core options and configuration functions for mozilla
20 # inherit mozconfig-v6.* or above for mozilla configuration support
22 # @ECLASS_VARIABLE: MOZILLA_FIVE_HOME
24 # This is an eclass-generated variable that defines the rpath that the mozilla
25 # product will be installed in. Read-only
27 if [[ ! ${_MOZCORECONF} ]]; then
29 inherit multilib toolchain-funcs flag-o-matic
31 IUSE="${IUSE} custom-cflags custom-optimization"
33 BDEPEND="dev-lang/python:2.7[ncurses,sqlite,ssl,threads(+)]
36 # @FUNCTION: mozconfig_annotate
38 # add an annotated line to .mozconfig
41 # mozconfig_annotate "building on ultrasparc" --enable-js-ultrasparc
42 # => ac_add_options --enable-js-ultrasparc # building on ultrasparc
43 mozconfig_annotate() {
44 declare reason=$1 x ; shift
45 [[ $# -gt 0 ]] || die "mozconfig_annotate missing flags for ${reason}\!"
47 echo "ac_add_options ${x} # ${reason}" >>.mozconfig
51 # @FUNCTION: mozconfig_use_enable
53 # add a line to .mozconfig based on a USE-flag
56 # mozconfig_use_enable truetype freetype2
57 # => ac_add_options --enable-freetype2 # +truetype
58 mozconfig_use_enable() {
59 declare flag=$(use_enable "$@")
60 mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
63 # @FUNCTION: mozconfig_use_with
65 # add a line to .mozconfig based on a USE-flag
68 # mozconfig_use_with kerberos gss-api /usr/$(get_libdir)
69 # => ac_add_options --with-gss-api=/usr/lib # +kerberos
70 mozconfig_use_with() {
71 declare flag=$(use_with "$@")
72 mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
75 # @FUNCTION: mozconfig_use_extension
77 # enable or disable an extension based on a USE-flag
80 # mozconfig_use_extension gnome gnomevfs
81 # => ac_add_options --enable-extensions=gnomevfs
82 mozconfig_use_extension() {
83 declare minus=$(use $1 || echo -)
84 mozconfig_annotate "${minus:-+}$1" --enable-extensions=${minus}${2}
88 # Ensure we use C locale when building
91 export LC_MESSAGES="C"
94 # Ensure we use correct toolchain
95 export HOST_CC="$(tc-getBUILD_CC)"
96 export HOST_CXX="$(tc-getBUILD_CXX)"
97 tc-export CC CXX LD PKG_CONFIG
99 # Ensure that we have a sane build enviroment
100 export MOZILLA_CLIENT=1
102 export NO_STATIC_LIB=1
103 export USE_PTHREADS=1
104 export ALDFLAGS=${LDFLAGS}
105 # ensure MOZCONFIG is not defined
108 # set MOZILLA_FIVE_HOME
109 export MOZILLA_FIVE_HOME="/usr/$(get_libdir)/${PN}"
111 # nested configure scripts in mozilla products generate unrecognized options
112 # false positives when toplevel configure passes downwards.
113 export QA_CONFIGURE_OPTIONS=".*"
115 export PYTHON=python2.7
118 # @FUNCTION: mozconfig_init
120 # Initialize mozilla configuration and populate with core settings.
121 # This should be called in src_configure before any other mozconfig_* functions.
123 declare enable_optimize pango_version myext x
124 declare XUL=$([[ ${PN} == xulrunner ]] && echo true || echo false)
125 declare FF=$([[ ${PN} == firefox ]] && echo true || echo false)
126 declare SM=$([[ ${PN} == seamonkey ]] && echo true || echo false)
127 declare TB=$([[ ${PN} == thunderbird ]] && echo true || echo false)
128 declare WF=$([[ ${PN} == waterfox* ]] && echo true || echo false)
130 ####################################
132 # Setup the initial .mozconfig
133 # See http://www.mozilla.org/build/configure-build.html
135 ####################################
139 cp xulrunner/config/mozconfig .mozconfig \
140 || die "cp xulrunner/config/mozconfig failed" ;;
142 cp browser/config/mozconfig .mozconfig \
143 || die "cp browser/config/mozconfig failed" ;;
145 # Must create the initial mozconfig to enable application
146 : >.mozconfig || die "initial mozconfig creation failed"
147 mozconfig_annotate "" --enable-application=suite ;;
149 # Must create the initial mozconfig to enable application
150 : >.mozconfig || die "initial mozconfig creation failed"
151 mozconfig_annotate "" --enable-application=mail ;;
154 ####################################
156 # CFLAGS setup and ARCH support
158 ####################################
160 # Set optimization level
161 mozconfig_annotate "Workaround known breakage" --enable-optimize=-O2
163 if [[ ${ARCH} == hppa ]]; then
164 mozconfig_annotate "more than -O0 causes a segfault on hppa" --enable-optimize=-O0
165 elif [[ ${ARCH} == x86 ]]; then
166 mozconfig_annotate "less then -O2 causes a segfault on x86" --enable-optimize=-O2
167 elif use custom-optimization || [[ ${ARCH} =~ (alpha|ia64) ]]; then
168 # Set optimization level based on CFLAGS
170 mozconfig_annotate "from CFLAGS" --enable-optimize=-O0
171 elif [[ ${ARCH} == ppc ]] && has_version '>=sys-libs/glibc-2.8'; then
172 mozconfig_annotate "more than -O1 segfaults on ppc with glibc-2.8" --enable-optimize=-O1
173 elif is-flag -O4; then
174 mozconfig_annotate "from CFLAGS" --enable-optimize=-O4
175 elif is-flag -O3; then
176 mozconfig_annotate "from CFLAGS" --enable-optimize=-O3
177 elif is-flag -O1; then
178 mozconfig_annotate "from CFLAGS" --enable-optimize=-O1
179 elif is-flag -Os; then
180 mozconfig_annotate "from CFLAGS" --enable-optimize=-Os
182 mozconfig_annotate "Gentoo's default optimization" --enable-optimize=-O2
185 # Enable Mozilla's default
186 mozconfig_annotate "mozilla default" --enable-optimize
189 # Strip optimization so it does not end up in compile string
192 # Strip over-aggressive CFLAGS
193 use custom-cflags || strip-flags
195 # Additional ARCH support
198 # Reduce the memory requirements for linking
199 append-ldflags -Wl,--no-keep-memory -Wl,--reduce-memory-overheads
202 # Historically we have needed to add -fPIC manually for 64-bit.
203 # Additionally, alpha should *always* build with -mieee for correct math
205 append-flags -fPIC -mieee
208 # Historically we have needed to add this manually for 64-bit
212 append-flags -fPIC -mminimal-toc
213 # Reduce the memory requirements for linking
214 append-ldflags -Wl,--no-keep-memory -Wl,--reduce-memory-overheads
218 # We need to append flags for >= gcc-6 support
219 append-cxxflags -fno-delete-null-pointer-checks -fno-lifetime-dse -fno-schedule-insns2
221 # Use the MOZILLA_FIVE_HOME for the rpath
222 append-ldflags -Wl,-rpath="${MOZILLA_FIVE_HOME}",--enable-new-dtags
223 # Set MOZILLA_FIVE_HOME in mozconfig
224 mozconfig_annotate '' --with-default-mozilla-five-home=${MOZILLA_FIVE_HOME}
226 ####################################
230 ####################################
232 mozconfig_annotate disable_update_strip \
235 --disable-install-strip
237 # jemalloc won't build with older glibc
238 ! has_version ">=sys-libs/glibc-2.4" && mozconfig_annotate "we have old glibc" --disable-jemalloc
241 # @FUNCTION: mozconfig_final
243 # Apply EXTRA_ECONF values to .mozconfig
244 # Display a table describing all configuration options paired
245 # with reasons, then clean up extensions list.
246 # This should be called in src_configure at the end of all other mozconfig_* functions.
248 declare ac opt hash reason
250 # Apply EXTRA_ECONF entries to .mozconfig
251 if [[ -n ${EXTRA_ECONF} ]]; then
252 IFS=\! read -a ac <<<${EXTRA_ECONF// --/\!}
253 for opt in "${ac[@]}"; do
254 mozconfig_annotate "EXTRA_ECONF" --${opt#--}
259 echo "=========================================================="
260 echo "Building ${PF} with the following configuration"
261 grep ^ac_add_options .mozconfig | while read ac opt hash reason; do
262 [[ -z ${hash} || ${hash} == \# ]] \
263 || die "error reading mozconfig: ${ac} ${opt} ${hash} ${reason}"
264 printf " %-30s %s\n" "${opt}" "${reason:-mozilla.org default}"
266 echo "=========================================================="
269 # Resolve multiple --enable-extensions down to one
270 declare exts=$(sed -n 's/^ac_add_options --enable-extensions=\([^ ]*\).*/\1/p' \
272 sed -i '/^ac_add_options --enable-extensions/d' .mozconfig
273 echo "ac_add_options --enable-extensions=${exts// /,}" >> .mozconfig