media-plugins/gst-plugins-taglib-1.14.4: ppc stable, bug 674854
[gentoo.git] / eclass / mozcoreconf-v6.eclass
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 #
4 # @ECLASS: mozcoreconf-v6.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 inherit multilib toolchain-funcs flag-o-matic python-any-r1 versionator
20
21 IUSE="${IUSE} custom-cflags custom-optimization"
22
23 DEPEND="virtual/pkgconfig
24         ${PYTHON_DEPS}"
25
26 # @FUNCTION: mozconfig_annotate
27 # @DESCRIPTION:
28 # add an annotated line to .mozconfig
29 #
30 # Example:
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}\!"
36         for x in ${*}; do
37                 echo "ac_add_options ${x} # ${reason}" >>.mozconfig
38         done
39 }
40
41 # @FUNCTION: mozconfig_use_enable
42 # @DESCRIPTION:
43 # add a line to .mozconfig based on a USE-flag
44 #
45 # Example:
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}"
51 }
52
53 # @FUNCTION mozconfig_use_with
54 # @DESCRIPTION
55 # add a line to .mozconfig based on a USE-flag
56 #
57 # Example:
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}"
63 }
64
65 # @FUNCTION mozconfig_use_extension
66 # @DESCRIPTION
67 # enable or disable an extension based on a USE-flag
68 #
69 # Example:
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}
75 }
76
77 moz_pkgsetup() {
78         # Ensure we use C locale when building
79         export LANG="C"
80         export LC_ALL="C"
81         export LC_MESSAGES="C"
82         export LC_CTYPE="C"
83
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
88
89         # Ensure that we have a sane build enviroment
90         export MOZILLA_CLIENT=1
91         export BUILD_OPT=1
92         export NO_STATIC_LIB=1
93         export USE_PTHREADS=1
94         export ALDFLAGS=${LDFLAGS}
95         # ensure MOZCONFIG is not defined
96         unset MOZCONFIG
97
98         # set MOZILLA_FIVE_HOME
99         export MOZILLA_FIVE_HOME="/usr/$(get_libdir)/${PN}"
100
101         # nested configure scripts in mozilla products generate unrecognized options
102         # false positives when toplevel configure passes downwards.
103         export QA_CONFIGURE_OPTIONS=".*"
104
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"
108                 ewarn "invalid."
109         fi
110
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
116         fi
117 }
118
119 # @FUNCTION: mozconfig_init
120 # @DESCRIPTION:
121 # Initialize mozilla configuration and populate with core settings.
122 # This should be called in src_configure before any other mozconfig_* functions.
123 mozconfig_init() {
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)
130
131         ####################################
132         #
133         # Setup the initial .mozconfig
134         # See http://www.mozilla.org/build/configure-build.html
135         #
136         ####################################
137
138         case ${PN} in
139                 *xulrunner)
140                         cp xulrunner/config/mozconfig .mozconfig \
141                                 || die "cp xulrunner/config/mozconfig failed" ;;
142                 *firefox)
143                         cp browser/config/mozconfig .mozconfig \
144                                 || die "cp browser/config/mozconfig failed" ;;
145                 *torbrowser)
146                         cp browser/config/mozconfig .mozconfig \
147                                 || die "cp browser/config/mozconfig failed" ;;
148                 seamonkey)
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 ;;
153                 *thunderbird)
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 ;;
158         esac
159
160         ####################################
161         #
162         # CFLAGS setup and ARCH support
163         #
164         ####################################
165
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
177                 if is-flag -O0; then
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
189                 else
190                         mozconfig_annotate "Gentoo's default optimization" --enable-optimize=-O2
191                 fi
192         else
193                 # Enable Mozilla's default
194                 mozconfig_annotate "mozilla default" --enable-optimize
195         fi
196
197         # Strip optimization so it does not end up in compile string
198         filter-flags '-O*'
199
200         # Strip over-aggressive CFLAGS
201         use custom-cflags || strip-flags
202
203         # Additional ARCH support
204         case "${ARCH}" in
205         arm)
206                 # Reduce the memory requirements for linking
207                 if use clang ; then
208                         # Nothing to do
209                         :;
210                 elif tc-ld-is-gold ; then
211                         append-ldflags -Wl,--no-keep-memory
212                 else
213                         append-ldflags -Wl,--no-keep-memory -Wl,--reduce-memory-overheads
214                 fi
215                 ;;
216         alpha)
217                 # Historically we have needed to add -fPIC manually for 64-bit.
218                 # Additionally, alpha should *always* build with -mieee for correct math
219                 # operation
220                 append-flags -fPIC -mieee
221                 ;;
222         ia64)
223                 # Historically we have needed to add this manually for 64-bit
224                 append-flags -fPIC
225                 ;;
226         ppc64)
227                 append-flags -fPIC -mminimal-toc
228                 # Reduce the memory requirements for linking
229                 if use clang ; then
230                         # Nothing to do
231                         :;
232                 elif tc-ld-is-gold ; then
233                         append-ldflags -Wl,--no-keep-memory
234                 else
235                         append-ldflags -Wl,--no-keep-memory -Wl,--reduce-memory-overheads
236                 fi
237                 ;;
238         esac
239
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
243         fi
244
245         # Use the MOZILLA_FIVE_HOME for the rpath
246         append-ldflags -Wl,-rpath="${MOZILLA_FIVE_HOME}",--enable-new-dtags
247
248         ####################################
249         #
250         # mozconfig setup
251         #
252         ####################################
253
254         mozconfig_annotate disable_update_strip \
255                 --disable-updater \
256                 --disable-strip \
257                 --disable-install-strip
258
259         # jemalloc won't build with older glibc
260         ! has_version ">=sys-libs/glibc-2.4" && mozconfig_annotate "we have old glibc" --disable-jemalloc
261 }
262
263 # @FUNCTION: mozconfig_final
264 # @DESCRIPTION:
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.
269 mozconfig_final() {
270         declare ac opt hash reason
271
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#--}
277                 done
278         fi
279
280         echo
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}"
287         done
288         echo "=========================================================="
289         echo
290
291         # Resolve multiple --enable-extensions down to one
292         declare exts=$(sed -n 's/^ac_add_options --enable-extensions=\([^ ]*\).*/\1/p' \
293                 .mozconfig | xargs)
294         sed -i '/^ac_add_options --enable-extensions/d' .mozconfig
295         echo "ac_add_options --enable-extensions=${exts// /,}" >> .mozconfig
296 }
297
298 _MOZCORECONF=1
299 fi