x11-terms/xfce4-terminal: amd64 stable wrt bug #712350
[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 #
4 # @ECLASS: mozcoreconf-v4.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 PYTHON_COMPAT=( python2_7 )
20 PYTHON_REQ_USE='ncurses,sqlite,ssl,threads'
21
22 inherit multilib toolchain-funcs flag-o-matic python-any-r1 versionator
23
24 IUSE="${IUSE} custom-cflags custom-optimization"
25
26 DEPEND="virtual/pkgconfig
27         ${PYTHON_DEPS}"
28
29 # @FUNCTION: mozconfig_annotate
30 # @DESCRIPTION:
31 # add an annotated line to .mozconfig
32 #
33 # Example:
34 # mozconfig_annotate "building on ultrasparc" --enable-js-ultrasparc
35 # => ac_add_options --enable-js-ultrasparc # building on ultrasparc
36 mozconfig_annotate() {
37         declare reason=$1 x ; shift
38         [[ $# -gt 0 ]] || die "mozconfig_annotate missing flags for ${reason}\!"
39         for x in ${*}; do
40                 echo "ac_add_options ${x} # ${reason}" >>.mozconfig
41         done
42 }
43
44 # @FUNCTION: mozconfig_use_enable
45 # @DESCRIPTION:
46 # add a line to .mozconfig based on a USE-flag
47 #
48 # Example:
49 # mozconfig_use_enable truetype freetype2
50 # => ac_add_options --enable-freetype2 # +truetype
51 mozconfig_use_enable() {
52         declare flag=$(use_enable "$@")
53         mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
54 }
55
56 # @FUNCTION mozconfig_use_with
57 # @DESCRIPTION
58 # add a line to .mozconfig based on a USE-flag
59 #
60 # Example:
61 # mozconfig_use_with kerberos gss-api /usr/$(get_libdir)
62 # => ac_add_options --with-gss-api=/usr/lib # +kerberos
63 mozconfig_use_with() {
64         declare flag=$(use_with "$@")
65         mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
66 }
67
68 # @FUNCTION mozconfig_use_extension
69 # @DESCRIPTION
70 # enable or disable an extension based on a USE-flag
71 #
72 # Example:
73 # mozconfig_use_extension gnome gnomevfs
74 # => ac_add_options --enable-extensions=gnomevfs
75 mozconfig_use_extension() {
76         declare minus=$(use $1 || echo -)
77         mozconfig_annotate "${minus:-+}$1" --enable-extensions=${minus}${2}
78 }
79
80 moz_pkgsetup() {
81         # Ensure we use C locale when building
82         export LANG="C"
83         export LC_ALL="C"
84         export LC_MESSAGES="C"
85         export LC_CTYPE="C"
86
87         # Ensure we use correct toolchain
88         export HOST_CC="$(tc-getBUILD_CC)"
89         export HOST_CXX="$(tc-getBUILD_CXX)"
90         tc-export CC CXX LD PKG_CONFIG
91
92         # Ensure that we have a sane build enviroment
93         export MOZILLA_CLIENT=1
94         export BUILD_OPT=1
95         export NO_STATIC_LIB=1
96         export USE_PTHREADS=1
97         export ALDFLAGS=${LDFLAGS}
98         # ensure MOZCONFIG is not defined
99         unset MOZCONFIG
100
101         # set MOZILLA_FIVE_HOME
102         export MOZILLA_FIVE_HOME="/usr/$(get_libdir)/${PN}"
103
104         # nested configure scripts in mozilla products generate unrecognized options
105         # false positives when toplevel configure passes downwards.
106         export QA_CONFIGURE_OPTIONS=".*"
107
108         if [[ $(gcc-major-version) -eq 3 ]]; then
109                 ewarn "Unsupported compiler detected, DO NOT file bugs for"
110                 ewarn "outdated compilers. Bugs opened with gcc-3 will be closed"
111                 ewarn "invalid."
112         fi
113
114         python-any-r1_pkg_setup
115 }
116
117 # @FUNCTION: mozconfig_init
118 # @DESCRIPTION:
119 # Initialize mozilla configuration and populate with core settings.
120 # This should be called in src_configure before any other mozconfig_* functions.
121 mozconfig_init() {
122         declare enable_optimize pango_version myext x
123         declare XUL=$([[ ${PN} == xulrunner ]] && echo true || echo false)
124         declare FF=$([[ ${PN} == firefox ]] && echo true || echo false)
125         declare SM=$([[ ${PN} == seamonkey ]] && echo true || echo false)
126         declare TB=$([[ ${PN} == thunderbird ]] && echo true || echo false)
127
128         ####################################
129         #
130         # Setup the initial .mozconfig
131         # See http://www.mozilla.org/build/configure-build.html
132         #
133         ####################################
134
135         case ${PN} in
136                 *xulrunner)
137                         cp xulrunner/config/mozconfig .mozconfig \
138                                 || die "cp xulrunner/config/mozconfig failed" ;;
139                 *firefox)
140                         cp browser/config/mozconfig .mozconfig \
141                                 || die "cp browser/config/mozconfig failed" ;;
142                 seamonkey)
143                         # Must create the initial mozconfig to enable application
144                         : >.mozconfig || die "initial mozconfig creation failed"
145                         mozconfig_annotate "" --enable-application=suite ;;
146                 *thunderbird)
147                         # Must create the initial mozconfig to enable application
148                         : >.mozconfig || die "initial mozconfig creation failed"
149                         mozconfig_annotate "" --enable-application=mail ;;
150         esac
151
152         ####################################
153         #
154         # CFLAGS setup and ARCH support
155         #
156         ####################################
157
158         # Set optimization level
159         if [[ ${ARCH} == hppa ]]; then
160                 mozconfig_annotate "more than -O0 causes a segfault on hppa" --enable-optimize=-O0
161         elif [[ ${ARCH} == x86 ]]; then
162                 mozconfig_annotate "less then -O2 causes a segfault on x86" --enable-optimize=-O2
163         elif use custom-optimization || [[ ${ARCH} =~ (alpha|ia64) ]]; then
164                 # Set optimization level based on CFLAGS
165                 if is-flag -O0; then
166                         mozconfig_annotate "from CFLAGS" --enable-optimize=-O0
167                 elif [[ ${ARCH} == ppc ]] && has_version '>=sys-libs/glibc-2.8'; then
168                         mozconfig_annotate "more than -O1 segfaults on ppc with glibc-2.8" --enable-optimize=-O1
169                 elif is-flag -O4; then
170                         mozconfig_annotate "from CFLAGS" --enable-optimize=-O4
171                 elif is-flag -O3; then
172                         mozconfig_annotate "from CFLAGS" --enable-optimize=-O3
173                 elif is-flag -O1; then
174                         mozconfig_annotate "from CFLAGS" --enable-optimize=-O1
175                 elif is-flag -Os; then
176                         mozconfig_annotate "from CFLAGS" --enable-optimize=-Os
177                 else
178                         mozconfig_annotate "Gentoo's default optimization" --enable-optimize=-O2
179                 fi
180         else
181                 # Enable Mozilla's default
182                 mozconfig_annotate "mozilla default" --enable-optimize
183         fi
184
185         # Strip optimization so it does not end up in compile string
186         filter-flags '-O*'
187
188         # Strip over-aggressive CFLAGS
189         use custom-cflags || strip-flags
190
191         # Additional ARCH support
192         case "${ARCH}" in
193         alpha)
194                 # Historically we have needed to add -fPIC manually for 64-bit.
195                 # Additionally, alpha should *always* build with -mieee for correct math
196                 # operation
197                 append-flags -fPIC -mieee
198                 ;;
199
200         ia64)
201                 # Historically we have needed to add this manually for 64-bit
202                 append-flags -fPIC
203                 ;;
204
205         ppc64)
206                 append-flags -fPIC -mminimal-toc
207                 ;;
208         esac
209
210         # We need to append flags for gcc-6 support
211         if [[ $(gcc-major-version) -ge 6 ]]; then
212                 append-cxxflags -fno-delete-null-pointer-checks -fno-lifetime-dse -fno-schedule-insns2
213         fi
214
215         # Use the MOZILLA_FIVE_HOME for the rpath
216         append-ldflags -Wl,-rpath="${MOZILLA_FIVE_HOME}",--enable-new-dtags
217         # Set MOZILLA_FIVE_HOME in mozconfig
218         mozconfig_annotate '' --with-default-mozilla-five-home=${MOZILLA_FIVE_HOME}
219
220         ####################################
221         #
222         # mozconfig setup
223         #
224         ####################################
225
226         mozconfig_annotate disable_update_strip \
227                 --disable-updater \
228                 --disable-strip \
229                 --disable-install-strip
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=1
261 fi