]> git.draconx.ca Git - gentoo-fixes.git/blob - eclass/mozcoreconf-v5.eclass
ce0e2a402f2a78cc0188257d8fa5cc5c0628973c
[gentoo-fixes.git] / eclass / mozcoreconf-v5.eclass
1 # This eclass is a modified version of the work originally distributed with
2 # Gentoo GNU/Linux, covered by the following copyright and permission notice:
3 #
4 #   Copyright 1999-2022 Gentoo Authors
5 #   Distributed under the terms of the GNU General Public License v2
6 #
7 # The modifications are:
8 #
9 #   * Avoid python eclasses which no longer support python2 (2022-12)
10 #
11 # @DEAD
12 # @ECLASS: mozcoreconf-v5.eclass
13 # @MAINTAINER:
14 # Mozilla team <mozilla@gentoo.org>
15 # @BLURB: core options and configuration functions for mozilla
16 # @DESCRIPTION:
17 #
18 # inherit mozconfig-v6.* or above for mozilla configuration support
19
20 # @ECLASS_VARIABLE: MOZILLA_FIVE_HOME
21 # @DESCRIPTION:
22 # This is an eclass-generated variable that defines the rpath that the mozilla
23 # product will be installed in.  Read-only
24
25 if [[ ! ${_MOZCORECONF} ]]; then
26
27 inherit multilib toolchain-funcs flag-o-matic versionator
28
29 IUSE="${IUSE} custom-cflags custom-optimization"
30
31 DEPEND="virtual/pkgconfig
32         dev-lang/python:2.7[ncurses,sqlite,ssl,threads(+)]"
33
34 # @FUNCTION: mozconfig_annotate
35 # @DESCRIPTION:
36 # add an annotated line to .mozconfig
37 #
38 # Example:
39 # mozconfig_annotate "building on ultrasparc" --enable-js-ultrasparc
40 # => ac_add_options --enable-js-ultrasparc # building on ultrasparc
41 mozconfig_annotate() {
42         declare reason=$1 x ; shift
43         [[ $# -gt 0 ]] || die "mozconfig_annotate missing flags for ${reason}\!"
44         for x in ${*}; do
45                 echo "ac_add_options ${x} # ${reason}" >>.mozconfig
46         done
47 }
48
49 # @FUNCTION: mozconfig_use_enable
50 # @DESCRIPTION:
51 # add a line to .mozconfig based on a USE-flag
52 #
53 # Example:
54 # mozconfig_use_enable truetype freetype2
55 # => ac_add_options --enable-freetype2 # +truetype
56 mozconfig_use_enable() {
57         declare flag=$(use_enable "$@")
58         mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
59 }
60
61 # @FUNCTION: mozconfig_use_with
62 # @DESCRIPTION:
63 # add a line to .mozconfig based on a USE-flag
64 #
65 # Example:
66 # mozconfig_use_with kerberos gss-api /usr/$(get_libdir)
67 # => ac_add_options --with-gss-api=/usr/lib # +kerberos
68 mozconfig_use_with() {
69         declare flag=$(use_with "$@")
70         mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
71 }
72
73 # @FUNCTION: mozconfig_use_extension
74 # @DESCRIPTION:
75 # enable or disable an extension based on a USE-flag
76 #
77 # Example:
78 # mozconfig_use_extension gnome gnomevfs
79 # => ac_add_options --enable-extensions=gnomevfs
80 mozconfig_use_extension() {
81         declare minus=$(use $1 || echo -)
82         mozconfig_annotate "${minus:-+}$1" --enable-extensions=${minus}${2}
83 }
84
85 moz_pkgsetup() {
86         # Ensure we use C locale when building
87         export LANG="C"
88         export LC_ALL="C"
89         export LC_MESSAGES="C"
90         export LC_CTYPE="C"
91
92         # Ensure we use correct toolchain
93         export HOST_CC="$(tc-getBUILD_CC)"
94         export HOST_CXX="$(tc-getBUILD_CXX)"
95         tc-export CC CXX LD PKG_CONFIG
96
97         # Ensure that we have a sane build enviroment
98         export MOZILLA_CLIENT=1
99         export BUILD_OPT=1
100         export NO_STATIC_LIB=1
101         export USE_PTHREADS=1
102         export ALDFLAGS=${LDFLAGS}
103         # ensure MOZCONFIG is not defined
104         unset MOZCONFIG
105
106         # set MOZILLA_FIVE_HOME
107         export MOZILLA_FIVE_HOME="/usr/$(get_libdir)/${PN}"
108
109         # nested configure scripts in mozilla products generate unrecognized options
110         # false positives when toplevel configure passes downwards.
111         export QA_CONFIGURE_OPTIONS=".*"
112
113         export PYTHON=python2.7
114 }
115
116 # @FUNCTION: mozconfig_init
117 # @DESCRIPTION:
118 # Initialize mozilla configuration and populate with core settings.
119 # This should be called in src_configure before any other mozconfig_* functions.
120 mozconfig_init() {
121         declare enable_optimize pango_version myext x
122         declare XUL=$([[ ${PN} == xulrunner ]] && echo true || echo false)
123         declare FF=$([[ ${PN} == firefox ]] && echo true || echo false)
124         declare SM=$([[ ${PN} == seamonkey ]] && echo true || echo false)
125         declare TB=$([[ ${PN} == thunderbird ]] && echo true || echo false)
126         declare WF=$([[ ${PN} == waterfox* ]] && 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|waterfox*)
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         mozconfig_annotate "Workaround known breakage" --enable-optimize=-O2
160
161         if [[ ${ARCH} == hppa ]]; then
162                 mozconfig_annotate "more than -O0 causes a segfault on hppa" --enable-optimize=-O0
163         elif [[ ${ARCH} == x86 ]]; then
164                 mozconfig_annotate "less then -O2 causes a segfault on x86" --enable-optimize=-O2
165         elif use custom-optimization || [[ ${ARCH} =~ (alpha|ia64) ]]; then
166                 # Set optimization level based on CFLAGS
167                 if is-flag -O0; then
168                         mozconfig_annotate "from CFLAGS" --enable-optimize=-O0
169                 elif [[ ${ARCH} == ppc ]] && has_version '>=sys-libs/glibc-2.8'; then
170                         mozconfig_annotate "more than -O1 segfaults on ppc with glibc-2.8" --enable-optimize=-O1
171                 elif is-flag -O4; then
172                         mozconfig_annotate "from CFLAGS" --enable-optimize=-O4
173                 elif is-flag -O3; then
174                         mozconfig_annotate "from CFLAGS" --enable-optimize=-O3
175                 elif is-flag -O1; then
176                         mozconfig_annotate "from CFLAGS" --enable-optimize=-O1
177                 elif is-flag -Os; then
178                         mozconfig_annotate "from CFLAGS" --enable-optimize=-Os
179                 else
180                         mozconfig_annotate "Gentoo's default optimization" --enable-optimize=-O2
181                 fi
182         else
183                 # Enable Mozilla's default
184                 mozconfig_annotate "mozilla default" --enable-optimize
185         fi
186
187         # Strip optimization so it does not end up in compile string
188         filter-flags '-O*'
189
190         # Strip over-aggressive CFLAGS
191         use custom-cflags || strip-flags
192
193         # Additional ARCH support
194         case "${ARCH}" in
195         arm)
196                 # Reduce the memory requirements for linking
197                 append-ldflags -Wl,--no-keep-memory -Wl,--reduce-memory-overheads
198                 ;;
199         alpha)
200                 # Historically we have needed to add -fPIC manually for 64-bit.
201                 # Additionally, alpha should *always* build with -mieee for correct math
202                 # operation
203                 append-flags -fPIC -mieee
204                 ;;
205         ia64)
206                 # Historically we have needed to add this manually for 64-bit
207                 append-flags -fPIC
208                 ;;
209         ppc64)
210                 append-flags -fPIC -mminimal-toc
211                 # Reduce the memory requirements for linking
212                 append-ldflags -Wl,--no-keep-memory -Wl,--reduce-memory-overheads
213                 ;;
214         esac
215
216         # We need to append flags for >= gcc-6 support
217         append-cxxflags -fno-delete-null-pointer-checks -fno-lifetime-dse -fno-schedule-insns2
218
219         # Use the MOZILLA_FIVE_HOME for the rpath
220         append-ldflags -Wl,-rpath="${MOZILLA_FIVE_HOME}",--enable-new-dtags
221         # Set MOZILLA_FIVE_HOME in mozconfig
222         mozconfig_annotate '' --with-default-mozilla-five-home=${MOZILLA_FIVE_HOME}
223
224         ####################################
225         #
226         # mozconfig setup
227         #
228         ####################################
229
230         mozconfig_annotate disable_update_strip \
231                 --disable-updater \
232                 --disable-strip \
233                 --disable-install-strip
234
235         # jemalloc won't build with older glibc
236         ! has_version ">=sys-libs/glibc-2.4" && mozconfig_annotate "we have old glibc" --disable-jemalloc
237 }
238
239 # @FUNCTION: mozconfig_final
240 # @DESCRIPTION:
241 # Apply EXTRA_ECONF values to .mozconfig
242 # Display a table describing all configuration options paired
243 # with reasons, then clean up extensions list.
244 # This should be called in src_configure at the end of all other mozconfig_* functions.
245 mozconfig_final() {
246         declare ac opt hash reason
247
248         # Apply EXTRA_ECONF entries to .mozconfig
249         if [[ -n ${EXTRA_ECONF} ]]; then
250                 IFS=\! read -a ac <<<${EXTRA_ECONF// --/\!}
251                 for opt in "${ac[@]}"; do
252                         mozconfig_annotate "EXTRA_ECONF" --${opt#--}
253                 done
254         fi
255
256         echo
257         echo "=========================================================="
258         echo "Building ${PF} with the following configuration"
259         grep ^ac_add_options .mozconfig | while read ac opt hash reason; do
260                 [[ -z ${hash} || ${hash} == \# ]] \
261                         || die "error reading mozconfig: ${ac} ${opt} ${hash} ${reason}"
262                 printf "    %-30s  %s\n" "${opt}" "${reason:-mozilla.org default}"
263         done
264         echo "=========================================================="
265         echo
266
267         # Resolve multiple --enable-extensions down to one
268         declare exts=$(sed -n 's/^ac_add_options --enable-extensions=\([^ ]*\).*/\1/p' \
269                 .mozconfig | xargs)
270         sed -i '/^ac_add_options --enable-extensions/d' .mozconfig
271         echo "ac_add_options --enable-extensions=${exts// /,}" >> .mozconfig
272 }
273
274 _MOZCORECONF=1
275 fi