dev-python/josepy: 1.1.0 cleanup
[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         dev-lang/python:2.7[ncurses,sqlite,ssl,threads(+)]
25         ${PYTHON_DEPS}"
26
27 # @FUNCTION: mozconfig_annotate
28 # @DESCRIPTION:
29 # add an annotated line to .mozconfig
30 #
31 # Example:
32 # mozconfig_annotate "building on ultrasparc" --enable-js-ultrasparc
33 # => ac_add_options --enable-js-ultrasparc # building on ultrasparc
34 mozconfig_annotate() {
35         declare reason=$1 x ; shift
36         [[ $# -gt 0 ]] || die "mozconfig_annotate missing flags for ${reason}\!"
37         for x in ${*}; do
38                 echo "ac_add_options ${x} # ${reason}" >>.mozconfig
39         done
40 }
41
42 # @FUNCTION: mozconfig_use_enable
43 # @DESCRIPTION:
44 # add a line to .mozconfig based on a USE-flag
45 #
46 # Example:
47 # mozconfig_use_enable truetype freetype2
48 # => ac_add_options --enable-freetype2 # +truetype
49 mozconfig_use_enable() {
50         declare flag=$(use_enable "$@")
51         mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
52 }
53
54 # @FUNCTION mozconfig_use_with
55 # @DESCRIPTION
56 # add a line to .mozconfig based on a USE-flag
57 #
58 # Example:
59 # mozconfig_use_with kerberos gss-api /usr/$(get_libdir)
60 # => ac_add_options --with-gss-api=/usr/lib # +kerberos
61 mozconfig_use_with() {
62         declare flag=$(use_with "$@")
63         mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
64 }
65
66 # @FUNCTION mozconfig_use_extension
67 # @DESCRIPTION
68 # enable or disable an extension based on a USE-flag
69 #
70 # Example:
71 # mozconfig_use_extension gnome gnomevfs
72 # => ac_add_options --enable-extensions=gnomevfs
73 mozconfig_use_extension() {
74         declare minus=$(use $1 || echo -)
75         mozconfig_annotate "${minus:-+}$1" --enable-extensions=${minus}${2}
76 }
77
78 moz_pkgsetup() {
79         # Ensure we use C locale when building
80         export LANG="C"
81         export LC_ALL="C"
82         export LC_MESSAGES="C"
83         export LC_CTYPE="C"
84
85         # Ensure we use correct toolchain
86         export HOST_CC="$(tc-getBUILD_CC)"
87         export HOST_CXX="$(tc-getBUILD_CXX)"
88         tc-export CC CXX LD PKG_CONFIG AR RANLIB
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         unset MOZCONFIG
98
99         # set MOZILLA_FIVE_HOME
100         export MOZILLA_FIVE_HOME="/usr/$(get_libdir)/${PN}"
101
102         # nested configure scripts in mozilla products generate unrecognized options
103         # false positives when toplevel configure passes downwards.
104         export QA_CONFIGURE_OPTIONS=".*"
105
106         python-any-r1_pkg_setup
107         # workaround to set python3 into PYTHON3 until mozilla doesn't need py2
108         if [[ "${PYTHON_COMPAT[@]}" != "${PYTHON_COMPAT[@]#python3*}" ]]; then
109                 export PYTHON3=${PYTHON}
110                 python_export python2_7 PYTHON EPYTHON
111         fi
112 }
113
114 # @FUNCTION: mozconfig_init
115 # @DESCRIPTION:
116 # Initialize mozilla configuration and populate with core settings.
117 # This should be called in src_configure before any other mozconfig_* functions.
118 mozconfig_init() {
119         declare enable_optimize pango_version myext x
120         declare XUL=$([[ ${PN} == xulrunner ]] && echo true || echo false)
121         declare FF=$([[ ${PN} == firefox ]] && echo true || echo false)
122         declare SM=$([[ ${PN} == seamonkey ]] && echo true || echo false)
123         declare TB=$([[ ${PN} == thunderbird ]] && echo true || echo false)
124         declare TRB=$([[ ${PN} == torbrowser ]] && echo true || echo false)
125
126         ####################################
127         #
128         # Setup the initial .mozconfig
129         # See http://www.mozilla.org/build/configure-build.html
130         #
131         ####################################
132
133         case ${PN} in
134                 *xulrunner)
135                         cp xulrunner/config/mozconfig .mozconfig \
136                                 || die "cp xulrunner/config/mozconfig failed" ;;
137                 *firefox)
138                         cp browser/config/mozconfig .mozconfig \
139                                 || die "cp browser/config/mozconfig failed" ;;
140                 *torbrowser)
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                         # NOTE--this is not compatible with mozilla prior to v60
147                         mozconfig_annotate "" --enable-application=comm/suite ;;
148                 *thunderbird)
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/mail ;;
153         esac
154
155         ####################################
156         #
157         # CFLAGS setup and ARCH support
158         #
159         ####################################
160
161         # Set optimization level
162         if [[ $(gcc-major-version) -eq 7 ]]; then
163                 mozconfig_annotate "Workaround known breakage" --enable-optimize=-O2
164         elif [[ ${ARCH} == hppa ]]; then
165                 mozconfig_annotate "more than -O0 causes a segfault on hppa" --enable-optimize=-O0
166         elif [[ ${ARCH} == x86 ]]; then
167                 mozconfig_annotate "less than -O2 causes a segfault on x86" --enable-optimize=-O2
168         elif [[ ${ARCH} == arm ]] && [[ $(gcc-major-version) -ge 6 ]]; then
169                 mozconfig_annotate "less than -O2 causes a breakage on arm with gcc-6" --enable-optimize=-O2
170         elif use custom-optimization || [[ ${ARCH} =~ (alpha|ia64) ]]; then
171                 # Set optimization level based on CFLAGS
172                 if is-flag -O0; then
173                         mozconfig_annotate "from CFLAGS" --enable-optimize=-O0
174                 elif [[ ${ARCH} == ppc ]] && has_version '>=sys-libs/glibc-2.8'; then
175                         mozconfig_annotate "more than -O1 segfaults on ppc with glibc-2.8" --enable-optimize=-O1
176                 elif is-flag -O4; then
177                         mozconfig_annotate "from CFLAGS" --enable-optimize=-O4
178                 elif is-flag -O3; then
179                         mozconfig_annotate "from CFLAGS" --enable-optimize=-O3
180                 elif is-flag -O1; then
181                         mozconfig_annotate "from CFLAGS" --enable-optimize=-O1
182                 elif is-flag -Os; then
183                         mozconfig_annotate "from CFLAGS" --enable-optimize=-Os
184                 else
185                         mozconfig_annotate "Gentoo's default optimization" --enable-optimize=-O2
186                 fi
187         else
188                 # Enable Mozilla's default
189                 mozconfig_annotate "mozilla default" --enable-optimize
190         fi
191
192         # Strip optimization so it does not end up in compile string
193         filter-flags '-O*'
194
195         if is-flagq '-g*' ; then
196                 mozconfig_annotate 'elf-hack broken with -g* flags' --disable-elf-hack
197         fi
198
199         # Strip over-aggressive CFLAGS
200         use custom-cflags || strip-flags
201
202         # Additional ARCH support
203         case "${ARCH}" in
204         arm | ppc64)
205                 # Reduce the memory requirements for linking
206                 if use clang ; then
207                         # Nothing to do
208                         :;
209                 elif tc-ld-is-gold; then
210                         append-ldflags -Wl,--no-keep-memory
211                 else
212                         append-ldflags -Wl,--no-keep-memory -Wl,--reduce-memory-overheads
213                 fi
214                 ;;
215         alpha)
216                 # Historically we have needed to add -fPIC manually for 64-bit.
217                 # Additionally, alpha should *always* build with -mieee for correct math
218                 # operation
219                 append-flags -fPIC -mieee
220                 ;;
221         ia64)
222                 # Historically we have needed to add this manually for 64-bit
223                 append-flags -fPIC
224                 ;;
225         esac
226
227         # We need to append flags for gcc-6 support
228         if [[ $(gcc-major-version) -ge 6 ]]; then
229                 append-cxxflags -flifetime-dse=1
230         fi
231
232         # Use the MOZILLA_FIVE_HOME for the rpath
233         append-ldflags -Wl,-rpath="${MOZILLA_FIVE_HOME}",--enable-new-dtags
234
235         ####################################
236         #
237         # mozconfig setup
238         #
239         ####################################
240
241         mozconfig_annotate disable_update_strip \
242                 --disable-updater \
243                 --disable-strip \
244                 --disable-install-strip
245
246         # jemalloc won't build with older glibc
247         ! has_version ">=sys-libs/glibc-2.4" && mozconfig_annotate "we have old glibc" --disable-jemalloc
248 }
249
250 # @FUNCTION: mozconfig_final
251 # @DESCRIPTION:
252 # Apply EXTRA_ECONF values to .mozconfig
253 # Display a table describing all configuration options paired
254 # with reasons, then clean up extensions list.
255 # This should be called in src_configure at the end of all other mozconfig_* functions.
256 mozconfig_final() {
257         declare ac opt hash reason
258
259         # Apply EXTRA_ECONF entries to .mozconfig
260         if [[ -n ${EXTRA_ECONF} ]]; then
261                 IFS=\! read -a ac <<<${EXTRA_ECONF// --/\!}
262                 for opt in "${ac[@]}"; do
263                         mozconfig_annotate "EXTRA_ECONF" --${opt#--}
264                 done
265         fi
266
267         echo
268         echo "=========================================================="
269         echo "Building ${PF} with the following configuration"
270         grep ^ac_add_options .mozconfig | while read ac opt hash reason; do
271                 [[ -z ${hash} || ${hash} == \# ]] \
272                         || die "error reading mozconfig: ${ac} ${opt} ${hash} ${reason}"
273                 printf "    %-30s  %s\n" "${opt}" "${reason:-mozilla.org default}"
274         done
275         echo "=========================================================="
276         echo
277
278         # Resolve multiple --enable-extensions down to one
279         declare exts=$(sed -n 's/^ac_add_options --enable-extensions=\([^ ]*\).*/\1/p' \
280                 .mozconfig | xargs)
281         sed -i '/^ac_add_options --enable-extensions/d' .mozconfig
282         echo "ac_add_options --enable-extensions=${exts// /,}" >> .mozconfig
283 }
284
285 _MOZCORECONF=1
286 fi