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