|
1 dnl This Source Code Form is subject to the terms of the Mozilla Public |
|
2 dnl License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 dnl file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
4 |
|
5 dnl Add compiler specific options |
|
6 |
|
7 AC_DEFUN([MOZ_DEFAULT_COMPILER], |
|
8 [ |
|
9 dnl set DEVELOPER_OPTIONS early; MOZ_DEFAULT_COMPILER is usually the first non-setup directive |
|
10 if test -z "$MOZILLA_OFFICIAL"; then |
|
11 DEVELOPER_OPTIONS=1 |
|
12 fi |
|
13 MOZ_ARG_ENABLE_BOOL(release, |
|
14 [ --enable-release Build with more conservative, release engineering-oriented options. |
|
15 This may slow down builds.], |
|
16 DEVELOPER_OPTIONS=, |
|
17 DEVELOPER_OPTIONS=1) |
|
18 |
|
19 AC_SUBST(DEVELOPER_OPTIONS) |
|
20 |
|
21 dnl Default to MSVC for win32 and gcc-4.2 for darwin |
|
22 dnl ============================================================== |
|
23 if test -z "$CROSS_COMPILE"; then |
|
24 case "$target" in |
|
25 *-mingw*) |
|
26 if test -z "$CC"; then CC=cl; fi |
|
27 if test -z "$CXX"; then CXX=cl; fi |
|
28 if test -z "$CPP"; then CPP="cl -E -nologo"; fi |
|
29 if test -z "$CXXCPP"; then CXXCPP="cl -TP -E -nologo"; ac_cv_prog_CXXCPP="$CXXCPP"; fi |
|
30 if test -z "$LD"; then LD=link; fi |
|
31 if test -z "$AS"; then |
|
32 case "${target_cpu}" in |
|
33 i*86) |
|
34 AS=ml; |
|
35 ;; |
|
36 x86_64) |
|
37 AS=ml64; |
|
38 ;; |
|
39 esac |
|
40 fi |
|
41 if test -z "$MIDL"; then MIDL=midl; fi |
|
42 |
|
43 # need override this flag since we don't use $(LDFLAGS) for this. |
|
44 if test -z "$HOST_LDFLAGS" ; then |
|
45 HOST_LDFLAGS=" " |
|
46 fi |
|
47 ;; |
|
48 *-darwin*) |
|
49 # GCC on darwin is based on gcc 4.2 and we don't support it anymore. |
|
50 if test -z "$CC"; then |
|
51 MOZ_PATH_PROGS(CC, clang) |
|
52 fi |
|
53 if test -z "$CXX"; then |
|
54 MOZ_PATH_PROGS(CXX, clang++) |
|
55 fi |
|
56 IS_GCC=$($CC -v 2>&1 | grep gcc) |
|
57 if test -n "$IS_GCC" |
|
58 then |
|
59 echo gcc is known to be broken on OS X, please use clang. |
|
60 echo see http://developer.mozilla.org/en-US/docs/Developer_Guide/Build_Instructions/Mac_OS_X_Prerequisites |
|
61 echo for more information. |
|
62 exit 1 |
|
63 fi |
|
64 ;; |
|
65 esac |
|
66 fi |
|
67 ]) |
|
68 |
|
69 dnl ============================================================================ |
|
70 dnl C++ rtti |
|
71 dnl We don't use it in the code, but it can be usefull for debugging, so give |
|
72 dnl the user the option of enabling it. |
|
73 dnl ============================================================================ |
|
74 AC_DEFUN([MOZ_RTTI], |
|
75 [ |
|
76 MOZ_ARG_ENABLE_BOOL(cpp-rtti, |
|
77 [ --enable-cpp-rtti Enable C++ RTTI ], |
|
78 [ _MOZ_USE_RTTI=1 ], |
|
79 [ _MOZ_USE_RTTI= ]) |
|
80 |
|
81 if test -z "$_MOZ_USE_RTTI"; then |
|
82 if test "$GNU_CC"; then |
|
83 CXXFLAGS="$CXXFLAGS -fno-rtti" |
|
84 else |
|
85 case "$target" in |
|
86 *-mingw*) |
|
87 CXXFLAGS="$CXXFLAGS -GR-" |
|
88 esac |
|
89 fi |
|
90 fi |
|
91 ]) |
|
92 |
|
93 dnl ======================================================== |
|
94 dnl = |
|
95 dnl = Debugging Options |
|
96 dnl = |
|
97 dnl ======================================================== |
|
98 AC_DEFUN([MOZ_DEBUGGING_OPTS], |
|
99 [ |
|
100 dnl Debug info is ON by default. |
|
101 if test -z "$MOZ_DEBUG_FLAGS"; then |
|
102 if test -n "$_MSC_VER"; then |
|
103 MOZ_DEBUG_FLAGS="-Zi" |
|
104 else |
|
105 MOZ_DEBUG_FLAGS="-g" |
|
106 fi |
|
107 fi |
|
108 |
|
109 AC_SUBST(MOZ_DEBUG_FLAGS) |
|
110 |
|
111 MOZ_ARG_ENABLE_STRING(debug, |
|
112 [ --enable-debug[=DBG] Enable building with developer debug info |
|
113 (using compiler flags DBG)], |
|
114 [ if test "$enableval" != "no"; then |
|
115 MOZ_DEBUG=1 |
|
116 if test -n "$enableval" -a "$enableval" != "yes"; then |
|
117 MOZ_DEBUG_FLAGS=`echo $enableval | sed -e 's|\\\ | |g'` |
|
118 _MOZ_DEBUG_FLAGS_SET=1 |
|
119 fi |
|
120 else |
|
121 MOZ_DEBUG= |
|
122 fi ], |
|
123 MOZ_DEBUG=) |
|
124 |
|
125 MOZ_DEBUG_ENABLE_DEFS="-DDEBUG -D_DEBUG -DTRACING" |
|
126 MOZ_ARG_WITH_STRING(debug-label, |
|
127 [ --with-debug-label=LABELS |
|
128 Define DEBUG_<value> for each comma-separated |
|
129 value given.], |
|
130 [ for option in `echo $withval | sed 's/,/ /g'`; do |
|
131 MOZ_DEBUG_ENABLE_DEFS="$MOZ_DEBUG_ENABLE_DEFS -DDEBUG_${option}" |
|
132 done]) |
|
133 |
|
134 MOZ_DEBUG_DISABLE_DEFS="-DNDEBUG -DTRIMMED" |
|
135 |
|
136 if test -n "$MOZ_DEBUG"; then |
|
137 AC_MSG_CHECKING([for valid debug flags]) |
|
138 _SAVE_CFLAGS=$CFLAGS |
|
139 CFLAGS="$CFLAGS $MOZ_DEBUG_FLAGS" |
|
140 AC_TRY_COMPILE([#include <stdio.h>], |
|
141 [printf("Hello World\n");], |
|
142 _results=yes, |
|
143 _results=no) |
|
144 AC_MSG_RESULT([$_results]) |
|
145 if test "$_results" = "no"; then |
|
146 AC_MSG_ERROR([These compiler flags are invalid: $MOZ_DEBUG_FLAGS]) |
|
147 fi |
|
148 CFLAGS=$_SAVE_CFLAGS |
|
149 fi |
|
150 |
|
151 dnl ======================================================== |
|
152 dnl = Enable generation of debug symbols |
|
153 dnl ======================================================== |
|
154 MOZ_ARG_ENABLE_STRING(debug-symbols, |
|
155 [ --enable-debug-symbols[=DBG] |
|
156 Enable debugging symbols (using compiler flags DBG)], |
|
157 [ if test "$enableval" != "no"; then |
|
158 MOZ_DEBUG_SYMBOLS=1 |
|
159 if test -n "$enableval" -a "$enableval" != "yes"; then |
|
160 if test -z "$_MOZ_DEBUG_FLAGS_SET"; then |
|
161 MOZ_DEBUG_FLAGS=`echo $enableval | sed -e 's|\\\ | |g'` |
|
162 else |
|
163 AC_MSG_ERROR([--enable-debug-symbols flags cannot be used with --enable-debug flags]) |
|
164 fi |
|
165 fi |
|
166 else |
|
167 MOZ_DEBUG_SYMBOLS= |
|
168 fi ], |
|
169 MOZ_DEBUG_SYMBOLS=1) |
|
170 |
|
171 if test -n "$MOZ_DEBUG" -o -n "$MOZ_DEBUG_SYMBOLS"; then |
|
172 AC_DEFINE(MOZ_DEBUG_SYMBOLS) |
|
173 export MOZ_DEBUG_SYMBOLS |
|
174 fi |
|
175 |
|
176 ]) |
|
177 |
|
178 dnl A high level macro for selecting compiler options. |
|
179 AC_DEFUN([MOZ_COMPILER_OPTS], |
|
180 [ |
|
181 if test "${MOZ_PSEUDO_DERECURSE-unset}" = unset; then |
|
182 dnl Don't enable on pymake, because of bug 918652. Bug 912979 is an annoyance |
|
183 dnl with pymake, too. |
|
184 MOZ_PSEUDO_DERECURSE=no-pymake |
|
185 fi |
|
186 |
|
187 MOZ_DEBUGGING_OPTS |
|
188 MOZ_RTTI |
|
189 if test "$CLANG_CXX"; then |
|
190 ## We disable return-type-c-linkage because jsval is defined as a C++ type but is |
|
191 ## returned by C functions. This is possible because we use knowledge about the ABI |
|
192 ## to typedef it to a C type with the same layout when the headers are included |
|
193 ## from C. |
|
194 ## |
|
195 ## mismatched-tags is disabled (bug 780474) mostly because it's useless. |
|
196 ## Worse, it's not supported by gcc, so it will cause tryserver bustage |
|
197 ## without any easy way for non-Clang users to check for it. |
|
198 _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wno-unknown-warning-option -Wno-return-type-c-linkage -Wno-mismatched-tags" |
|
199 fi |
|
200 |
|
201 AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) actually is a C++ compiler]) |
|
202 AC_LANG_SAVE |
|
203 AC_LANG_CPLUSPLUS |
|
204 _SAVE_LIBS=$LIBS |
|
205 LIBS= |
|
206 AC_TRY_LINK([#include <new>], [int *foo = new int;],, |
|
207 AC_MSG_RESULT([no]) |
|
208 AC_MSG_ERROR([$CXX $CXXFLAGS $LDFLAGS failed to compile and link a simple C++ source.])) |
|
209 LIBS=$_SAVE_LIBS |
|
210 AC_LANG_RESTORE |
|
211 AC_MSG_RESULT([yes]) |
|
212 |
|
213 if test -z "$GNU_CC"; then |
|
214 case "$target" in |
|
215 *-mingw*) |
|
216 ## Warning 4099 (equivalent of mismatched-tags) is disabled (bug 780474) |
|
217 ## for the same reasons as above. |
|
218 _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -wd4099" |
|
219 esac |
|
220 fi |
|
221 |
|
222 if test -n "$DEVELOPER_OPTIONS"; then |
|
223 MOZ_FORCE_GOLD=1 |
|
224 fi |
|
225 |
|
226 MOZ_ARG_ENABLE_BOOL(gold, |
|
227 [ --enable-gold Enable GNU Gold Linker when it is not already the default], |
|
228 MOZ_FORCE_GOLD=1, |
|
229 MOZ_FORCE_GOLD= |
|
230 ) |
|
231 |
|
232 if test "$GNU_CC" -a -n "$MOZ_FORCE_GOLD"; then |
|
233 dnl if the default linker is BFD ld, check if gold is available and try to use it |
|
234 dnl for local builds only. |
|
235 if $CC -Wl,--version 2>&1 | grep -q "GNU ld"; then |
|
236 GOLD=$($CC -print-prog-name=ld.gold) |
|
237 case "$GOLD" in |
|
238 /*) |
|
239 ;; |
|
240 *) |
|
241 GOLD=$(which $GOLD) |
|
242 ;; |
|
243 esac |
|
244 if test -n "$GOLD"; then |
|
245 mkdir -p $_objdir/build/unix/gold |
|
246 rm -f $_objdir/build/unix/gold/ld |
|
247 ln -s "$GOLD" $_objdir/build/unix/gold/ld |
|
248 if $CC -B $_objdir/build/unix/gold -Wl,--version 2>&1 | grep -q "GNU gold"; then |
|
249 LDFLAGS="$LDFLAGS -B $_objdir/build/unix/gold" |
|
250 else |
|
251 rm -rf $_objdir/build/unix/gold |
|
252 fi |
|
253 fi |
|
254 fi |
|
255 fi |
|
256 |
|
257 if test "$GNU_CC"; then |
|
258 if test -z "$DEVELOPER_OPTIONS"; then |
|
259 CFLAGS="$CFLAGS -ffunction-sections -fdata-sections" |
|
260 CXXFLAGS="$CXXFLAGS -ffunction-sections -fdata-sections" |
|
261 fi |
|
262 CFLAGS="$CFLAGS -fno-math-errno" |
|
263 CXXFLAGS="$CXXFLAGS -fno-exceptions -fno-math-errno" |
|
264 fi |
|
265 |
|
266 dnl ======================================================== |
|
267 dnl = Identical Code Folding |
|
268 dnl ======================================================== |
|
269 |
|
270 MOZ_ARG_DISABLE_BOOL(icf, |
|
271 [ --disable-icf Disable Identical Code Folding], |
|
272 MOZ_DISABLE_ICF=1, |
|
273 MOZ_DISABLE_ICF= ) |
|
274 |
|
275 if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -a -z "$MOZ_DISABLE_ICF" -a -z "$DEVELOPER_OPTIONS"; then |
|
276 AC_CACHE_CHECK([whether the linker supports Identical Code Folding], |
|
277 LD_SUPPORTS_ICF, |
|
278 [echo 'int foo() {return 42;}' \ |
|
279 'int bar() {return 42;}' \ |
|
280 'int main() {return foo() - bar();}' > conftest.${ac_ext} |
|
281 # If the linker supports ICF, foo and bar symbols will have |
|
282 # the same address |
|
283 if AC_TRY_COMMAND([${CC-cc} -o conftest${ac_exeext} $LDFLAGS -Wl,--icf=safe -ffunction-sections conftest.${ac_ext} $LIBS 1>&2]) && |
|
284 test -s conftest${ac_exeext} && |
|
285 objdump -t conftest${ac_exeext} | awk changequote(<<, >>)'{a[<<$>>6] = <<$>>1} END {if (a["foo"] && (a["foo"] != a["bar"])) { exit 1 }}'changequote([, ]); then |
|
286 LD_SUPPORTS_ICF=yes |
|
287 else |
|
288 LD_SUPPORTS_ICF=no |
|
289 fi |
|
290 rm -rf conftest*]) |
|
291 if test "$LD_SUPPORTS_ICF" = yes; then |
|
292 _SAVE_LDFLAGS="$LDFLAGS -Wl,--icf=safe" |
|
293 LDFLAGS="$LDFLAGS -Wl,--icf=safe -Wl,--print-icf-sections" |
|
294 AC_TRY_LINK([], [], |
|
295 [LD_PRINT_ICF_SECTIONS=-Wl,--print-icf-sections], |
|
296 [LD_PRINT_ICF_SECTIONS=]) |
|
297 AC_SUBST([LD_PRINT_ICF_SECTIONS]) |
|
298 LDFLAGS="$_SAVE_LDFLAGS" |
|
299 fi |
|
300 fi |
|
301 |
|
302 dnl ======================================================== |
|
303 dnl = Automatically remove dead symbols |
|
304 dnl ======================================================== |
|
305 |
|
306 if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -a -z "$DEVELOPER_OPTIONS"; then |
|
307 if test -n "$MOZ_DEBUG_FLAGS"; then |
|
308 dnl See bug 670659 |
|
309 AC_CACHE_CHECK([whether removing dead symbols breaks debugging], |
|
310 GC_SECTIONS_BREAKS_DEBUG_RANGES, |
|
311 [echo 'int foo() {return 42;}' \ |
|
312 'int bar() {return 1;}' \ |
|
313 'int main() {return foo();}' > conftest.${ac_ext} |
|
314 if AC_TRY_COMMAND([${CC-cc} -o conftest.${ac_objext} $CFLAGS $MOZ_DEBUG_FLAGS -c conftest.${ac_ext} 1>&2]) && |
|
315 AC_TRY_COMMAND([${CC-cc} -o conftest${ac_exeext} $LDFLAGS $MOZ_DEBUG_FLAGS -Wl,--gc-sections conftest.${ac_objext} $LIBS 1>&2]) && |
|
316 test -s conftest${ac_exeext} -a -s conftest.${ac_objext}; then |
|
317 if test "`$PYTHON -m mozbuild.configure.check_debug_ranges conftest.${ac_objext} conftest.${ac_ext}`" = \ |
|
318 "`$PYTHON -m mozbuild.configure.check_debug_ranges conftest${ac_exeext} conftest.${ac_ext}`"; then |
|
319 GC_SECTIONS_BREAKS_DEBUG_RANGES=no |
|
320 else |
|
321 GC_SECTIONS_BREAKS_DEBUG_RANGES=yes |
|
322 fi |
|
323 else |
|
324 dnl We really don't expect to get here, but just in case |
|
325 GC_SECTIONS_BREAKS_DEBUG_RANGES="no, but it's broken in some other way" |
|
326 fi |
|
327 rm -rf conftest*]) |
|
328 if test "$GC_SECTIONS_BREAKS_DEBUG_RANGES" = no; then |
|
329 DSO_LDOPTS="$DSO_LDOPTS -Wl,--gc-sections" |
|
330 fi |
|
331 else |
|
332 DSO_LDOPTS="$DSO_LDOPTS -Wl,--gc-sections" |
|
333 fi |
|
334 fi |
|
335 ]) |
|
336 |
|
337 dnl GCC and clang will fail if given an unknown warning option like -Wfoobar. |
|
338 dnl But later versions won't fail if given an unknown negated warning option |
|
339 dnl like -Wno-foobar. So when we are check for support of negated warning |
|
340 dnl options, we actually test the positive form, but add the negated form to |
|
341 dnl the flags variable. |
|
342 |
|
343 AC_DEFUN([MOZ_C_SUPPORTS_WARNING], |
|
344 [ |
|
345 AC_CACHE_CHECK(whether the C compiler supports $1$2, $3, |
|
346 [ |
|
347 AC_LANG_SAVE |
|
348 AC_LANG_C |
|
349 _SAVE_CFLAGS="$CFLAGS" |
|
350 CFLAGS="$CFLAGS -Werror -W$2" |
|
351 AC_TRY_COMPILE([], |
|
352 [return(0);], |
|
353 $3="yes", |
|
354 $3="no") |
|
355 CFLAGS="$_SAVE_CFLAGS" |
|
356 AC_LANG_RESTORE |
|
357 ]) |
|
358 if test "${$3}" = "yes"; then |
|
359 _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} $1$2" |
|
360 fi |
|
361 ]) |
|
362 |
|
363 AC_DEFUN([MOZ_CXX_SUPPORTS_WARNING], |
|
364 [ |
|
365 AC_CACHE_CHECK(whether the C++ compiler supports $1$2, $3, |
|
366 [ |
|
367 AC_LANG_SAVE |
|
368 AC_LANG_CPLUSPLUS |
|
369 _SAVE_CXXFLAGS="$CXXFLAGS" |
|
370 CXXFLAGS="$CXXFLAGS -Werror -W$2" |
|
371 AC_TRY_COMPILE([], |
|
372 [return(0);], |
|
373 $3="yes", |
|
374 $3="no") |
|
375 CXXFLAGS="$_SAVE_CXXFLAGS" |
|
376 AC_LANG_RESTORE |
|
377 ]) |
|
378 if test "${$3}" = "yes"; then |
|
379 _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} $1$2" |
|
380 fi |
|
381 ]) |