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