1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: mozcoreconf-v6.eclass
6 # Mozilla team <mozilla@gentoo.org>
7 # @BLURB: core options and configuration functions for mozilla
10 # inherit mozconfig-v6.* or above for mozilla configuration support
12 # @ECLASS-VARIABLE: MOZILLA_FIVE_HOME
14 # This is an eclass-generated variable that defines the rpath that the mozilla
15 # product will be installed in. Read-only
17 if [[ ! ${_MOZCORECONF} ]]; then
19 inherit multilib toolchain-funcs flag-o-matic python-any-r1 versionator
21 IUSE="${IUSE} custom-cflags custom-optimization"
23 DEPEND="virtual/pkgconfig
26 # @FUNCTION: mozconfig_annotate
28 # add an annotated line to .mozconfig
31 # mozconfig_annotate "building on ultrasparc" --enable-js-ultrasparc
32 # => ac_add_options --enable-js-ultrasparc # building on ultrasparc
33 mozconfig_annotate() {
34 declare reason=$1 x ; shift
35 [[ $# -gt 0 ]] || die "mozconfig_annotate missing flags for ${reason}\!"
37 echo "ac_add_options ${x} # ${reason}" >>.mozconfig
41 # @FUNCTION: mozconfig_use_enable
43 # add a line to .mozconfig based on a USE-flag
46 # mozconfig_use_enable truetype freetype2
47 # => ac_add_options --enable-freetype2 # +truetype
48 mozconfig_use_enable() {
49 declare flag=$(use_enable "$@")
50 mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
53 # @FUNCTION mozconfig_use_with
55 # add a line to .mozconfig based on a USE-flag
58 # mozconfig_use_with kerberos gss-api /usr/$(get_libdir)
59 # => ac_add_options --with-gss-api=/usr/lib # +kerberos
60 mozconfig_use_with() {
61 declare flag=$(use_with "$@")
62 mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
65 # @FUNCTION mozconfig_use_extension
67 # enable or disable an extension based on a USE-flag
70 # mozconfig_use_extension gnome gnomevfs
71 # => ac_add_options --enable-extensions=gnomevfs
72 mozconfig_use_extension() {
73 declare minus=$(use $1 || echo -)
74 mozconfig_annotate "${minus:-+}$1" --enable-extensions=${minus}${2}
78 # Ensure we use C locale when building
81 export LC_MESSAGES="C"
84 # Ensure we use correct toolchain
85 export HOST_CC="$(tc-getBUILD_CC)"
86 export HOST_CXX="$(tc-getBUILD_CXX)"
87 tc-export CC CXX LD PKG_CONFIG AR RANLIB
89 # Ensure that we have a sane build enviroment
90 export MOZILLA_CLIENT=1
92 export NO_STATIC_LIB=1
94 export ALDFLAGS=${LDFLAGS}
95 # ensure MOZCONFIG is not defined
98 # set MOZILLA_FIVE_HOME
99 export MOZILLA_FIVE_HOME="/usr/$(get_libdir)/${PN}"
101 # nested configure scripts in mozilla products generate unrecognized options
102 # false positives when toplevel configure passes downwards.
103 export QA_CONFIGURE_OPTIONS=".*"
105 if [[ $(gcc-major-version) -eq 3 ]]; then
106 ewarn "Unsupported compiler detected, DO NOT file bugs for"
107 ewarn "outdated compilers. Bugs opened with gcc-3 will be closed"
111 python-any-r1_pkg_setup
112 # workaround to set python3 into PYTHON3 until mozilla doesn't need py2
113 if [[ "${PYTHON_COMPAT[@]}" != "${PYTHON_COMPAT[@]#python3*}" ]]; then
114 export PYTHON3=${PYTHON}
115 python_export python2_7 PYTHON EPYTHON
119 # @FUNCTION: mozconfig_init
121 # Initialize mozilla configuration and populate with core settings.
122 # This should be called in src_configure before any other mozconfig_* functions.
124 declare enable_optimize pango_version myext x
125 declare XUL=$([[ ${PN} == xulrunner ]] && echo true || echo false)
126 declare FF=$([[ ${PN} == firefox ]] && echo true || echo false)
127 declare SM=$([[ ${PN} == seamonkey ]] && echo true || echo false)
128 declare TB=$([[ ${PN} == thunderbird ]] && echo true || echo false)
129 declare TRB=$([[ ${PN} == torbrowser ]] && echo true || echo false)
131 ####################################
133 # Setup the initial .mozconfig
134 # See http://www.mozilla.org/build/configure-build.html
136 ####################################
140 cp xulrunner/config/mozconfig .mozconfig \
141 || die "cp xulrunner/config/mozconfig failed" ;;
143 cp browser/config/mozconfig .mozconfig \
144 || die "cp browser/config/mozconfig failed" ;;
146 cp browser/config/mozconfig .mozconfig \
147 || die "cp browser/config/mozconfig failed" ;;
149 # Must create the initial mozconfig to enable application
150 : >.mozconfig || die "initial mozconfig creation failed"
151 # NOTE--this is not compatible with mozilla prior to v60
152 mozconfig_annotate "" --enable-application=comm/suite ;;
154 # Must create the initial mozconfig to enable application
155 : >.mozconfig || die "initial mozconfig creation failed"
156 # NOTE--this is not compatible with mozilla prior to v60
157 mozconfig_annotate "" --enable-application=comm/mail ;;
160 ####################################
162 # CFLAGS setup and ARCH support
164 ####################################
166 # Set optimization level
167 if [[ $(gcc-major-version) -eq 7 ]]; then
168 mozconfig_annotate "Workaround known breakage" --enable-optimize=-O2
169 elif [[ ${ARCH} == hppa ]]; then
170 mozconfig_annotate "more than -O0 causes a segfault on hppa" --enable-optimize=-O0
171 elif [[ ${ARCH} == x86 ]]; then
172 mozconfig_annotate "less than -O2 causes a segfault on x86" --enable-optimize=-O2
173 elif [[ ${ARCH} == arm ]] && [[ $(gcc-major-version) -ge 6 ]]; then
174 mozconfig_annotate "less than -O2 causes a breakage on arm with gcc-6" --enable-optimize=-O2
175 elif use custom-optimization || [[ ${ARCH} =~ (alpha|ia64) ]]; then
176 # Set optimization level based on CFLAGS
178 mozconfig_annotate "from CFLAGS" --enable-optimize=-O0
179 elif [[ ${ARCH} == ppc ]] && has_version '>=sys-libs/glibc-2.8'; then
180 mozconfig_annotate "more than -O1 segfaults on ppc with glibc-2.8" --enable-optimize=-O1
181 elif is-flag -O4; then
182 mozconfig_annotate "from CFLAGS" --enable-optimize=-O4
183 elif is-flag -O3; then
184 mozconfig_annotate "from CFLAGS" --enable-optimize=-O3
185 elif is-flag -O1; then
186 mozconfig_annotate "from CFLAGS" --enable-optimize=-O1
187 elif is-flag -Os; then
188 mozconfig_annotate "from CFLAGS" --enable-optimize=-Os
190 mozconfig_annotate "Gentoo's default optimization" --enable-optimize=-O2
193 # Enable Mozilla's default
194 mozconfig_annotate "mozilla default" --enable-optimize
197 # Strip optimization so it does not end up in compile string
200 # Strip over-aggressive CFLAGS
201 use custom-cflags || strip-flags
203 # Additional ARCH support
206 # Reduce the memory requirements for linking
210 elif tc-ld-is-gold ; then
211 append-ldflags -Wl,--no-keep-memory
213 append-ldflags -Wl,--no-keep-memory -Wl,--reduce-memory-overheads
217 # Historically we have needed to add -fPIC manually for 64-bit.
218 # Additionally, alpha should *always* build with -mieee for correct math
220 append-flags -fPIC -mieee
223 # Historically we have needed to add this manually for 64-bit
227 append-flags -fPIC -mminimal-toc
228 # Reduce the memory requirements for linking
232 elif tc-ld-is-gold ; then
233 append-ldflags -Wl,--no-keep-memory
235 append-ldflags -Wl,--no-keep-memory -Wl,--reduce-memory-overheads
240 # We need to append flags for gcc-6 support
241 if [[ $(gcc-major-version) -ge 6 ]]; then
242 append-cxxflags -fno-delete-null-pointer-checks -fno-lifetime-dse -fno-schedule-insns -fno-schedule-insns2
245 # Use the MOZILLA_FIVE_HOME for the rpath
246 append-ldflags -Wl,-rpath="${MOZILLA_FIVE_HOME}",--enable-new-dtags
248 ####################################
252 ####################################
254 mozconfig_annotate disable_update_strip \
257 --disable-install-strip
259 # jemalloc won't build with older glibc
260 ! has_version ">=sys-libs/glibc-2.4" && mozconfig_annotate "we have old glibc" --disable-jemalloc
263 # @FUNCTION: mozconfig_final
265 # Apply EXTRA_ECONF values to .mozconfig
266 # Display a table describing all configuration options paired
267 # with reasons, then clean up extensions list.
268 # This should be called in src_configure at the end of all other mozconfig_* functions.
270 declare ac opt hash reason
272 # Apply EXTRA_ECONF entries to .mozconfig
273 if [[ -n ${EXTRA_ECONF} ]]; then
274 IFS=\! read -a ac <<<${EXTRA_ECONF// --/\!}
275 for opt in "${ac[@]}"; do
276 mozconfig_annotate "EXTRA_ECONF" --${opt#--}
281 echo "=========================================================="
282 echo "Building ${PF} with the following configuration"
283 grep ^ac_add_options .mozconfig | while read ac opt hash reason; do
284 [[ -z ${hash} || ${hash} == \# ]] \
285 || die "error reading mozconfig: ${ac} ${opt} ${hash} ${reason}"
286 printf " %-30s %s\n" "${opt}" "${reason:-mozilla.org default}"
288 echo "=========================================================="
291 # Resolve multiple --enable-extensions down to one
292 declare exts=$(sed -n 's/^ac_add_options --enable-extensions=\([^ ]*\).*/\1/p' \
294 sed -i '/^ac_add_options --enable-extensions/d' .mozconfig
295 echo "ac_add_options --enable-extensions=${exts// /,}" >> .mozconfig