eclass/mozcoreconf: added v5 with EXTRA_ECONF support and gcc7 handling
[gentoo.git] / eclass / mozcoreconf-v5.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 #
4 # @ECLASS: mozcoreconf-v5.eclass
5 # @MAINTAINER:
6 # Mozilla team <mozilla@gentoo.org>
7 # @BLURB: core options and configuration functions for mozilla
8 # @DESCRIPTION:
9 #
10 # inherit mozconfig-v6.* or above for mozilla configuration support
11
12 # @ECLASS-VARIABLE: MOZILLA_FIVE_HOME
13 # @DESCRIPTION:
14 # This is an eclass-generated variable that defines the rpath that the mozilla
15 # product will be installed in.  Read-only
16
17 if [[ ! ${_MOZCORECONF} ]]; then
18
19 PYTHON_COMPAT=( python2_7 )
20 PYTHON_REQ_USE='ncurses,sqlite,ssl,threads'
21
22 inherit multilib toolchain-funcs flag-o-matic python-any-r1 versionator
23
24 IUSE="${IUSE} custom-cflags custom-optimization"
25
26 DEPEND="virtual/pkgconfig
27         ${PYTHON_DEPS}"
28
29 # @FUNCTION: mozconfig_annotate
30 # @DESCRIPTION:
31 # add an annotated line to .mozconfig
32 #
33 # Example:
34 # mozconfig_annotate "building on ultrasparc" --enable-js-ultrasparc
35 # => ac_add_options --enable-js-ultrasparc # building on ultrasparc
36 mozconfig_annotate() {
37         declare reason=$1 x ; shift
38         [[ $# -gt 0 ]] || die "mozconfig_annotate missing flags for ${reason}\!"
39         for x in ${*}; do
40                 echo "ac_add_options ${x} # ${reason}" >>.mozconfig
41         done
42 }
43
44 # @FUNCTION: mozconfig_use_enable
45 # @DESCRIPTION:
46 # add a line to .mozconfig based on a USE-flag
47 #
48 # Example:
49 # mozconfig_use_enable truetype freetype2
50 # => ac_add_options --enable-freetype2 # +truetype
51 mozconfig_use_enable() {
52         declare flag=$(use_enable "$@")
53         mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
54 }
55
56 # @FUNCTION mozconfig_use_with
57 # @DESCRIPTION
58 # add a line to .mozconfig based on a USE-flag
59 #
60 # Example:
61 # mozconfig_use_with kerberos gss-api /usr/$(get_libdir)
62 # => ac_add_options --with-gss-api=/usr/lib # +kerberos
63 mozconfig_use_with() {
64         declare flag=$(use_with "$@")
65         mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
66 }
67
68 # @FUNCTION mozconfig_use_extension
69 # @DESCRIPTION
70 # enable or disable an extension based on a USE-flag
71 #
72 # Example:
73 # mozconfig_use_extension gnome gnomevfs
74 # => ac_add_options --enable-extensions=gnomevfs
75 mozconfig_use_extension() {
76         declare minus=$(use $1 || echo -)
77         mozconfig_annotate "${minus:-+}$1" --enable-extensions=${minus}${2}
78 }
79
80 moz_pkgsetup() {
81         # Ensure we use C locale when building
82         export LANG="C"
83         export LC_ALL="C"
84         export LC_MESSAGES="C"
85         export LC_CTYPE="C"
86
87         # Ensure we use correct toolchain
88         export HOST_CC="$(tc-getBUILD_CC)"
89         export HOST_CXX="$(tc-getBUILD_CXX)"
90         tc-export CC CXX LD PKG_CONFIG
91
92         # Ensure that we have a sane build enviroment
93         export MOZILLA_CLIENT=1
94         export BUILD_OPT=1
95         export NO_STATIC_LIB=1
96         export USE_PTHREADS=1
97         export ALDFLAGS=${LDFLAGS}
98         # ensure MOZCONFIG is not defined
99         eval unset MOZCONFIG
100
101         # set MOZILLA_FIVE_HOME
102         export MOZILLA_FIVE_HOME="/usr/$(get_libdir)/${PN}"
103
104         # nested configure scripts in mozilla products generate unrecognized options
105         # false positives when toplevel configure passes downwards.
106         export QA_CONFIGURE_OPTIONS=".*"
107
108         if [[ $(gcc-major-version) -eq 3 ]]; then
109                 ewarn "Unsupported compiler detected, DO NOT file bugs for"
110                 ewarn "outdated compilers. Bugs opened with gcc-3 will be closed"
111                 ewarn "invalid."
112         fi
113
114         python-any-r1_pkg_setup
115 }
116
117 # @FUNCTION: mozconfig_init
118 # @DESCRIPTION:
119 # Initialize mozilla configuration and populate with core settings.
120 # This should be called in src_configure before any other mozconfig_* functions.
121 mozconfig_init() {
122         declare enable_optimize pango_version myext x
123         declare XUL=$([[ ${PN} == xulrunner ]] && echo true || echo false)
124         declare FF=$([[ ${PN} == firefox ]] && echo true || echo false)
125         declare SM=$([[ ${PN} == seamonkey ]] && echo true || echo false)
126         declare TB=$([[ ${PN} == thunderbird ]] && echo true || echo false)
127
128         ####################################
129         #
130         # Setup the initial .mozconfig
131         # See http://www.mozilla.org/build/configure-build.html
132         #
133         ####################################
134
135         case ${PN} in
136                 *xulrunner)
137                         cp xulrunner/config/mozconfig .mozconfig \
138                                 || die "cp xulrunner/config/mozconfig failed" ;;
139                 *firefox)
140                         cp browser/config/mozconfig .mozconfig \
141                                 || die "cp browser/config/mozconfig failed" ;;
142                 seamonkey)
143                         # Must create the initial mozconfig to enable application
144                         : >.mozconfig || die "initial mozconfig creation failed"
145                         mozconfig_annotate "" --enable-application=suite ;;
146                 *thunderbird)
147                         # Must create the initial mozconfig to enable application
148                         : >.mozconfig || die "initial mozconfig creation failed"
149                         mozconfig_annotate "" --enable-application=mail ;;
150         esac
151
152         ####################################
153         #
154         # CFLAGS setup and ARCH support
155         #
156         ####################################
157
158         # Set optimization level
159         if [[ $(gcc-major-version) -ge 7 ]]; then
160                 mozconfig_annotate "Workaround known breakage" --enable-optimize=-O2
161         elif [[ ${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
167                 if is-flag -O0; then
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
179                 else
180                         mozconfig_annotate "Gentoo's default optimization" --enable-optimize=-O2
181                 fi
182         else
183                 # Enable Mozilla's default
184                 mozconfig_annotate "mozilla default" --enable-optimize
185         fi
186
187         # Strip optimization so it does not end up in compile string
188         filter-flags '-O*'
189
190         # Strip over-aggressive CFLAGS
191         use custom-cflags || strip-flags
192
193         # Additional ARCH support
194         case "${ARCH}" in
195         arm)
196                 # Reduce the memory requirements for linking
197                 append-ldflags -Wl,--no-keep-memory -Wl,--reduce-memory-overheads
198                 ;;
199         alpha)
200                 # Historically we have needed to add -fPIC manually for 64-bit.
201                 # Additionally, alpha should *always* build with -mieee for correct math
202                 # operation
203                 append-flags -fPIC -mieee
204                 ;;
205         ia64)
206                 # Historically we have needed to add this manually for 64-bit
207                 append-flags -fPIC
208                 ;;
209         ppc64)
210                 append-flags -fPIC -mminimal-toc
211                 # Reduce the memory requirements for linking
212                 append-ldflags -Wl,--no-keep-memory -Wl,--reduce-memory-overheads
213                 ;;
214         esac
215
216         # We need to append flags for gcc-6 support
217         if [[ $(gcc-major-version) -ge 6 ]]; then
218                 append-cxxflags -fno-delete-null-pointer-checks -fno-lifetime-dse -fno-schedule-insns2
219         fi
220
221         # Go a little faster; use less RAM
222         append-flags "$MAKEEDIT_FLAGS"
223
224         # Use the MOZILLA_FIVE_HOME for the rpath
225         append-ldflags -Wl,-rpath="${MOZILLA_FIVE_HOME}",--enable-new-dtags
226         # Set MOZILLA_FIVE_HOME in mozconfig
227         mozconfig_annotate '' --with-default-mozilla-five-home=${MOZILLA_FIVE_HOME}
228
229         ####################################
230         #
231         # mozconfig setup
232         #
233         ####################################
234
235         mozconfig_annotate disable_update_strip \
236                 --disable-updater \
237                 --disable-strip \
238                 --disable-install-strip
239
240         # jemalloc won't build with older glibc
241         ! has_version ">=sys-libs/glibc-2.4" && mozconfig_annotate "we have old glibc" --disable-jemalloc
242 }
243
244 # @FUNCTION: mozconfig_final
245 # @DESCRIPTION:
246 # Apply EXTRA_ECONF values to .mozconfig
247 # Display a table describing all configuration options paired
248 # with reasons, then clean up extensions list.
249 # This should be called in src_configure at the end of all other mozconfig_* functions.
250 mozconfig_final() {
251         declare ac opt hash reason
252
253         # Apply EXTRA_ECONF entries to .mozconfig
254         if [[ -n ${EXTRA_ECONF} ]]; then
255                 IFS=\! read -a ac <<<${EXTRA_ECONF// --/\!}
256                 for opt in "${ac[@]}"; do
257                         mozconfig_annotate "EXTRA_ECONF" --${opt#--}
258                 done
259         fi
260
261         echo
262         echo "=========================================================="
263         echo "Building ${PF} with the following configuration"
264         grep ^ac_add_options .mozconfig | while read ac opt hash reason; do
265                 [[ -z ${hash} || ${hash} == \# ]] \
266                         || die "error reading mozconfig: ${ac} ${opt} ${hash} ${reason}"
267                 printf "    %-30s  %s\n" "${opt}" "${reason:-mozilla.org default}"
268         done
269         echo "=========================================================="
270         echo
271
272         # Resolve multiple --enable-extensions down to one
273         declare exts=$(sed -n 's/^ac_add_options --enable-extensions=\([^ ]*\).*/\1/p' \
274                 .mozconfig | xargs)
275         sed -i '/^ac_add_options --enable-extensions/d' .mozconfig
276         echo "ac_add_options --enable-extensions=${exts// /,}" >> .mozconfig
277 }
278
279 _MOZCORECONF=1
280 fi