Bug 1842773 - Part 30: Add support to create growable ArrayBuffers. r=sfink
[gecko.git] / js / src / old-configure.in
bloba7dca8feea4c2a4d10f30bc54f6e1adb7e54f9b6
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 "$TARGET_CPU" != "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 now option to ld])
226     _SAVE_LDFLAGS=$LDFLAGS
227     LDFLAGS="$LDFLAGS -Wl,-z,now"
228     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
229                   AC_MSG_RESULT([no])
230                   LDFLAGS=$_SAVE_LDFLAGS)
232     AC_MSG_CHECKING([for -z nocopyreloc option to ld])
233     _SAVE_LDFLAGS=$LDFLAGS
234     LDFLAGS="$LDFLAGS -Wl,-z,nocopyreloc"
235     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
236                   AC_MSG_RESULT([no])
237                   LDFLAGS=$_SAVE_LDFLAGS)
239     AC_MSG_CHECKING([for -Bsymbolic-functions option to ld])
240     _SAVE_LDFLAGS=$LDFLAGS
241     LDFLAGS="$LDFLAGS -Wl,-Bsymbolic-functions"
242     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
243                   AC_MSG_RESULT([no])
244                   LDFLAGS=$_SAVE_LDFLAGS)
246     # While sha1 is deterministic, it is slower.
247     if test -z "$DEVELOPER_OPTIONS"; then
248         build_id=sha1
249     else
250         build_id=uuid
251     fi
252     AC_MSG_CHECKING([for --build-id=$build_id option to ld])
253     _SAVE_LDFLAGS=$LDFLAGS
254     LDFLAGS="$LDFLAGS -Wl,--build-id=$build_id"
255     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
256                   AC_MSG_RESULT([no])
257                   LDFLAGS=$_SAVE_LDFLAGS)
259     _DEFINES_CFLAGS="-include $jsconfdefs -DMOZILLA_CLIENT"
262 if test "$GNU_CXX"; then
263     _DEFINES_CXXFLAGS="-DMOZILLA_CLIENT -include $jsconfdefs"
266 dnl ========================================================
267 dnl System overrides of the defaults for host
268 dnl ========================================================
269 case "$host" in
270 *mingw*)
271     if test -n "$_WIN32_MSVC"; then
272         HOST_CFLAGS="$HOST_CFLAGS"
273     else
274         HOST_CFLAGS="$HOST_CFLAGS -mwindows"
275     fi
276     HOST_CFLAGS="$HOST_CFLAGS -DXP_WIN -DWIN32 -D_WIN32 -D_CRT_SECURE_NO_WARNINGS"
277     HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O2}"
278     HOST_BIN_SUFFIX=.exe
280     case "${host_cpu}" in
281     i*86)
282         if test -n "$_WIN32_MSVC"; then
283             HOST_LDFLAGS="$HOST_LDFLAGS -MACHINE:X86"
284         fi
285         ;;
286     x86_64)
287         if test -n "$_WIN32_MSVC"; then
288             HOST_LDFLAGS="$HOST_LDFLAGS -MACHINE:X64"
289         fi
290         HOST_CFLAGS="$HOST_CFLAGS -D_AMD64_"
291         ;;
292     esac
293     ;;
295 *-darwin*)
296     HOST_CFLAGS="$HOST_CFLAGS -DXP_UNIX -DXP_MACOSX"
297     HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O3}"
298     ;;
300 *-linux*|*-kfreebsd*-gnu|*-gnu*)
301     HOST_CFLAGS="$HOST_CFLAGS -DXP_UNIX"
302     HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O3}"
303     ;;
306     HOST_CFLAGS="$HOST_CFLAGS -DXP_UNIX"
307     HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O2}"
308     ;;
309 esac
311 dnl ========================================================
312 dnl System overrides of the defaults for target
313 dnl ========================================================
315 case "$target" in
316 *-darwin*)
317     MOZ_OPTIMIZE_FLAGS="-O3"
318     DSO_LDOPTS=''
320     dnl DTrace and -dead_strip don't interact well. See bug 403132.
321     dnl ===================================================================
322     if test "x$enable_dtrace" = "xyes"; then
323         echo "Skipping -dead_strip because DTrace is enabled. See bug 403132."
324     else
325         dnl check for the presence of the -dead_strip linker flag
326         AC_MSG_CHECKING([for -dead_strip option to ld])
327         _SAVE_LDFLAGS=$LDFLAGS
328         LDFLAGS="$LDFLAGS -Wl,-dead_strip"
329         AC_TRY_LINK(,[return 0;],_HAVE_DEAD_STRIP=1,_HAVE_DEAD_STRIP=)
330         if test -n "$_HAVE_DEAD_STRIP" ; then
331             AC_MSG_RESULT([yes])
332             MOZ_OPTIMIZE_LDFLAGS="-Wl,-dead_strip"
333         else
334             AC_MSG_RESULT([no])
335         fi
337         LDFLAGS=$_SAVE_LDFLAGS
338     fi
339     MOZ_FIX_LINK_PATHS=
340     ;;
342 *-android*|*-linuxandroid*)
343     MOZ_OPTIMIZE_FLAGS="-O3"
344     if test -z "$CLANG_CC"; then
345        MOZ_OPTIMIZE_FLAGS="-fno-reorder-functions $MOZ_OPTIMIZE_FLAGS"
346     fi
347     ;;
349 *-*linux*)
350     if test "$GNU_CC" -o "$GNU_CXX"; then
351         MOZ_PGO_OPTIMIZE_FLAGS="-O3"
352         MOZ_OPTIMIZE_FLAGS="-O3"
353     fi
355     case "${target_cpu}" in
356     alpha*)
357         CFLAGS="$CFLAGS -mieee"
358         CXXFLAGS="$CXXFLAGS -mieee"
359     ;;
360     esac
361     ;;
363 *-mingw*)
364     DSO_PIC_CFLAGS=
365     if test -n "$GNU_CC" -o -n "$CLANG_CC"; then
366         # $GNU_CC will match gcc and clang; while $CLANG_CC will match only clang
367         if test -z "$CLANG_CC"; then
368             AC_MSG_ERROR(Firefox cannot be built with mingw-gcc and requires a mingw-clang toolchain to work)
369         fi
371         DSO_LDOPTS='-shared'
372         MOZ_FIX_LINK_PATHS=
374         # Silence problematic clang warnings
375         CXXFLAGS="$CXXFLAGS -Wno-incompatible-ms-struct"
376         LDFLAGS="$LDFLAGS -Wl,--no-insert-timestamp"
378         MOZ_OPTIMIZE_FLAGS="-O2"
380         WIN32_CONSOLE_EXE_LDFLAGS=-mconsole
381         WIN32_GUI_EXE_LDFLAGS=-mwindows
382     else
383         TARGET_COMPILER_ABI=msvc
384         WIN32_SUBSYSTEM_VERSION=10.0
385         WIN32_CONSOLE_EXE_LDFLAGS=-SUBSYSTEM:CONSOLE,$WIN32_SUBSYSTEM_VERSION
386         WIN32_GUI_EXE_LDFLAGS=-SUBSYSTEM:WINDOWS,$WIN32_SUBSYSTEM_VERSION
387         DSO_LDOPTS=-SUBSYSTEM:WINDOWS,$WIN32_SUBSYSTEM_VERSION
388         _DEFINES_CFLAGS="-FI $jsconfdefs -DMOZILLA_CLIENT"
389         _DEFINES_CXXFLAGS="-FI $jsconfdefs -DMOZILLA_CLIENT"
390         CFLAGS="$CFLAGS -Gy -Zc:inline"
391         CXXFLAGS="$CXXFLAGS -Gy -Zc:inline"
392         if test "$TARGET_CPU" = "x86";then
393           dnl VS2012+ defaults to -arch:SSE2. We want to target nothing
394           dnl more recent, so set that explicitly here unless another
395           dnl target arch has already been set.
396           changequote(,)
397           if test -z `echo $CFLAGS | grep -i [-/]arch:` ; then
398             CFLAGS="$CFLAGS -arch:SSE2"
399           fi
400           if test -z `echo $CXXFLAGS | grep -i [-/]arch:` ; then
401             CXXFLAGS="$CXXFLAGS -arch:SSE2"
402           fi
403           changequote([,])
404         fi
405         dnl VS2013+ supports -Gw for better linker optimizations.
406         dnl http://blogs.msdn.com/b/vcblog/archive/2013/09/11/introducing-gw-compiler-switch.aspx
407         dnl Disabled on ASan because it causes false-positive ODR violations.
408         if test -z "$MOZ_ASAN"; then
409             CFLAGS="$CFLAGS -Gw"
410             CXXFLAGS="$CXXFLAGS -Gw"
411         else
412             # String tail merging doesn't play nice with ASan's ODR checker.
413             LDFLAGS="$LDFLAGS -opt:nolldtailmerge"
414         fi
415         MOZ_DEBUG_LDFLAGS='-DEBUG'
416         if test "$HOST_OS_ARCH" != "WINNT"; then
417           # %_PDB% is a special signal to emit only the PDB basename. This
418           # avoids problems in Windows tools that don't like forward-slashes.
419           MOZ_DEBUG_LDFLAGS="$MOZ_DEBUG_LDFLAGS -PDBALTPATH:%_PDB%"
420         fi
421         MOZ_OPTIMIZE_FLAGS="-O2"
422         MOZ_FIX_LINK_PATHS=
423         LDFLAGS="$LDFLAGS -LARGEADDRESSAWARE"
424     fi
425     AC_DEFINE(HAVE__MSIZE)
426     AC_DEFINE(WIN32_LEAN_AND_MEAN)
427     dnl See http://support.microsoft.com/kb/143208 to use STL
428     AC_DEFINE(NOMINMAX)
429     BIN_SUFFIX='.exe'
431     case "$host_os" in
432     cygwin*|msvc*|mks*)
433         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.])
434         ;;
435     esac
437     case "$target" in
438     i*86-*)
439         if test -n "$GNU_CC"; then
440             CFLAGS="$CFLAGS -mstackrealign"
441             CXXFLAGS="$CXXFLAGS -mstackrealign"
442             LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
443         else
444             DSO_LDOPTS="$DSO_LDOPTS -MACHINE:X86"
445             LDFLAGS="$LDFLAGS -SAFESEH"
446         fi
448         AC_DEFINE(_X86_)
449         ;;
450     x86_64-*)
451         if test -n "$_WIN32_MSVC"; then
452             DSO_LDOPTS="$DSO_LDOPTS -MACHINE:X64"
453         fi
454         AC_DEFINE(_AMD64_)
455         ;;
456     aarch64-*)
457         if test -n "$_WIN32_MSVC"; then
458             DSO_LDOPTS="$DSO_LDOPTS -MACHINE:ARM64"
459         fi
460         AC_DEFINE(_ARM64_)
461         ;;
462     *)
463         AC_DEFINE(_CPU_ARCH_NOT_DEFINED)
464         ;;
465     esac
466     ;;
468 *-netbsd*)
469     CFLAGS="$CFLAGS -Dunix"
470     CXXFLAGS="$CXXFLAGS -Dunix"
471     if $CC -E - -dM </dev/null | grep __ELF__ >/dev/null; then
472         DSO_PIC_CFLAGS='-fPIC -DPIC'
473         DSO_LDOPTS='-shared'
474         MOZ_PROGRAM_LDFLAGS="$MOZ_PROGRAM_LDFLAGS -Wl,--export-dynamic"
475     else
476         DSO_PIC_CFLAGS='-fPIC -DPIC'
477         DSO_LDOPTS='-shared'
478     fi
479     # This will fail on a.out systems prior to 1.5.1_ALPHA.
480     if test "$LIBRUNPATH"; then
481         DSO_LDOPTS="-Wl,-R$LIBRUNPATH $DSO_LDOPTS"
482     fi
483     ;;
485 *-openbsd*)
486     DSO_PIC_CFLAGS='-fPIC'
487     DSO_LDOPTS='-shared -fPIC'
488     if test "$LIBRUNPATH"; then
489         DSO_LDOPTS="-R$LIBRUNPATH $DSO_LDOPTS"
490     fi
491     ;;
493 *-solaris*)
494     MOZ_FIX_LINK_PATHS="-L${DIST}/bin"
495     ;;
497 *-wasi*)
498     CXXFLAGS="$CXXFLAGS -mthread-model single"
499     MOZ_FIX_LINK_PATHS=
500     ;;
502 esac
504 CFLAGS="$CFLAGS $DSO_PIC_CFLAGS"
505 CXXFLAGS="$CXXFLAGS $DSO_PIC_CFLAGS"
507 if test -z "$MOZ_OPTIMIZE_FLAGS"; then
508         MOZ_OPTIMIZE_FLAGS="-O"
511 if test -z "$COMPILE_ENVIRONMENT"; then
512     SKIP_COMPILER_CHECKS=1
513     SKIP_LIBRARY_CHECKS=1
516 if test -n "$COMPILE_ENVIRONMENT"; then
517     MOZ_COMPILER_OPTS
520 if test -z "$SKIP_COMPILER_CHECKS"; then
521 dnl Checks for typedefs, structures, and compiler characteristics.
522 dnl ========================================================
523 AC_C_CONST
524 AC_TYPE_MODE_T
525 AC_TYPE_OFF_T
526 AC_TYPE_PID_T
527 AC_TYPE_SIZE_T
528 AC_LANG_CPLUSPLUS
529 AC_LANG_C
530 AC_MSG_CHECKING(for ssize_t)
531 AC_CACHE_VAL(ac_cv_type_ssize_t,
532  [AC_TRY_COMPILE([#include <stdio.h>
533                   #include <sys/types.h>],
534                  [ssize_t foo = 0;],
535                  [ac_cv_type_ssize_t=true],
536                  [ac_cv_type_ssize_t=false])])
537 if test "$ac_cv_type_ssize_t" = true ; then
538   AC_DEFINE(HAVE_SSIZE_T)
539   AC_MSG_RESULT(yes)
540 else
541   AC_MSG_RESULT(no)
544 AC_LANG_CPLUSPLUS
546 MOZ_CXX11
548 dnl Checks for header files.
549 dnl ========================================================
550 AC_HEADER_DIRENT
552 dnl Checks for libraries.
553 dnl ========================================================
554 AC_CHECK_LIB(c_r, gethostbyname_r)
556 dnl We don't want to link with libdl even if it's present on OS X, since
557 dnl it's not used and not part of the default installation. OS/2 has dlfcn
558 dnl in libc.
559 dnl We don't want to link against libm or libpthread on Darwin since
560 dnl they both are just symlinks to libSystem and explicitly linking
561 dnl against libSystem causes issues when debugging (see bug 299601).
562 case $target in
563 *-darwin*)
564     ;;
566     AC_SEARCH_LIBS(dlopen, dl,
567         MOZ_CHECK_HEADER(dlfcn.h,
568         AC_DEFINE(HAVE_DLOPEN)))
569     ;;
570 esac
572 _SAVE_CFLAGS="$CFLAGS"
573 CFLAGS="$CFLAGS -D_GNU_SOURCE"
574 AC_CHECK_FUNCS(dladdr)
575 CFLAGS="$_SAVE_CFLAGS"
577 if test ! "$GNU_CXX"; then
578     AC_CHECK_LIB(C, demangle)
581 AC_CHECK_LIB(socket, socket)
583 dnl ========================================================
584 dnl = pthread support
585 dnl = Start by checking whether the system support pthreads
586 dnl ========================================================
587 case "$target_os" in
588 darwin*)
589     USE_PTHREADS=1
590     ;;
592     AC_CHECK_LIB(pthreads, pthread_create,
593         USE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads",
594         AC_CHECK_LIB(pthread, pthread_create,
595             USE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread",
596             AC_CHECK_LIB(c_r, pthread_create,
597                 USE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r",
598                 AC_CHECK_LIB(c, pthread_create,
599                     USE_PTHREADS=1
600                 )
601             )
602         )
603     )
604     ;;
605 esac
607 dnl ========================================================
608 dnl Do the platform specific pthread hackery
609 dnl ========================================================
610 if test "$USE_PTHREADS"x != x
611 then
612         dnl
613         dnl See if -pthread is supported.
614         dnl
615         rm -f conftest*
616         ac_cv_have_dash_pthread=no
617         AC_MSG_CHECKING(whether ${CC-cc} accepts -pthread)
618         echo 'int main() { return 0; }' | cat > conftest.c
619         ${CC-cc} -pthread -o conftest conftest.c > conftest.out 2>&1
620         if test $? -eq 0; then
621                 if test -z "`grep -E -i '(unrecognize|unknown)' conftest.out | grep pthread`" -a -z "`grep -E -i '(error|incorrect)' conftest.out`" ; then
622                         ac_cv_have_dash_pthread=yes
623                 case "$target_os" in
624                 freebsd*)
625 # Freebsd doesn't use -pthread for compiles, it uses them for linking
626                 ;;
627                 *)
628                             CFLAGS="$CFLAGS -pthread"
629                             CXXFLAGS="$CXXFLAGS -pthread"
630                 ;;
631                 esac
632                 fi
633         fi
634         rm -f conftest*
635     AC_MSG_RESULT($ac_cv_have_dash_pthread)
637         dnl
638         dnl See if -pthreads is supported.
639         dnl
640     ac_cv_have_dash_pthreads=no
641     if test "$ac_cv_have_dash_pthread" = "no"; then
642             AC_MSG_CHECKING(whether ${CC-cc} accepts -pthreads)
643         echo 'int main() { return 0; }' | cat > conftest.c
644             ${CC-cc} -pthreads -o conftest conftest.c > conftest.out 2>&1
645         if test $? -eq 0; then
646                 if test -z "`grep -E -i '(unrecognize|unknown)' conftest.out | grep pthreads`" -a -z "`grep -E -i '(error|incorrect)' conftest.out`" ; then
647                             ac_cv_have_dash_pthreads=yes
648                             CFLAGS="$CFLAGS -pthreads"
649                             CXXFLAGS="$CXXFLAGS -pthreads"
650                     fi
651             fi
652             rm -f conftest*
653         AC_MSG_RESULT($ac_cv_have_dash_pthreads)
654     fi
656         case "$target" in
657             *-*-freebsd*)
658                         AC_DEFINE(_REENTRANT)
659                         AC_DEFINE(_THREAD_SAFE)
660                         dnl -pthread links in -lpthread, so don't specify it explicitly.
661                         if test "$ac_cv_have_dash_pthread" = "yes"; then
662                                 _PTHREAD_LDFLAGS="-pthread"
663                         fi
664                         ;;
666             *-*-openbsd*|*-*-bsdi*)
667                         AC_DEFINE(_REENTRANT)
668                         AC_DEFINE(_THREAD_SAFE)
669                         dnl -pthread links in -lc_r, so don't specify it explicitly.
670                         if test "$ac_cv_have_dash_pthread" = "yes"; then
671                 _PTHREAD_LDFLAGS="-pthread"
672                         fi
673                         ;;
675             *-*-linux*|*-*-kfreebsd*-gnu|*-*-gnu*)
676                         AC_DEFINE(_REENTRANT)
677                         ;;
679         esac
680     LDFLAGS="${_PTHREAD_LDFLAGS} ${LDFLAGS}"
684 dnl Checks for library functions.
685 dnl ========================================================
687 dnl check for clock_gettime(), the CLOCK_MONOTONIC clock
688 AC_CACHE_CHECK(for clock_gettime(CLOCK_MONOTONIC),
689                ac_cv_clock_monotonic,
690                [for libs in "" -lrt; do
691                     _SAVE_LIBS="$LIBS"
692                     LIBS="$LIBS $libs"
693 dnl clock_gettime is available on OSX since 10.12, so depending on MACOSX_DEPLOYMENT_TARGET,
694 dnl we should or not be able to use it. To detect if we can, we need to make the
695 dnl availability attribute strict, so that compilation fails when the target is < 10.12.
696                     AC_TRY_LINK([#define availability(os, ...) availability(os, strict, __VA_ARGS)
697                                  #include <time.h>],
698                                  [ struct timespec ts;
699                                    clock_gettime(CLOCK_MONOTONIC, &ts); ],
700                                  ac_cv_clock_monotonic=$libs
701                                  LIBS="$_SAVE_LIBS"
702                                  break,
703                                  ac_cv_clock_monotonic=no)
704                     LIBS="$_SAVE_LIBS"
705                 done])
706 if test "$ac_cv_clock_monotonic" != "no"; then
707     HAVE_CLOCK_MONOTONIC=1
708     REALTIME_LIBS=$ac_cv_clock_monotonic
709     AC_DEFINE(HAVE_CLOCK_MONOTONIC)
710     AC_SUBST(HAVE_CLOCK_MONOTONIC)
711     AC_SUBST_LIST(REALTIME_LIBS)
714 dnl Checks for math functions.
715 dnl ========================================================
716 AC_CHECK_LIB(m, sin)
718 AC_CACHE_CHECK(
719     [for res_ninit()],
720     ac_cv_func_res_ninit,
721     [if test "$OS_TARGET" = NetBSD -o "$OS_TARGET" = OpenBSD; then
722         dnl no need for res_ninit() on NetBSD and OpenBSD
723         ac_cv_func_res_ninit=no
724      else
725        AC_TRY_LINK([
726             #ifdef linux
727             #define _BSD_SOURCE 1
728             #endif
729             #include <sys/types.h>
730             #include <netinet/in.h>
731             #include <arpa/nameser.h>
732             #include <resolv.h>
733             ],
734             [int foo = res_ninit(&_res);],
735             [ac_cv_func_res_ninit=yes],
736             [ac_cv_func_res_ninit=no])
737      fi
738     ])
740 if test "$ac_cv_func_res_ninit" = "yes"; then
741     AC_DEFINE(HAVE_RES_NINIT)
742 dnl must add the link line we do something as foolish as this... dougt
743 dnl else
744 dnl    AC_CHECK_LIB(bind, res_ninit, AC_DEFINE(HAVE_RES_NINIT),
745 dnl        AC_CHECK_LIB(resolv, res_ninit, AC_DEFINE(HAVE_RES_NINIT)))
748 AM_LANGINFO_CODESET
750 AC_LANG_C
752 dnl ===================================================================
753 dnl ========================================================
754 dnl Put your C++ language/feature checks below
755 dnl ========================================================
756 AC_LANG_CPLUSPLUS
758 ARM_ABI_PREFIX=
759 if test "$GNU_CC"; then
760   if test "$TARGET_CPU" = "arm" ; then
761     AC_CACHE_CHECK(for ARM EABI,
762         ac_cv_gcc_arm_eabi,
763         [AC_TRY_COMPILE([],
764                         [
765 #if defined(__ARM_EABI__)
766   return 0;
767 #else
768 #error Not ARM EABI.
769 #endif
770                         ],
771                         ac_cv_gcc_arm_eabi="yes",
772                         ac_cv_gcc_arm_eabi="no")])
773     if test "$ac_cv_gcc_arm_eabi" = "yes"; then
774         HAVE_ARM_EABI=1
775         ARM_ABI_PREFIX=eabi-
776     else
777         ARM_ABI_PREFIX=oabi-
778     fi
779   fi
781   TARGET_COMPILER_ABI="${TARGET_COMPILER_ABI-${ARM_ABI_PREFIX}gcc3}"
784 # try harder, when checking for __thread support, see bug 521750 comment #33 and below
785 # We pass MOZ_OPTIMIZE_LDFLAGS to the linker because if dead_strip is
786 # enabled, the linker in xcode 4.1 will crash. Without this it would crash when
787 # linking XUL.
788 _SAVE_LDFLAGS=$LDFLAGS
789 LDFLAGS="$LDFLAGS $DSO_LDOPTS $MOZ_OPTIMIZE_LDFLAGS"
790 AC_CACHE_CHECK(for __thread keyword for TLS variables,
791                ac_cv_thread_keyword,
792                [AC_TRY_LINK([__thread bool tlsIsMainThread = false;],
793                             [return tlsIsMainThread;],
794                             ac_cv_thread_keyword=yes,
795                             ac_cv_thread_keyword=no)])
796 LDFLAGS=$_SAVE_LDFLAGS
797 if test "$ac_cv_thread_keyword" = yes; then
798   # mips builds fail with TLS variables because of a binutils bug.
799   # See bug 528687
800   case "${target}" in
801     mips*-*)
802       :
803       ;;
804     *-android*|*-linuxandroid*)
805       :
806       ;;
807     *)
808       AC_DEFINE(HAVE_THREAD_TLS_KEYWORD)
809       ;;
810   esac
813 dnl End of C++ language/feature checks
814 AC_LANG_C
816 fi # ! SKIP_COMPILER_CHECKS
818 TARGET_XPCOM_ABI=
819 if test -n "${TARGET_CPU}" -a -n "${TARGET_COMPILER_ABI}"; then
820     TARGET_XPCOM_ABI="${TARGET_CPU}-${TARGET_COMPILER_ABI}"
823 dnl We can't run TRY_COMPILE tests on Windows, so hard-code some
824 dnl features that Windows actually does support.
826 if test -n "$SKIP_COMPILER_CHECKS"; then
827    dnl Windows has malloc.h
828    AC_DEFINE(MALLOC_H, [<malloc.h>])
829    AC_DEFINE(HAVE_FORCEINLINE)
830 fi # SKIP_COMPILER_CHECKS
832 dnl Mozilla specific options
833 dnl ========================================================
834 dnl The macros used for command line options
835 dnl are defined in build/autoconf/altoptions.m4.
837 dnl ========================================================
838 dnl = Enable code optimization. ON by default.
839 dnl ========================================================
841 # Use value from moz.configure if one is defined. Else use our computed
842 # value.
843 if test -n "${MOZ_CONFIGURE_OPTIMIZE_FLAGS}"; then
844     MOZ_OPTIMIZE_FLAGS=${MOZ_CONFIGURE_OPTIMIZE_FLAGS}
847 if test "$COMPILE_ENVIRONMENT"; then
848 if test -n "$MOZ_OPTIMIZE"; then
849     AC_MSG_CHECKING([for valid optimization flags])
850     _SAVE_CFLAGS=$CFLAGS
851     CFLAGS="$CFLAGS $MOZ_OPTIMIZE_FLAGS"
852     AC_TRY_COMPILE([#include <stdio.h>],
853         [printf("Hello World\n");],
854         _results=yes,
855         _results=no)
856     AC_MSG_RESULT([$_results])
857     if test "$_results" = "no"; then
858         AC_MSG_ERROR([These compiler flags are invalid: $MOZ_OPTIMIZE_FLAGS])
859     fi
860     CFLAGS=$_SAVE_CFLAGS
861     if test -n "$MOZ_LTO" -a -n "$CLANG_CC"; then
862         # When using llvm-based LTO, non numeric optimization levels are
863         # not supported by the linker, so force the linker to use -O2 (
864         # which doesn't influence the level compilation units are actually
865         # compiled at).
866         case " $MOZ_OPTIMIZE_FLAGS " in
867         *\ -Os\ *|*\ -Oz\ *)
868             MOZ_OPTIMIZE_LDFLAGS="$MOZ_OPTIMIZE_LDFLAGS -O2"
869             ;;
870         esac
871     fi
873 fi # COMPILE_ENVIRONMENT
875 AC_SUBST_LIST(MOZ_OPTIMIZE_FLAGS)
876 AC_SUBST_LIST(MOZ_OPTIMIZE_LDFLAGS)
877 AC_SUBST_LIST(MOZ_PGO_OPTIMIZE_FLAGS)
879 dnl ========================================================
880 dnl = Enable jemalloc
881 dnl ========================================================
883 if test "$JS_STANDALONE" -a -z "$MOZ_MEMORY"; then
884   MOZ_GLUE_IN_PROGRAM=
885 else
886   case "${OS_TARGET}" in
887   Android|WINNT|Darwin)
888     MOZ_GLUE_IN_PROGRAM=
889     ;;
890   *)
891     dnl On !Android !Windows !OSX, we only want to link executables against mozglue
892     MOZ_GLUE_IN_PROGRAM=1
893     AC_DEFINE(MOZ_GLUE_IN_PROGRAM)
894     ;;
895   esac
898 if test "$MOZ_MEMORY"; then
899   dnl The generic feature tests that determine how to compute ncpus are long and
900   dnl complicated.  Therefore, simply define special cpp variables for the
901   dnl platforms we have special knowledge of.
902   case "${target}" in
903   *-mingw*)
904     export MOZ_NO_DEBUG_RTL=1
905     ;;
906   esac
908 AC_SUBST(MOZ_GLUE_IN_PROGRAM)
910 dnl ========================================================
911 dnl instruments
912 dnl ========================================================
913 if test -n "$MOZ_INSTRUMENTS"; then
914     LIBS="$LIBS -framework CoreFoundation"
917 dnl ========================================================
918 dnl = Enable using the clang plugin to build
919 dnl ========================================================
921 if test -n "$COMPILE_ENVIRONMENT"; then
922 MOZ_CONFIG_CLANG_PLUGIN
923 fi # COMPILE_ENVIRONMENT
925 if test -z "$SKIP_COMPILER_CHECKS"; then
927 dnl ========================================================
928 dnl Check for gcc -pipe support
929 dnl ========================================================
930 AC_MSG_CHECKING([for -pipe support])
931 if test -n "$GNU_CC" -a -n "$GNU_CXX"; then
932     dnl Any gcc that supports firefox supports -pipe.
933     CFLAGS="$CFLAGS -pipe"
934     CXXFLAGS="$CXXFLAGS -pipe"
935     AC_MSG_RESULT([yes])
936 else
937     AC_MSG_RESULT([no])
940 fi # ! SKIP_COMPILER_CHECKS
942 MOZ_EXPAND_LIBS
944 dnl ========================================================
945 dnl =
946 dnl = Maintainer debug option (no --enable equivalent)
947 dnl =
948 dnl ========================================================
950 AC_SUBST_LIST(ASFLAGS)
951 AC_SUBST_LIST(MOZ_DEBUG_LDFLAGS)
953 AC_SUBST_LIST(MOZ_FIX_LINK_PATHS)
955 AC_SUBST(MOZ_POST_PROGRAM_COMMAND)
957 AC_SUBST(MOZ_APP_DISPLAYNAME)
959 AC_SUBST(MOZ_PKG_SPECIAL)
961 dnl Echo the CFLAGS to remove extra whitespace.
962 CFLAGS=`echo \
963         $_COMPILATION_CFLAGS \
964         $CFLAGS`
966 CXXFLAGS=`echo \
967         $_COMPILATION_CXXFLAGS \
968         $CXXFLAGS`
970 COMPILE_CFLAGS=`echo \
971     $_DEFINES_CFLAGS \
972     $COMPILE_CFLAGS`
974 COMPILE_CXXFLAGS=`echo \
975     $_DEFINES_CXXFLAGS \
976     $COMPILE_CXXFLAGS`
978 HOST_CFLAGS=`echo \
979     $_COMPILATION_HOST_CFLAGS \
980     $HOST_CFLAGS`
982 HOST_CXXFLAGS=`echo \
983     $_COMPILATION_HOST_CXXFLAGS \
984     $HOST_CXXFLAGS`
986 OS_CFLAGS="$CFLAGS"
987 OS_CXXFLAGS="$CXXFLAGS"
988 OS_CPPFLAGS="$CPPFLAGS"
989 OS_COMPILE_CFLAGS="$COMPILE_CFLAGS"
990 OS_COMPILE_CXXFLAGS="$COMPILE_CXXFLAGS"
991 OS_LDFLAGS="$LDFLAGS"
992 OS_LIBS="$LIBS"
993 AC_SUBST_LIST(OS_CFLAGS)
994 AC_SUBST_LIST(OS_CXXFLAGS)
995 AC_SUBST_LIST(OS_CPPFLAGS)
996 AC_SUBST_LIST(OS_COMPILE_CFLAGS)
997 AC_SUBST_LIST(OS_COMPILE_CXXFLAGS)
998 AC_SUBST_LIST(OS_LDFLAGS)
999 AC_SUBST(OS_LIBS)
1001 AC_SUBST(HOST_CC)
1002 AC_SUBST(HOST_CXX)
1003 AC_SUBST_LIST(HOST_CFLAGS)
1004 AC_SUBST_LIST(HOST_CPPFLAGS)
1005 AC_SUBST_LIST(HOST_CXXFLAGS)
1006 AC_SUBST(HOST_LDFLAGS)
1007 AC_SUBST_LIST(HOST_OPTIMIZE_FLAGS)
1008 AC_SUBST(HOST_BIN_SUFFIX)
1010 AC_SUBST(TARGET_XPCOM_ABI)
1012 AC_SUBST(DSO_LDOPTS)
1013 AC_SUBST(BIN_SUFFIX)
1014 AC_SUBST(USE_N32)
1015 AC_SUBST(WIN32_CONSOLE_EXE_LDFLAGS)
1016 AC_SUBST(WIN32_GUI_EXE_LDFLAGS)
1018 dnl Set various defines and substitutions
1019 dnl ========================================================
1021 AC_SUBST(MOZ_DEV_EDITION)
1022 if test -n "$MOZ_DEV_EDITION"; then
1023     AC_DEFINE(MOZ_DEV_EDITION)
1026 dnl ========================================================
1027 dnl JavaScript shell
1028 dnl ========================================================
1030 MOZ_CHECK_ALLOCATOR
1032 if test -n "$JS_STANDALONE"; then
1033 JS_LIBRARY_NAME="mozjs-$MOZILLA_SYMBOLVERSION"
1034 else
1035 JS_LIBRARY_NAME="mozjs"
1037 JS_CONFIG_LIBS="$NSPR_LIBS $LIBS"
1038 if test -n "$GNU_CC"; then
1039 JS_CONFIG_MOZ_JS_LIBS='-L${libdir} -l${JS_LIBRARY_NAME}'
1040 else
1041 JS_CONFIG_MOZ_JS_LIBS='${libdir}/${JS_LIBRARY_NAME}.lib'
1043 AC_SUBST(JS_LIBRARY_NAME)
1044 AC_SUBST(JS_CONFIG_MOZ_JS_LIBS)
1045 AC_SUBST(JS_CONFIG_LIBS)
1047 # Avoid using obsolete NSPR features
1048 AC_DEFINE(NO_NSPR_10_SUPPORT)
1050 dnl Spit out some output
1051 dnl ========================================================
1052 MOZ_CREATE_CONFIG_STATUS()
1054 rm -fr confdefs* $ac_clean_files