Bug 1865597 - Add error checking when initializing parallel marking and disable on...
[gecko.git] / js / src / old-configure.in
blobe069adb6a876f8fbeddcdc6a5be2783e922c3653
1 dnl -*- Mode: Autoconf; tab-width: 4; indent-tabs-mode: nil; -*-
2 dnl vi: set tabstop=4 shiftwidth=4 expandtab syntax=m4:
3 dnl This Source Code Form is subject to the terms of the Mozilla Public
4 dnl License, v. 2.0. If a copy of the MPL was not distributed with this
5 dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 dnl Process this file with autoconf to produce a configure script.
8 dnl ========================================================
9 AC_PREREQ(2.13)
10 AC_INIT(js/src/jsapi.h)
11 AC_CONFIG_AUX_DIR(${srcdir}/build/autoconf)
12 AC_CANONICAL_SYSTEM
14 dnl ========================================================
15 dnl =
16 dnl = Don't change the following lines. Doing so breaks:
17 dnl =
18 dnl = CFLAGS="-foo" ./configure
19 dnl =
20 dnl ========================================================
21 CFLAGS="${CFLAGS=}"
22 CPPFLAGS="${CPPFLAGS=}"
23 CXXFLAGS="${CXXFLAGS=}"
24 LDFLAGS="${LDFLAGS=}"
25 HOST_CFLAGS="${HOST_CFLAGS=}"
26 HOST_CXXFLAGS="${HOST_CXXFLAGS=}"
27 HOST_LDFLAGS="${HOST_LDFLAGS=}"
29 dnl Set the minimum version of toolkit libs used by mozilla
30 dnl ========================================================
31 W32API_VERSION=3.14
33 dnl Set various checks
34 dnl ========================================================
35 MISSING_X=
37 dnl Initialize the Pthread test variables early so they can be
38 dnl  overridden by each platform.
39 dnl ========================================================
40 USE_PTHREADS=
41 _PTHREAD_LDFLAGS=""
43 LDFLAGS="$LDFLAGS $LINKER_LDFLAGS $PACK_REL_RELOC_FLAGS"
44 HOST_LDFLAGS="$HOST_LDFLAGS $HOST_LINKER_LDFLAGS"
46 if test -z "$JS_STANDALONE"; then
47   autoconfmk=autoconf-js.mk
49 AC_SUBST(autoconfmk)
51 jsconfdefs=$_objdir/js/src/js-confdefs.h
53 MOZ_ANDROID_NDK
55 dnl ========================================================
56 dnl Checks for compilers.
57 dnl ========================================================
59 if test "$COMPILE_ENVIRONMENT"; then
61 # Run some logic to figure out exe extensions (mostly for mingw's sake)
62 AC_EXEEXT
64 # Note:
65 #   In Mozilla, we use the names $target, $host and $build incorrectly, but are
66 #   too far gone to back out now. See Bug 475488:
67 #     - When we say $target, we mean $host, that is, the system on which
68 #       Mozilla will be run.
69 #     - When we say $host, we mean $build, that is, the system on which Mozilla
70 #       is built.
71 #     - $target (in its correct usage) is for compilers who generate code for a
72 #       different platform than $host, so it would not be used by Mozilla.
73 if test "$target" != "$host"; then
74     MOZ_CROSS_COMPILER
75 else
76     AC_PROG_CC
77     AC_PROG_CXX
80 MOZ_TOOL_VARIABLES
82 dnl Special win32 checks
83 dnl ========================================================
85 WINVER=0A00
87 case "$target" in
88 *-mingw*)
89     if test "$GCC" != "yes"; then
90         # Check to see if we are really running in a msvc environemnt
91         _WIN32_MSVC=1
93         # Make sure compilers are valid
94         CXXFLAGS="$CXXFLAGS -TP"
95         # _CRT_SECURE_NO_WARNINGS disables warnings about using MSVC-specific
96         # secure CRT functions.
97         CXXFLAGS="$CXXFLAGS -D_CRT_SECURE_NO_WARNINGS"
98         AC_LANG_SAVE
99         AC_LANG_C
100         AC_TRY_COMPILE([#include <stdio.h>],
101             [ printf("Hello World\n"); ],,
102             AC_MSG_ERROR([\$(CC) test failed.  You must have MS VC++ in your path to build.]) )
104         AC_LANG_CPLUSPLUS
105         AC_TRY_COMPILE([#include <new.h>],
106             [ unsigned *test = new unsigned(42); ],,
107             AC_MSG_ERROR([\$(CXX) test failed.  You must have MS VC++ in your path to build.]) )
108         AC_LANG_RESTORE
110         AC_DEFINE(_CRT_SECURE_NO_WARNINGS)
111         AC_DEFINE(_CRT_NONSTDC_NO_WARNINGS)
113         MSVC_C_RUNTIME_DLL=vcruntime140.dll
114         if test -n "$IS_VS2019_OR_MORE" -a "$CPU_ARCH" != "x86"; then
115             MSVC_C_RUNTIME_1_DLL=vcruntime140_1.dll
116         fi
117         MSVC_CXX_RUNTIME_DLL=msvcp140.dll
119         # -Zc:sizedDealloc- disables C++14 global sized deallocation (see bug 1160146)
120         CXXFLAGS="$CXXFLAGS -Zc:sizedDealloc-"
122         AC_SUBST(MSVC_C_RUNTIME_DLL)
123         AC_SUBST(MSVC_C_RUNTIME_1_DLL)
124         AC_SUBST(MSVC_CXX_RUNTIME_DLL)
126         CFLAGS="$CFLAGS -D_HAS_EXCEPTIONS=0"
127         CXXFLAGS="$CXXFLAGS -D_HAS_EXCEPTIONS=0"
128     else
129         # Check w32api version
130         _W32API_MAJOR_VERSION=`echo $W32API_VERSION | $AWK -F\. '{ print $1 }'`
131         _W32API_MINOR_VERSION=`echo $W32API_VERSION | $AWK -F\. '{ print $2 }'`
132         AC_MSG_CHECKING([for w32api version >= $W32API_VERSION])
133         AC_TRY_COMPILE([#include <w32api.h>],
134             #if (__W32API_MAJOR_VERSION < $_W32API_MAJOR_VERSION) || \
135                 (__W32API_MAJOR_VERSION == $_W32API_MAJOR_VERSION && \
136                  __W32API_MINOR_VERSION < $_W32API_MINOR_VERSION)
137                 #error "test failed."
138             #endif
139             , [ res=yes ], [ res=no ])
140         AC_MSG_RESULT([$res])
141         if test "$res" != "yes"; then
142             AC_MSG_ERROR([w32api version $W32API_VERSION or higher required.])
143         fi
144     fi # !GNU_CC
146     AC_DEFINE(_USE_MATH_DEFINES) # Otherwise Windows' math.h doesn't #define M_PI.
148     AC_DEFINE_UNQUOTED(WINVER,0x$WINVER)
149     AC_DEFINE_UNQUOTED(_WIN32_WINNT,0x$WINVER)
150     AC_DEFINE_UNQUOTED(_WIN32_IE,0x0A00)
152     ;;
153 esac
155 if test -n "$_WIN32_MSVC"; then
156     SKIP_PATH_CHECKS=1
157     SKIP_COMPILER_CHECKS=1
158     SKIP_LIBRARY_CHECKS=1
161 fi # COMPILE_ENVIRONMENT
163 AC_SUBST(GNU_CC)
164 AC_SUBST(GNU_CXX)
166 dnl ========================================================
167 dnl set the defaults first
168 dnl ========================================================
169 MOZ_FIX_LINK_PATHS="-Wl,-rpath-link,${DIST}/bin -Wl,-rpath-link,${prefix}/lib"
171 dnl Configure platform-specific CPU architecture compiler options.
172 dnl ==============================================================
173 MOZ_ARCH_OPTS
175 MOZ_CONFIG_SANITIZE
177 dnl ========================================================
178 dnl GNU specific defaults
179 dnl ========================================================
180 if test "$GNU_CC"; then
181     DSO_LDOPTS='-shared'
182     if test "$GCC_USE_GNU_LD"; then
183         # Some tools like ASan use a runtime library that is only
184         # linked against executables, so we must allow undefined
185         # symbols for shared objects in some cases.
186         if test -z "$MOZ_ASAN$MOZ_MSAN$MOZ_UBSAN$MOZ_TSAN$FUZZING_INTERFACES"; then
187             # Don't allow undefined symbols in libraries
188             DSO_LDOPTS="$DSO_LDOPTS -Wl,-z,defs"
189         fi
190     fi
192     if test "$OS_ARCH" != "WINNT"; then
193         DSO_PIC_CFLAGS='-fPIC'
194         ASFLAGS="$ASFLAGS -fPIC"
195     fi
197     AC_MSG_CHECKING([for --noexecstack option to as])
198     _SAVE_CFLAGS=$CFLAGS
199     CFLAGS="$CFLAGS -Wa,--noexecstack"
200     AC_TRY_COMPILE(,,AC_MSG_RESULT([yes])
201                      [ASFLAGS="$ASFLAGS -Wa,--noexecstack"],
202                      AC_MSG_RESULT([no]))
203     CFLAGS=$_SAVE_CFLAGS
204     AC_MSG_CHECKING([for -z noexecstack option to ld])
205     _SAVE_LDFLAGS=$LDFLAGS
206     LDFLAGS="$LDFLAGS -Wl,-z,noexecstack"
207     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
208                   AC_MSG_RESULT([no])
209                   LDFLAGS=$_SAVE_LDFLAGS)
211     AC_MSG_CHECKING([for -z text option to ld])
212     _SAVE_LDFLAGS=$LDFLAGS
213     LDFLAGS="$LDFLAGS -Wl,-z,text"
214     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
215                   AC_MSG_RESULT([no])
216                   LDFLAGS=$_SAVE_LDFLAGS)
218     AC_MSG_CHECKING([for -z relro option to ld])
219     _SAVE_LDFLAGS=$LDFLAGS
220     LDFLAGS="$LDFLAGS -Wl,-z,relro"
221     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
222                   AC_MSG_RESULT([no])
223                   LDFLAGS=$_SAVE_LDFLAGS)
225     AC_MSG_CHECKING([for -z nocopyreloc option to ld])
226     _SAVE_LDFLAGS=$LDFLAGS
227     LDFLAGS="$LDFLAGS -Wl,-z,nocopyreloc"
228     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
229                   AC_MSG_RESULT([no])
230                   LDFLAGS=$_SAVE_LDFLAGS)
232     AC_MSG_CHECKING([for -Bsymbolic-functions option to ld])
233     _SAVE_LDFLAGS=$LDFLAGS
234     LDFLAGS="$LDFLAGS -Wl,-Bsymbolic-functions"
235     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
236                   AC_MSG_RESULT([no])
237                   LDFLAGS=$_SAVE_LDFLAGS)
239     # While sha1 is deterministic, it is slower.
240     if test -z "$DEVELOPER_OPTIONS"; then
241         build_id=sha1
242     else
243         build_id=uuid
244     fi
245     AC_MSG_CHECKING([for --build-id=$build_id option to ld])
246     _SAVE_LDFLAGS=$LDFLAGS
247     LDFLAGS="$LDFLAGS -Wl,--build-id=$build_id"
248     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
249                   AC_MSG_RESULT([no])
250                   LDFLAGS=$_SAVE_LDFLAGS)
252     _DEFINES_CFLAGS="-include $jsconfdefs -DMOZILLA_CLIENT"
255 if test "$GNU_CXX"; then
256     _DEFINES_CXXFLAGS="-DMOZILLA_CLIENT -include $jsconfdefs"
259 dnl ========================================================
260 dnl System overrides of the defaults for host
261 dnl ========================================================
262 case "$host" in
263 *mingw*)
264     if test -n "$_WIN32_MSVC"; then
265         HOST_CFLAGS="$HOST_CFLAGS"
266     else
267         HOST_CFLAGS="$HOST_CFLAGS -mwindows"
268     fi
269     HOST_CFLAGS="$HOST_CFLAGS -DXP_WIN -DWIN32 -D_WIN32 -D_CRT_SECURE_NO_WARNINGS"
270     HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O2}"
271     HOST_BIN_SUFFIX=.exe
273     case "${host_cpu}" in
274     i*86)
275         if test -n "$_WIN32_MSVC"; then
276             HOST_LDFLAGS="$HOST_LDFLAGS -MACHINE:X86"
277         fi
278         ;;
279     x86_64)
280         if test -n "$_WIN32_MSVC"; then
281             HOST_LDFLAGS="$HOST_LDFLAGS -MACHINE:X64"
282         fi
283         HOST_CFLAGS="$HOST_CFLAGS -D_AMD64_"
284         ;;
285     esac
286     ;;
288 *-darwin*)
289     HOST_CFLAGS="$HOST_CFLAGS -DXP_UNIX -DXP_MACOSX"
290     HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O3}"
291     ;;
293 *-linux*|*-kfreebsd*-gnu|*-gnu*)
294     HOST_CFLAGS="$HOST_CFLAGS -DXP_UNIX"
295     HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O3}"
296     ;;
299     HOST_CFLAGS="$HOST_CFLAGS -DXP_UNIX"
300     HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O2}"
301     ;;
302 esac
304 dnl ========================================================
305 dnl System overrides of the defaults for target
306 dnl ========================================================
308 case "$target" in
309 *-darwin*)
310     MOZ_OPTIMIZE_FLAGS="-O3"
311     DSO_LDOPTS=''
313     dnl DTrace and -dead_strip don't interact well. See bug 403132.
314     dnl ===================================================================
315     if test "x$enable_dtrace" = "xyes"; then
316         echo "Skipping -dead_strip because DTrace is enabled. See bug 403132."
317     else
318         dnl check for the presence of the -dead_strip linker flag
319         AC_MSG_CHECKING([for -dead_strip option to ld])
320         _SAVE_LDFLAGS=$LDFLAGS
321         LDFLAGS="$LDFLAGS -Wl,-dead_strip"
322         AC_TRY_LINK(,[return 0;],_HAVE_DEAD_STRIP=1,_HAVE_DEAD_STRIP=)
323         if test -n "$_HAVE_DEAD_STRIP" ; then
324             AC_MSG_RESULT([yes])
325             MOZ_OPTIMIZE_LDFLAGS="-Wl,-dead_strip"
326         else
327             AC_MSG_RESULT([no])
328         fi
330         LDFLAGS=$_SAVE_LDFLAGS
331     fi
332     MOZ_FIX_LINK_PATHS=
333     ;;
335 *-android*|*-linuxandroid*)
336     MOZ_OPTIMIZE_FLAGS="-O3"
337     if test -z "$CLANG_CC"; then
338        MOZ_OPTIMIZE_FLAGS="-freorder-blocks -fno-reorder-functions $MOZ_OPTIMIZE_FLAGS"
339     fi
340     ;;
342 *-*linux*)
343     if test "$GNU_CC" -o "$GNU_CXX"; then
344         MOZ_PGO_OPTIMIZE_FLAGS="-O3"
345         MOZ_OPTIMIZE_FLAGS="-O3"
346         if test -z "$CLANG_CC"; then
347            MOZ_OPTIMIZE_FLAGS="-freorder-blocks $MOZ_OPTIMIZE_FLAGS"
348         fi
349     fi
351     case "${target_cpu}" in
352     alpha*)
353         CFLAGS="$CFLAGS -mieee"
354         CXXFLAGS="$CXXFLAGS -mieee"
355     ;;
356     esac
357     ;;
359 *-mingw*)
360     DSO_PIC_CFLAGS=
361     if test -n "$GNU_CC" -o -n "$CLANG_CC"; then
362         # $GNU_CC will match gcc and clang; while $CLANG_CC will match only clang
363         if test -z "$CLANG_CC"; then
364             AC_MSG_ERROR(Firefox cannot be built with mingw-gcc and requires a mingw-clang toolchain to work)
365         fi
367         DSO_LDOPTS='-shared'
368         MOZ_FIX_LINK_PATHS=
370         # Silence problematic clang warnings
371         CXXFLAGS="$CXXFLAGS -Wno-incompatible-ms-struct"
372         LDFLAGS="$LDFLAGS -Wl,--no-insert-timestamp"
374         MOZ_OPTIMIZE_FLAGS="-O2"
376         WIN32_CONSOLE_EXE_LDFLAGS=-mconsole
377         WIN32_GUI_EXE_LDFLAGS=-mwindows
378     else
379         TARGET_COMPILER_ABI=msvc
380         WIN32_SUBSYSTEM_VERSION=10.0
381         WIN32_CONSOLE_EXE_LDFLAGS=-SUBSYSTEM:CONSOLE,$WIN32_SUBSYSTEM_VERSION
382         WIN32_GUI_EXE_LDFLAGS=-SUBSYSTEM:WINDOWS,$WIN32_SUBSYSTEM_VERSION
383         DSO_LDOPTS=-SUBSYSTEM:WINDOWS,$WIN32_SUBSYSTEM_VERSION
384         _DEFINES_CFLAGS="-FI $jsconfdefs -DMOZILLA_CLIENT"
385         _DEFINES_CXXFLAGS="-FI $jsconfdefs -DMOZILLA_CLIENT"
386         CFLAGS="$CFLAGS -Gy -Zc:inline"
387         CXXFLAGS="$CXXFLAGS -Gy -Zc:inline"
388         if test "$CPU_ARCH" = "x86";then
389           dnl VS2012+ defaults to -arch:SSE2. We want to target nothing
390           dnl more recent, so set that explicitly here unless another
391           dnl target arch has already been set.
392           changequote(,)
393           if test -z `echo $CFLAGS | grep -i [-/]arch:` ; then
394             CFLAGS="$CFLAGS -arch:SSE2"
395           fi
396           if test -z `echo $CXXFLAGS | grep -i [-/]arch:` ; then
397             CXXFLAGS="$CXXFLAGS -arch:SSE2"
398           fi
399           changequote([,])
400         fi
401         dnl VS2013+ supports -Gw for better linker optimizations.
402         dnl http://blogs.msdn.com/b/vcblog/archive/2013/09/11/introducing-gw-compiler-switch.aspx
403         dnl Disabled on ASan because it causes false-positive ODR violations.
404         if test -z "$MOZ_ASAN"; then
405             CFLAGS="$CFLAGS -Gw"
406             CXXFLAGS="$CXXFLAGS -Gw"
407         else
408             # String tail merging doesn't play nice with ASan's ODR checker.
409             LDFLAGS="$LDFLAGS -opt:nolldtailmerge"
410         fi
411         MOZ_DEBUG_LDFLAGS='-DEBUG'
412         if test "$HOST_OS_ARCH" != "WINNT"; then
413           # %_PDB% is a special signal to emit only the PDB basename. This
414           # avoids problems in Windows tools that don't like forward-slashes.
415           MOZ_DEBUG_LDFLAGS="$MOZ_DEBUG_LDFLAGS -PDBALTPATH:%_PDB%"
416         fi
417         MOZ_OPTIMIZE_FLAGS="-O2"
418         MOZ_FIX_LINK_PATHS=
419         LDFLAGS="$LDFLAGS -LARGEADDRESSAWARE"
420     fi
421     AC_DEFINE(HAVE__MSIZE)
422     AC_DEFINE(WIN32_LEAN_AND_MEAN)
423     dnl See http://support.microsoft.com/kb/143208 to use STL
424     AC_DEFINE(NOMINMAX)
425     BIN_SUFFIX='.exe'
427     case "$host_os" in
428     cygwin*|msvc*|mks*)
429         AC_MSG_ERROR([Using a Cygwin build environment is unsupported. Configure cannot check for presence of necessary headers. Please upgrade to MozillaBuild; see https://developer.mozilla.org/en/Windows_Build_Prerequisites.])
430         ;;
431     esac
433     case "$target" in
434     i*86-*)
435         if test -n "$GNU_CC"; then
436             CFLAGS="$CFLAGS -mstackrealign"
437             CXXFLAGS="$CXXFLAGS -mstackrealign"
438             LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
439         else
440             DSO_LDOPTS="$DSO_LDOPTS -MACHINE:X86"
441             LDFLAGS="$LDFLAGS -SAFESEH"
442         fi
444         AC_DEFINE(_X86_)
445         ;;
446     x86_64-*)
447         if test -n "$_WIN32_MSVC"; then
448             DSO_LDOPTS="$DSO_LDOPTS -MACHINE:X64"
449         fi
450         AC_DEFINE(_AMD64_)
451         ;;
452     aarch64-*)
453         if test -n "$_WIN32_MSVC"; then
454             DSO_LDOPTS="$DSO_LDOPTS -MACHINE:ARM64"
455         fi
456         AC_DEFINE(_ARM64_)
457         ;;
458     *)
459         AC_DEFINE(_CPU_ARCH_NOT_DEFINED)
460         ;;
461     esac
462     ;;
464 *-netbsd*)
465     CFLAGS="$CFLAGS -Dunix"
466     CXXFLAGS="$CXXFLAGS -Dunix"
467     if $CC -E - -dM </dev/null | grep __ELF__ >/dev/null; then
468         DSO_PIC_CFLAGS='-fPIC -DPIC'
469         DSO_LDOPTS='-shared'
470         MOZ_PROGRAM_LDFLAGS="$MOZ_PROGRAM_LDFLAGS -Wl,--export-dynamic"
471     else
472         DSO_PIC_CFLAGS='-fPIC -DPIC'
473         DSO_LDOPTS='-shared'
474     fi
475     # This will fail on a.out systems prior to 1.5.1_ALPHA.
476     if test "$LIBRUNPATH"; then
477         DSO_LDOPTS="-Wl,-R$LIBRUNPATH $DSO_LDOPTS"
478     fi
479     ;;
481 *-openbsd*)
482     DSO_PIC_CFLAGS='-fPIC'
483     DSO_LDOPTS='-shared -fPIC'
484     if test "$LIBRUNPATH"; then
485         DSO_LDOPTS="-R$LIBRUNPATH $DSO_LDOPTS"
486     fi
487     ;;
489 *-solaris*)
490     MOZ_FIX_LINK_PATHS="-L${DIST}/bin"
491     ;;
493 *-wasi*)
494     CXXFLAGS="$CXXFLAGS -mthread-model single"
495     MOZ_FIX_LINK_PATHS=
496     ;;
498 esac
500 CFLAGS="$CFLAGS $DSO_PIC_CFLAGS"
501 CXXFLAGS="$CXXFLAGS $DSO_PIC_CFLAGS"
503 if test -z "$MOZ_OPTIMIZE_FLAGS"; then
504         MOZ_OPTIMIZE_FLAGS="-O"
507 if test -z "$COMPILE_ENVIRONMENT"; then
508     SKIP_COMPILER_CHECKS=1
509     SKIP_LIBRARY_CHECKS=1
512 if test -n "$COMPILE_ENVIRONMENT"; then
513     MOZ_COMPILER_OPTS
516 if test -z "$SKIP_COMPILER_CHECKS"; then
517 dnl Checks for typedefs, structures, and compiler characteristics.
518 dnl ========================================================
519 AC_C_CONST
520 AC_TYPE_MODE_T
521 AC_TYPE_OFF_T
522 AC_TYPE_PID_T
523 AC_TYPE_SIZE_T
524 AC_LANG_CPLUSPLUS
525 AC_LANG_C
526 AC_MSG_CHECKING(for ssize_t)
527 AC_CACHE_VAL(ac_cv_type_ssize_t,
528  [AC_TRY_COMPILE([#include <stdio.h>
529                   #include <sys/types.h>],
530                  [ssize_t foo = 0;],
531                  [ac_cv_type_ssize_t=true],
532                  [ac_cv_type_ssize_t=false])])
533 if test "$ac_cv_type_ssize_t" = true ; then
534   AC_DEFINE(HAVE_SSIZE_T)
535   AC_MSG_RESULT(yes)
536 else
537   AC_MSG_RESULT(no)
540 AC_LANG_CPLUSPLUS
542 MOZ_CXX11
544 dnl Checks for header files.
545 dnl ========================================================
546 AC_HEADER_DIRENT
548 dnl Checks for libraries.
549 dnl ========================================================
550 AC_CHECK_LIB(c_r, gethostbyname_r)
552 dnl We don't want to link with libdl even if it's present on OS X, since
553 dnl it's not used and not part of the default installation. OS/2 has dlfcn
554 dnl in libc.
555 dnl We don't want to link against libm or libpthread on Darwin since
556 dnl they both are just symlinks to libSystem and explicitly linking
557 dnl against libSystem causes issues when debugging (see bug 299601).
558 case $target in
559 *-darwin*)
560     ;;
562     AC_SEARCH_LIBS(dlopen, dl,
563         MOZ_CHECK_HEADER(dlfcn.h,
564         AC_DEFINE(HAVE_DLOPEN)))
565     ;;
566 esac
568 _SAVE_CFLAGS="$CFLAGS"
569 CFLAGS="$CFLAGS -D_GNU_SOURCE"
570 AC_CHECK_FUNCS(dladdr)
571 CFLAGS="$_SAVE_CFLAGS"
573 if test ! "$GNU_CXX"; then
574     AC_CHECK_LIB(C, demangle)
577 AC_CHECK_LIB(socket, socket)
579 dnl ========================================================
580 dnl = pthread support
581 dnl = Start by checking whether the system support pthreads
582 dnl ========================================================
583 case "$target_os" in
584 darwin*)
585     USE_PTHREADS=1
586     ;;
588     AC_CHECK_LIB(pthreads, pthread_create,
589         USE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads",
590         AC_CHECK_LIB(pthread, pthread_create,
591             USE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread",
592             AC_CHECK_LIB(c_r, pthread_create,
593                 USE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r",
594                 AC_CHECK_LIB(c, pthread_create,
595                     USE_PTHREADS=1
596                 )
597             )
598         )
599     )
600     ;;
601 esac
603 dnl ========================================================
604 dnl Do the platform specific pthread hackery
605 dnl ========================================================
606 if test "$USE_PTHREADS"x != x
607 then
608         dnl
609         dnl See if -pthread is supported.
610         dnl
611         rm -f conftest*
612         ac_cv_have_dash_pthread=no
613         AC_MSG_CHECKING(whether ${CC-cc} accepts -pthread)
614         echo 'int main() { return 0; }' | cat > conftest.c
615         ${CC-cc} -pthread -o conftest conftest.c > conftest.out 2>&1
616         if test $? -eq 0; then
617                 if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthread`" -a -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
618                         ac_cv_have_dash_pthread=yes
619                 case "$target_os" in
620                 freebsd*)
621 # Freebsd doesn't use -pthread for compiles, it uses them for linking
622                 ;;
623                 *)
624                             CFLAGS="$CFLAGS -pthread"
625                             CXXFLAGS="$CXXFLAGS -pthread"
626                 ;;
627                 esac
628                 fi
629         fi
630         rm -f conftest*
631     AC_MSG_RESULT($ac_cv_have_dash_pthread)
633         dnl
634         dnl See if -pthreads is supported.
635         dnl
636     ac_cv_have_dash_pthreads=no
637     if test "$ac_cv_have_dash_pthread" = "no"; then
638             AC_MSG_CHECKING(whether ${CC-cc} accepts -pthreads)
639         echo 'int main() { return 0; }' | cat > conftest.c
640             ${CC-cc} -pthreads -o conftest conftest.c > conftest.out 2>&1
641         if test $? -eq 0; then
642                 if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthreads`" -a -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
643                             ac_cv_have_dash_pthreads=yes
644                             CFLAGS="$CFLAGS -pthreads"
645                             CXXFLAGS="$CXXFLAGS -pthreads"
646                     fi
647             fi
648             rm -f conftest*
649         AC_MSG_RESULT($ac_cv_have_dash_pthreads)
650     fi
652         case "$target" in
653             *-*-freebsd*)
654                         AC_DEFINE(_REENTRANT)
655                         AC_DEFINE(_THREAD_SAFE)
656                         dnl -pthread links in -lpthread, so don't specify it explicitly.
657                         if test "$ac_cv_have_dash_pthread" = "yes"; then
658                                 _PTHREAD_LDFLAGS="-pthread"
659                         fi
660                         ;;
662             *-*-openbsd*|*-*-bsdi*)
663                         AC_DEFINE(_REENTRANT)
664                         AC_DEFINE(_THREAD_SAFE)
665                         dnl -pthread links in -lc_r, so don't specify it explicitly.
666                         if test "$ac_cv_have_dash_pthread" = "yes"; then
667                 _PTHREAD_LDFLAGS="-pthread"
668                         fi
669                         ;;
671             *-*-linux*|*-*-kfreebsd*-gnu|*-*-gnu*)
672                         AC_DEFINE(_REENTRANT)
673                         ;;
675         esac
676     LDFLAGS="${_PTHREAD_LDFLAGS} ${LDFLAGS}"
680 dnl Checks for library functions.
681 dnl ========================================================
683 dnl check for clock_gettime(), the CLOCK_MONOTONIC clock
684 AC_CACHE_CHECK(for clock_gettime(CLOCK_MONOTONIC),
685                ac_cv_clock_monotonic,
686                [for libs in "" -lrt; do
687                     _SAVE_LIBS="$LIBS"
688                     LIBS="$LIBS $libs"
689 dnl clock_gettime is available on OSX since 10.12, so depending on MACOSX_DEPLOYMENT_TARGET,
690 dnl we should or not be able to use it. To detect if we can, we need to make the
691 dnl availability attribute strict, so that compilation fails when the target is < 10.12.
692                     AC_TRY_LINK([#define availability(os, ...) availability(os, strict, __VA_ARGS)
693                                  #include <time.h>],
694                                  [ struct timespec ts;
695                                    clock_gettime(CLOCK_MONOTONIC, &ts); ],
696                                  ac_cv_clock_monotonic=$libs
697                                  LIBS="$_SAVE_LIBS"
698                                  break,
699                                  ac_cv_clock_monotonic=no)
700                     LIBS="$_SAVE_LIBS"
701                 done])
702 if test "$ac_cv_clock_monotonic" != "no"; then
703     HAVE_CLOCK_MONOTONIC=1
704     REALTIME_LIBS=$ac_cv_clock_monotonic
705     AC_DEFINE(HAVE_CLOCK_MONOTONIC)
706     AC_SUBST(HAVE_CLOCK_MONOTONIC)
707     AC_SUBST_LIST(REALTIME_LIBS)
710 dnl Checks for math functions.
711 dnl ========================================================
712 AC_CHECK_LIB(m, sin)
714 AC_CACHE_CHECK(
715     [for res_ninit()],
716     ac_cv_func_res_ninit,
717     [if test "$OS_TARGET" = NetBSD -o "$OS_TARGET" = OpenBSD; then
718         dnl no need for res_ninit() on NetBSD and OpenBSD
719         ac_cv_func_res_ninit=no
720      else
721        AC_TRY_LINK([
722             #ifdef linux
723             #define _BSD_SOURCE 1
724             #endif
725             #include <sys/types.h>
726             #include <netinet/in.h>
727             #include <arpa/nameser.h>
728             #include <resolv.h>
729             ],
730             [int foo = res_ninit(&_res);],
731             [ac_cv_func_res_ninit=yes],
732             [ac_cv_func_res_ninit=no])
733      fi
734     ])
736 if test "$ac_cv_func_res_ninit" = "yes"; then
737     AC_DEFINE(HAVE_RES_NINIT)
738 dnl must add the link line we do something as foolish as this... dougt
739 dnl else
740 dnl    AC_CHECK_LIB(bind, res_ninit, AC_DEFINE(HAVE_RES_NINIT),
741 dnl        AC_CHECK_LIB(resolv, res_ninit, AC_DEFINE(HAVE_RES_NINIT)))
744 AM_LANGINFO_CODESET
746 AC_LANG_C
748 dnl ===================================================================
749 dnl ========================================================
750 dnl Put your C++ language/feature checks below
751 dnl ========================================================
752 AC_LANG_CPLUSPLUS
754 ARM_ABI_PREFIX=
755 if test "$GNU_CC"; then
756   if test "$CPU_ARCH" = "arm" ; then
757     AC_CACHE_CHECK(for ARM EABI,
758         ac_cv_gcc_arm_eabi,
759         [AC_TRY_COMPILE([],
760                         [
761 #if defined(__ARM_EABI__)
762   return 0;
763 #else
764 #error Not ARM EABI.
765 #endif
766                         ],
767                         ac_cv_gcc_arm_eabi="yes",
768                         ac_cv_gcc_arm_eabi="no")])
769     if test "$ac_cv_gcc_arm_eabi" = "yes"; then
770         HAVE_ARM_EABI=1
771         ARM_ABI_PREFIX=eabi-
772     else
773         ARM_ABI_PREFIX=oabi-
774     fi
775   fi
777   TARGET_COMPILER_ABI="${TARGET_COMPILER_ABI-${ARM_ABI_PREFIX}gcc3}"
780 # try harder, when checking for __thread support, see bug 521750 comment #33 and below
781 # We pass MOZ_OPTIMIZE_LDFLAGS to the linker because if dead_strip is
782 # enabled, the linker in xcode 4.1 will crash. Without this it would crash when
783 # linking XUL.
784 _SAVE_LDFLAGS=$LDFLAGS
785 LDFLAGS="$LDFLAGS $DSO_LDOPTS $MOZ_OPTIMIZE_LDFLAGS"
786 AC_CACHE_CHECK(for __thread keyword for TLS variables,
787                ac_cv_thread_keyword,
788                [AC_TRY_LINK([__thread bool tlsIsMainThread = false;],
789                             [return tlsIsMainThread;],
790                             ac_cv_thread_keyword=yes,
791                             ac_cv_thread_keyword=no)])
792 LDFLAGS=$_SAVE_LDFLAGS
793 if test "$ac_cv_thread_keyword" = yes; then
794   # mips builds fail with TLS variables because of a binutils bug.
795   # See bug 528687
796   case "${target}" in
797     mips*-*)
798       :
799       ;;
800     *-android*|*-linuxandroid*)
801       :
802       ;;
803     *)
804       AC_DEFINE(HAVE_THREAD_TLS_KEYWORD)
805       ;;
806   esac
809 dnl End of C++ language/feature checks
810 AC_LANG_C
812 fi # ! SKIP_COMPILER_CHECKS
814 TARGET_XPCOM_ABI=
815 if test -n "${CPU_ARCH}" -a -n "${TARGET_COMPILER_ABI}"; then
816     TARGET_XPCOM_ABI="${CPU_ARCH}-${TARGET_COMPILER_ABI}"
819 dnl We can't run TRY_COMPILE tests on Windows, so hard-code some
820 dnl features that Windows actually does support.
822 if test -n "$SKIP_COMPILER_CHECKS"; then
823    dnl Windows has malloc.h
824    AC_DEFINE(MALLOC_H, [<malloc.h>])
825    AC_DEFINE(HAVE_FORCEINLINE)
826 fi # SKIP_COMPILER_CHECKS
828 dnl Mozilla specific options
829 dnl ========================================================
830 dnl The macros used for command line options
831 dnl are defined in build/autoconf/altoptions.m4.
833 dnl ========================================================
834 dnl = Enable code optimization. ON by default.
835 dnl ========================================================
837 # Use value from moz.configure if one is defined. Else use our computed
838 # value.
839 if test -n "${MOZ_CONFIGURE_OPTIMIZE_FLAGS}"; then
840     MOZ_OPTIMIZE_FLAGS=${MOZ_CONFIGURE_OPTIMIZE_FLAGS}
843 if test "$COMPILE_ENVIRONMENT"; then
844 if test -n "$MOZ_OPTIMIZE"; then
845     AC_MSG_CHECKING([for valid optimization flags])
846     _SAVE_CFLAGS=$CFLAGS
847     CFLAGS="$CFLAGS $MOZ_OPTIMIZE_FLAGS"
848     AC_TRY_COMPILE([#include <stdio.h>],
849         [printf("Hello World\n");],
850         _results=yes,
851         _results=no)
852     AC_MSG_RESULT([$_results])
853     if test "$_results" = "no"; then
854         AC_MSG_ERROR([These compiler flags are invalid: $MOZ_OPTIMIZE_FLAGS])
855     fi
856     CFLAGS=$_SAVE_CFLAGS
857     if test -n "$MOZ_LTO" -a -n "$CLANG_CC"; then
858         # When using llvm-based LTO, non numeric optimization levels are
859         # not supported by the linker, so force the linker to use -O2 (
860         # which doesn't influence the level compilation units are actually
861         # compiled at).
862         case " $MOZ_OPTIMIZE_FLAGS " in
863         *\ -Os\ *|*\ -Oz\ *)
864             MOZ_OPTIMIZE_LDFLAGS="$MOZ_OPTIMIZE_LDFLAGS -O2"
865             ;;
866         esac
867     fi
869 fi # COMPILE_ENVIRONMENT
871 AC_SUBST_LIST(MOZ_OPTIMIZE_FLAGS)
872 AC_SUBST_LIST(MOZ_OPTIMIZE_LDFLAGS)
873 AC_SUBST_LIST(MOZ_PGO_OPTIMIZE_FLAGS)
875 dnl ========================================================
876 dnl = Enable jemalloc
877 dnl ========================================================
879 if test "$JS_STANDALONE" -a -z "$MOZ_MEMORY"; then
880   MOZ_GLUE_IN_PROGRAM=
881 else
882   case "${OS_TARGET}" in
883   Android|WINNT|Darwin)
884     MOZ_GLUE_IN_PROGRAM=
885     ;;
886   *)
887     dnl On !Android !Windows !OSX, we only want to link executables against mozglue
888     MOZ_GLUE_IN_PROGRAM=1
889     AC_DEFINE(MOZ_GLUE_IN_PROGRAM)
890     ;;
891   esac
894 if test "$MOZ_MEMORY"; then
895   dnl The generic feature tests that determine how to compute ncpus are long and
896   dnl complicated.  Therefore, simply define special cpp variables for the
897   dnl platforms we have special knowledge of.
898   case "${target}" in
899   *-mingw*)
900     export MOZ_NO_DEBUG_RTL=1
901     ;;
902   esac
904 AC_SUBST(MOZ_GLUE_IN_PROGRAM)
906 dnl ========================================================
907 dnl instruments
908 dnl ========================================================
909 if test -n "$MOZ_INSTRUMENTS"; then
910     LIBS="$LIBS -framework CoreFoundation"
913 dnl ========================================================
914 dnl = Enable using the clang plugin to build
915 dnl ========================================================
917 if test -n "$COMPILE_ENVIRONMENT"; then
918 MOZ_CONFIG_CLANG_PLUGIN
919 fi # COMPILE_ENVIRONMENT
921 if test -z "$SKIP_COMPILER_CHECKS"; then
923 dnl ========================================================
924 dnl Check for gcc -pipe support
925 dnl ========================================================
926 AC_MSG_CHECKING([for -pipe support])
927 if test -n "$GNU_CC" -a -n "$GNU_CXX"; then
928     dnl Any gcc that supports firefox supports -pipe.
929     CFLAGS="$CFLAGS -pipe"
930     CXXFLAGS="$CXXFLAGS -pipe"
931     AC_MSG_RESULT([yes])
932 else
933     AC_MSG_RESULT([no])
936 fi # ! SKIP_COMPILER_CHECKS
938 MOZ_EXPAND_LIBS
940 dnl ========================================================
941 dnl =
942 dnl = Maintainer debug option (no --enable equivalent)
943 dnl =
944 dnl ========================================================
946 AC_SUBST_LIST(ASFLAGS)
947 AC_SUBST_LIST(MOZ_DEBUG_LDFLAGS)
949 AC_SUBST_LIST(MOZ_FIX_LINK_PATHS)
951 AC_SUBST(MOZ_POST_PROGRAM_COMMAND)
953 AC_SUBST(MOZ_APP_DISPLAYNAME)
955 AC_SUBST(MOZ_PKG_SPECIAL)
957 dnl Echo the CFLAGS to remove extra whitespace.
958 CFLAGS=`echo \
959         $_COMPILATION_CFLAGS \
960         $CFLAGS`
962 CXXFLAGS=`echo \
963         $_COMPILATION_CXXFLAGS \
964         $CXXFLAGS`
966 COMPILE_CFLAGS=`echo \
967     $_DEFINES_CFLAGS \
968     $COMPILE_CFLAGS`
970 COMPILE_CXXFLAGS=`echo \
971     $_DEFINES_CXXFLAGS \
972     $COMPILE_CXXFLAGS`
974 HOST_CFLAGS=`echo \
975     $_COMPILATION_HOST_CFLAGS \
976     $HOST_CFLAGS`
978 HOST_CXXFLAGS=`echo \
979     $_COMPILATION_HOST_CXXFLAGS \
980     $HOST_CXXFLAGS`
982 OS_CFLAGS="$CFLAGS"
983 OS_CXXFLAGS="$CXXFLAGS"
984 OS_CPPFLAGS="$CPPFLAGS"
985 OS_COMPILE_CFLAGS="$COMPILE_CFLAGS"
986 OS_COMPILE_CXXFLAGS="$COMPILE_CXXFLAGS"
987 OS_LDFLAGS="$LDFLAGS"
988 OS_LIBS="$LIBS"
989 AC_SUBST_LIST(OS_CFLAGS)
990 AC_SUBST_LIST(OS_CXXFLAGS)
991 AC_SUBST_LIST(OS_CPPFLAGS)
992 AC_SUBST_LIST(OS_COMPILE_CFLAGS)
993 AC_SUBST_LIST(OS_COMPILE_CXXFLAGS)
994 AC_SUBST_LIST(OS_LDFLAGS)
995 AC_SUBST(OS_LIBS)
997 AC_SUBST(HOST_CC)
998 AC_SUBST(HOST_CXX)
999 AC_SUBST_LIST(HOST_CFLAGS)
1000 AC_SUBST_LIST(HOST_CPPFLAGS)
1001 AC_SUBST_LIST(HOST_CXXFLAGS)
1002 AC_SUBST(HOST_LDFLAGS)
1003 AC_SUBST_LIST(HOST_OPTIMIZE_FLAGS)
1004 AC_SUBST(HOST_BIN_SUFFIX)
1006 AC_SUBST(TARGET_XPCOM_ABI)
1008 AC_SUBST(DSO_LDOPTS)
1009 AC_SUBST(BIN_SUFFIX)
1010 AC_SUBST(USE_N32)
1011 AC_SUBST(WIN32_CONSOLE_EXE_LDFLAGS)
1012 AC_SUBST(WIN32_GUI_EXE_LDFLAGS)
1014 dnl Set various defines and substitutions
1015 dnl ========================================================
1017 AC_SUBST(MOZ_DEV_EDITION)
1018 if test -n "$MOZ_DEV_EDITION"; then
1019     AC_DEFINE(MOZ_DEV_EDITION)
1022 dnl ========================================================
1023 dnl JavaScript shell
1024 dnl ========================================================
1026 MOZ_CHECK_ALLOCATOR
1028 if test -n "$JS_STANDALONE"; then
1029 JS_LIBRARY_NAME="mozjs-$MOZILLA_SYMBOLVERSION"
1030 else
1031 JS_LIBRARY_NAME="mozjs"
1033 JS_CONFIG_LIBS="$NSPR_LIBS $LIBS"
1034 if test -n "$GNU_CC"; then
1035 JS_CONFIG_MOZ_JS_LIBS='-L${libdir} -l${JS_LIBRARY_NAME}'
1036 else
1037 JS_CONFIG_MOZ_JS_LIBS='${libdir}/${JS_LIBRARY_NAME}.lib'
1039 AC_SUBST(JS_LIBRARY_NAME)
1040 AC_SUBST(JS_CONFIG_MOZ_JS_LIBS)
1041 AC_SUBST(JS_CONFIG_LIBS)
1043 # Avoid using obsolete NSPR features
1044 AC_DEFINE(NO_NSPR_10_SUPPORT)
1046 dnl Spit out some output
1047 dnl ========================================================
1048 MOZ_CREATE_CONFIG_STATUS()
1050 rm -fr confdefs* $ac_clean_files