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