Backed out 2 changesets (bug 1832733) for causing mochitest manifest failures and...
[gecko.git] / js / src / old-configure.in
blobcabd72a2b61cd08775058612fd1ccfeb4725eeab
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"
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 # Target the Windows 8.1 SDK by default
86 WINVER=601
88 case "$target" in
89 *-mingw*)
90     if test "$GCC" != "yes"; then
91         # Check to see if we are really running in a msvc environemnt
92         _WIN32_MSVC=1
94         # Make sure compilers are valid
95         CXXFLAGS="$CXXFLAGS -TP"
96         # _CRT_SECURE_NO_WARNINGS disables warnings about using MSVC-specific
97         # secure CRT functions.
98         CXXFLAGS="$CXXFLAGS -D_CRT_SECURE_NO_WARNINGS"
99         AC_LANG_SAVE
100         AC_LANG_C
101         AC_TRY_COMPILE([#include <stdio.h>],
102             [ printf("Hello World\n"); ],,
103             AC_MSG_ERROR([\$(CC) test failed.  You must have MS VC++ in your path to build.]) )
105         AC_LANG_CPLUSPLUS
106         AC_TRY_COMPILE([#include <new.h>],
107             [ unsigned *test = new unsigned(42); ],,
108             AC_MSG_ERROR([\$(CXX) test failed.  You must have MS VC++ in your path to build.]) )
109         AC_LANG_RESTORE
111         AC_DEFINE(_CRT_SECURE_NO_WARNINGS)
112         AC_DEFINE(_CRT_NONSTDC_NO_WARNINGS)
114         MSVC_C_RUNTIME_DLL=vcruntime140.dll
115         if test -n "$IS_VS2019_OR_MORE" -a "$CPU_ARCH" != "x86"; then
116             MSVC_C_RUNTIME_1_DLL=vcruntime140_1.dll
117         fi
118         MSVC_CXX_RUNTIME_DLL=msvcp140.dll
120         # -Zc:sizedDealloc- disables C++14 global sized deallocation (see bug 1160146)
121         CXXFLAGS="$CXXFLAGS -Zc:sizedDealloc-"
123         AC_SUBST(MSVC_C_RUNTIME_DLL)
124         AC_SUBST(MSVC_C_RUNTIME_1_DLL)
125         AC_SUBST(MSVC_CXX_RUNTIME_DLL)
127         CFLAGS="$CFLAGS -D_HAS_EXCEPTIONS=0"
128         CXXFLAGS="$CXXFLAGS -D_HAS_EXCEPTIONS=0"
129     else
130         # Check w32api version
131         _W32API_MAJOR_VERSION=`echo $W32API_VERSION | $AWK -F\. '{ print $1 }'`
132         _W32API_MINOR_VERSION=`echo $W32API_VERSION | $AWK -F\. '{ print $2 }'`
133         AC_MSG_CHECKING([for w32api version >= $W32API_VERSION])
134         AC_TRY_COMPILE([#include <w32api.h>],
135             #if (__W32API_MAJOR_VERSION < $_W32API_MAJOR_VERSION) || \
136                 (__W32API_MAJOR_VERSION == $_W32API_MAJOR_VERSION && \
137                  __W32API_MINOR_VERSION < $_W32API_MINOR_VERSION)
138                 #error "test failed."
139             #endif
140             , [ res=yes ], [ res=no ])
141         AC_MSG_RESULT([$res])
142         if test "$res" != "yes"; then
143             AC_MSG_ERROR([w32api version $W32API_VERSION or higher required.])
144         fi
145     fi # !GNU_CC
147     AC_DEFINE(_USE_MATH_DEFINES) # Otherwise Windows' math.h doesn't #define M_PI.
149     AC_DEFINE_UNQUOTED(WINVER,0x$WINVER)
150     AC_DEFINE_UNQUOTED(_WIN32_WINNT,0x$WINVER)
151     # Require OS features provided by IE 8.0 (Win7)
152     AC_DEFINE_UNQUOTED(_WIN32_IE,0x0800)
154     ;;
155 esac
157 if test -n "$_WIN32_MSVC"; then
158     SKIP_PATH_CHECKS=1
159     SKIP_COMPILER_CHECKS=1
160     SKIP_LIBRARY_CHECKS=1
163 fi # COMPILE_ENVIRONMENT
165 AC_SUBST(GNU_CC)
166 AC_SUBST(GNU_CXX)
168 dnl ========================================================
169 dnl set the defaults first
170 dnl ========================================================
171 MOZ_FIX_LINK_PATHS="-Wl,-rpath-link,${DIST}/bin -Wl,-rpath-link,${prefix}/lib"
173 dnl Configure platform-specific CPU architecture compiler options.
174 dnl ==============================================================
175 MOZ_ARCH_OPTS
177 MOZ_CONFIG_SANITIZE
179 dnl ========================================================
180 dnl GNU specific defaults
181 dnl ========================================================
182 if test "$GNU_CC"; then
183     DSO_LDOPTS='-shared'
184     if test "$GCC_USE_GNU_LD"; then
185         # Some tools like ASan use a runtime library that is only
186         # linked against executables, so we must allow undefined
187         # symbols for shared objects in some cases.
188         if test -z "$MOZ_ASAN$MOZ_MSAN$MOZ_UBSAN$MOZ_TSAN$FUZZING_INTERFACES"; then
189             # Don't allow undefined symbols in libraries
190             DSO_LDOPTS="$DSO_LDOPTS -Wl,-z,defs"
191         fi
192     fi
194     if test "$OS_ARCH" != "WINNT"; then
195         DSO_PIC_CFLAGS='-fPIC'
196         ASFLAGS="$ASFLAGS -fPIC"
197     fi
199     AC_MSG_CHECKING([for --noexecstack option to as])
200     _SAVE_CFLAGS=$CFLAGS
201     CFLAGS="$CFLAGS -Wa,--noexecstack"
202     AC_TRY_COMPILE(,,AC_MSG_RESULT([yes])
203                      [ASFLAGS="$ASFLAGS -Wa,--noexecstack"],
204                      AC_MSG_RESULT([no]))
205     CFLAGS=$_SAVE_CFLAGS
206     AC_MSG_CHECKING([for -z noexecstack option to ld])
207     _SAVE_LDFLAGS=$LDFLAGS
208     LDFLAGS="$LDFLAGS -Wl,-z,noexecstack"
209     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
210                   AC_MSG_RESULT([no])
211                   LDFLAGS=$_SAVE_LDFLAGS)
213     AC_MSG_CHECKING([for -z text option to ld])
214     _SAVE_LDFLAGS=$LDFLAGS
215     LDFLAGS="$LDFLAGS -Wl,-z,text"
216     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
217                   AC_MSG_RESULT([no])
218                   LDFLAGS=$_SAVE_LDFLAGS)
220     AC_MSG_CHECKING([for -z relro option to ld])
221     _SAVE_LDFLAGS=$LDFLAGS
222     LDFLAGS="$LDFLAGS -Wl,-z,relro"
223     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
224                   AC_MSG_RESULT([no])
225                   LDFLAGS=$_SAVE_LDFLAGS)
227     AC_MSG_CHECKING([for -z nocopyreloc option to ld])
228     _SAVE_LDFLAGS=$LDFLAGS
229     LDFLAGS="$LDFLAGS -Wl,-z,nocopyreloc"
230     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
231                   AC_MSG_RESULT([no])
232                   LDFLAGS=$_SAVE_LDFLAGS)
234     AC_MSG_CHECKING([for -Bsymbolic-functions option to ld])
235     _SAVE_LDFLAGS=$LDFLAGS
236     LDFLAGS="$LDFLAGS -Wl,-Bsymbolic-functions"
237     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
238                   AC_MSG_RESULT([no])
239                   LDFLAGS=$_SAVE_LDFLAGS)
241     # While sha1 is deterministic, it is slower.
242     if test -z "$DEVELOPER_OPTIONS"; then
243         build_id=sha1
244     else
245         build_id=uuid
246     fi
247     AC_MSG_CHECKING([for --build-id=$build_id option to ld])
248     _SAVE_LDFLAGS=$LDFLAGS
249     LDFLAGS="$LDFLAGS -Wl,--build-id=$build_id"
250     AC_TRY_LINK(,,AC_MSG_RESULT([yes]),
251                   AC_MSG_RESULT([no])
252                   LDFLAGS=$_SAVE_LDFLAGS)
254     _DEFINES_CFLAGS="-include $jsconfdefs -DMOZILLA_CLIENT"
257 if test "$GNU_CXX"; then
258     _DEFINES_CXXFLAGS="-DMOZILLA_CLIENT -include $jsconfdefs"
261 dnl ========================================================
262 dnl System overrides of the defaults for host
263 dnl ========================================================
264 case "$host" in
265 *mingw*)
266     if test -n "$_WIN32_MSVC"; then
267         HOST_CFLAGS="$HOST_CFLAGS"
268     else
269         HOST_CFLAGS="$HOST_CFLAGS -mwindows"
270     fi
271     HOST_CFLAGS="$HOST_CFLAGS -DXP_WIN -DWIN32 -D_WIN32 -D_CRT_SECURE_NO_WARNINGS"
272     HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O2}"
273     HOST_BIN_SUFFIX=.exe
275     case "${host_cpu}" in
276     i*86)
277         if test -n "$_WIN32_MSVC"; then
278             HOST_LDFLAGS="$HOST_LDFLAGS -MACHINE:X86"
279         fi
280         ;;
281     x86_64)
282         if test -n "$_WIN32_MSVC"; then
283             HOST_LDFLAGS="$HOST_LDFLAGS -MACHINE:X64"
284         fi
285         HOST_CFLAGS="$HOST_CFLAGS -D_AMD64_"
286         ;;
287     esac
288     ;;
290 *-darwin*)
291     HOST_CFLAGS="$HOST_CFLAGS -DXP_UNIX -DXP_MACOSX"
292     HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O3}"
293     ;;
295 *-linux*|*-kfreebsd*-gnu|*-gnu*)
296     HOST_CFLAGS="$HOST_CFLAGS -DXP_UNIX"
297     HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O3}"
298     ;;
301     HOST_CFLAGS="$HOST_CFLAGS -DXP_UNIX"
302     HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O2}"
303     ;;
304 esac
306 dnl ========================================================
307 dnl System overrides of the defaults for target
308 dnl ========================================================
310 case "$target" in
311 *-darwin*)
312     MOZ_OPTIMIZE_FLAGS="-O3"
313     DSO_LDOPTS=''
315     dnl DTrace and -dead_strip don't interact well. See bug 403132.
316     dnl ===================================================================
317     if test "x$enable_dtrace" = "xyes"; then
318         echo "Skipping -dead_strip because DTrace is enabled. See bug 403132."
319     else
320         dnl check for the presence of the -dead_strip linker flag
321         AC_MSG_CHECKING([for -dead_strip option to ld])
322         _SAVE_LDFLAGS=$LDFLAGS
323         LDFLAGS="$LDFLAGS -Wl,-dead_strip"
324         AC_TRY_LINK(,[return 0;],_HAVE_DEAD_STRIP=1,_HAVE_DEAD_STRIP=)
325         if test -n "$_HAVE_DEAD_STRIP" ; then
326             AC_MSG_RESULT([yes])
327             MOZ_OPTIMIZE_LDFLAGS="-Wl,-dead_strip"
328         else
329             AC_MSG_RESULT([no])
330         fi
332         LDFLAGS=$_SAVE_LDFLAGS
333     fi
334     MOZ_FIX_LINK_PATHS=
335     ;;
337 *-android*|*-linuxandroid*)
338     MOZ_OPTIMIZE_FLAGS="-O3"
339     if test -z "$CLANG_CC"; then
340        MOZ_OPTIMIZE_FLAGS="-freorder-blocks -fno-reorder-functions $MOZ_OPTIMIZE_FLAGS"
341     fi
342     ;;
344 *-*linux*)
345     if test "$GNU_CC" -o "$GNU_CXX"; then
346         MOZ_PGO_OPTIMIZE_FLAGS="-O3"
347         MOZ_OPTIMIZE_FLAGS="-O3"
348         if test -z "$CLANG_CC"; then
349            MOZ_OPTIMIZE_FLAGS="-freorder-blocks $MOZ_OPTIMIZE_FLAGS"
350         fi
351     fi
353     case "${target_cpu}" in
354     alpha*)
355         CFLAGS="$CFLAGS -mieee"
356         CXXFLAGS="$CXXFLAGS -mieee"
357     ;;
358     esac
359     ;;
361 *-mingw*)
362     DSO_PIC_CFLAGS=
363     if test -n "$GNU_CC" -o -n "$CLANG_CC"; then
364         # $GNU_CC will match gcc and clang; while $CLANG_CC will match only clang
365         if test -z "$CLANG_CC"; then
366             AC_MSG_ERROR(Firefox cannot be built with mingw-gcc and requires a mingw-clang toolchain to work)
367         fi
369         DSO_LDOPTS='-shared'
370         MOZ_FIX_LINK_PATHS=
372         # Silence problematic clang warnings
373         CXXFLAGS="$CXXFLAGS -Wno-incompatible-ms-struct"
374         LDFLAGS="$LDFLAGS -Wl,--no-insert-timestamp"
376         MOZ_OPTIMIZE_FLAGS="-O2"
378         WIN32_CONSOLE_EXE_LDFLAGS=-mconsole
379         WIN32_GUI_EXE_LDFLAGS=-mwindows
380     else
381         TARGET_COMPILER_ABI=msvc
382         # aarch64 doesn't support subsystems below 6.02
383         if test "$CPU_ARCH" = "aarch64"; then
384             WIN32_SUBSYSTEM_VERSION=6.02
385         else
386             WIN32_SUBSYSTEM_VERSION=6.01
387         fi
388         WIN32_CONSOLE_EXE_LDFLAGS=-SUBSYSTEM:CONSOLE,$WIN32_SUBSYSTEM_VERSION
389         WIN32_GUI_EXE_LDFLAGS=-SUBSYSTEM:WINDOWS,$WIN32_SUBSYSTEM_VERSION
390         DSO_LDOPTS=-SUBSYSTEM:WINDOWS,$WIN32_SUBSYSTEM_VERSION
391         _DEFINES_CFLAGS="-FI $jsconfdefs -DMOZILLA_CLIENT"
392         _DEFINES_CXXFLAGS="-FI $jsconfdefs -DMOZILLA_CLIENT"
393         CFLAGS="$CFLAGS -Gy -Zc:inline"
394         CXXFLAGS="$CXXFLAGS -Gy -Zc:inline"
395         if test "$CPU_ARCH" = "x86";then
396           dnl VS2012+ defaults to -arch:SSE2. We want to target nothing
397           dnl more recent, so set that explicitly here unless another
398           dnl target arch has already been set.
399           changequote(,)
400           if test -z `echo $CFLAGS | grep -i [-/]arch:` ; then
401             CFLAGS="$CFLAGS -arch:SSE2"
402           fi
403           if test -z `echo $CXXFLAGS | grep -i [-/]arch:` ; then
404             CXXFLAGS="$CXXFLAGS -arch:SSE2"
405           fi
406           changequote([,])
407         fi
408         dnl VS2013+ supports -Gw for better linker optimizations.
409         dnl http://blogs.msdn.com/b/vcblog/archive/2013/09/11/introducing-gw-compiler-switch.aspx
410         dnl Disabled on ASan because it causes false-positive ODR violations.
411         if test -z "$MOZ_ASAN"; then
412             CFLAGS="$CFLAGS -Gw"
413             CXXFLAGS="$CXXFLAGS -Gw"
414         else
415             # String tail merging doesn't play nice with ASan's ODR checker.
416             LDFLAGS="$LDFLAGS -opt:nolldtailmerge"
417         fi
418         MOZ_DEBUG_LDFLAGS='-DEBUG'
419         if test "$HOST_OS_ARCH" != "WINNT"; then
420           # %_PDB% is a special signal to emit only the PDB basename. This
421           # avoids problems in Windows tools that don't like forward-slashes.
422           MOZ_DEBUG_LDFLAGS="$MOZ_DEBUG_LDFLAGS -PDBALTPATH:%_PDB%"
423         fi
424         MOZ_OPTIMIZE_FLAGS="-O2"
425         MOZ_FIX_LINK_PATHS=
426         LDFLAGS="$LDFLAGS -LARGEADDRESSAWARE"
427     fi
428     AC_DEFINE(HAVE__MSIZE)
429     AC_DEFINE(WIN32_LEAN_AND_MEAN)
430     dnl See http://support.microsoft.com/kb/143208 to use STL
431     AC_DEFINE(NOMINMAX)
432     BIN_SUFFIX='.exe'
434     case "$host_os" in
435     cygwin*|msvc*|mks*)
436         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.])
437         ;;
438     esac
440     case "$target" in
441     i*86-*)
442         if test -n "$GNU_CC"; then
443             CFLAGS="$CFLAGS -mstackrealign"
444             CXXFLAGS="$CXXFLAGS -mstackrealign"
445             LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
446         else
447             DSO_LDOPTS="$DSO_LDOPTS -MACHINE:X86"
448             LDFLAGS="$LDFLAGS -SAFESEH"
449         fi
451         AC_DEFINE(_X86_)
452         ;;
453     x86_64-*)
454         if test -n "$_WIN32_MSVC"; then
455             DSO_LDOPTS="$DSO_LDOPTS -MACHINE:X64"
456         fi
457         AC_DEFINE(_AMD64_)
458         ;;
459     aarch64-*)
460         if test -n "$_WIN32_MSVC"; then
461             DSO_LDOPTS="$DSO_LDOPTS -MACHINE:ARM64"
462         fi
463         AC_DEFINE(_ARM64_)
464         ;;
465     *)
466         AC_DEFINE(_CPU_ARCH_NOT_DEFINED)
467         ;;
468     esac
469     ;;
471 *-netbsd*)
472     CFLAGS="$CFLAGS -Dunix"
473     CXXFLAGS="$CXXFLAGS -Dunix"
474     if $CC -E - -dM </dev/null | grep __ELF__ >/dev/null; then
475         DSO_PIC_CFLAGS='-fPIC -DPIC'
476         DSO_LDOPTS='-shared'
477         MOZ_PROGRAM_LDFLAGS="$MOZ_PROGRAM_LDFLAGS -Wl,--export-dynamic"
478     else
479         DSO_PIC_CFLAGS='-fPIC -DPIC'
480         DSO_LDOPTS='-shared'
481     fi
482     # This will fail on a.out systems prior to 1.5.1_ALPHA.
483     if test "$LIBRUNPATH"; then
484         DSO_LDOPTS="-Wl,-R$LIBRUNPATH $DSO_LDOPTS"
485     fi
486     ;;
488 *-openbsd*)
489     DSO_PIC_CFLAGS='-fPIC'
490     DSO_LDOPTS='-shared -fPIC'
491     if test "$LIBRUNPATH"; then
492         DSO_LDOPTS="-R$LIBRUNPATH $DSO_LDOPTS"
493     fi
494     ;;
496 *-solaris*)
497     MOZ_FIX_LINK_PATHS="-L${DIST}/bin"
498     ;;
500 *-wasi*)
501     CXXFLAGS="$CXXFLAGS -mthread-model single"
502     MOZ_FIX_LINK_PATHS=
503     ;;
505 esac
507 CFLAGS="$CFLAGS $DSO_PIC_CFLAGS"
508 CXXFLAGS="$CXXFLAGS $DSO_PIC_CFLAGS"
510 if test -z "$MOZ_OPTIMIZE_FLAGS"; then
511         MOZ_OPTIMIZE_FLAGS="-O"
514 if test -z "$COMPILE_ENVIRONMENT"; then
515     SKIP_COMPILER_CHECKS=1
516     SKIP_LIBRARY_CHECKS=1
519 if test -n "$COMPILE_ENVIRONMENT"; then
520     MOZ_COMPILER_OPTS
523 if test -z "$SKIP_COMPILER_CHECKS"; then
524 dnl Checks for typedefs, structures, and compiler characteristics.
525 dnl ========================================================
526 AC_C_CONST
527 AC_TYPE_MODE_T
528 AC_TYPE_OFF_T
529 AC_TYPE_PID_T
530 AC_TYPE_SIZE_T
531 AC_LANG_CPLUSPLUS
532 AC_LANG_C
533 AC_MSG_CHECKING(for ssize_t)
534 AC_CACHE_VAL(ac_cv_type_ssize_t,
535  [AC_TRY_COMPILE([#include <stdio.h>
536                   #include <sys/types.h>],
537                  [ssize_t foo = 0;],
538                  [ac_cv_type_ssize_t=true],
539                  [ac_cv_type_ssize_t=false])])
540 if test "$ac_cv_type_ssize_t" = true ; then
541   AC_DEFINE(HAVE_SSIZE_T)
542   AC_MSG_RESULT(yes)
543 else
544   AC_MSG_RESULT(no)
547 AC_LANG_CPLUSPLUS
549 MOZ_CXX11
551 dnl Checks for header files.
552 dnl ========================================================
553 AC_HEADER_DIRENT
555 dnl Checks for libraries.
556 dnl ========================================================
557 AC_CHECK_LIB(c_r, gethostbyname_r)
559 dnl We don't want to link with libdl even if it's present on OS X, since
560 dnl it's not used and not part of the default installation. OS/2 has dlfcn
561 dnl in libc.
562 dnl We don't want to link against libm or libpthread on Darwin since
563 dnl they both are just symlinks to libSystem and explicitly linking
564 dnl against libSystem causes issues when debugging (see bug 299601).
565 case $target in
566 *-darwin*)
567     ;;
569     AC_SEARCH_LIBS(dlopen, dl,
570         MOZ_CHECK_HEADER(dlfcn.h,
571         AC_DEFINE(HAVE_DLOPEN)))
572     ;;
573 esac
575 _SAVE_CFLAGS="$CFLAGS"
576 CFLAGS="$CFLAGS -D_GNU_SOURCE"
577 AC_CHECK_FUNCS(dladdr)
578 CFLAGS="$_SAVE_CFLAGS"
580 if test ! "$GNU_CXX"; then
581     AC_CHECK_LIB(C, demangle)
584 AC_CHECK_LIB(socket, socket)
586 dnl ========================================================
587 dnl = pthread support
588 dnl = Start by checking whether the system support pthreads
589 dnl ========================================================
590 case "$target_os" in
591 darwin*)
592     USE_PTHREADS=1
593     ;;
595     AC_CHECK_LIB(pthreads, pthread_create,
596         USE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads",
597         AC_CHECK_LIB(pthread, pthread_create,
598             USE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread",
599             AC_CHECK_LIB(c_r, pthread_create,
600                 USE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r",
601                 AC_CHECK_LIB(c, pthread_create,
602                     USE_PTHREADS=1
603                 )
604             )
605         )
606     )
607     ;;
608 esac
610 dnl ========================================================
611 dnl Do the platform specific pthread hackery
612 dnl ========================================================
613 if test "$USE_PTHREADS"x != x
614 then
615         dnl
616         dnl See if -pthread is supported.
617         dnl
618         rm -f conftest*
619         ac_cv_have_dash_pthread=no
620         AC_MSG_CHECKING(whether ${CC-cc} accepts -pthread)
621         echo 'int main() { return 0; }' | cat > conftest.c
622         ${CC-cc} -pthread -o conftest conftest.c > conftest.out 2>&1
623         if test $? -eq 0; then
624                 if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthread`" -a -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
625                         ac_cv_have_dash_pthread=yes
626                 case "$target_os" in
627                 freebsd*)
628 # Freebsd doesn't use -pthread for compiles, it uses them for linking
629                 ;;
630                 *)
631                             CFLAGS="$CFLAGS -pthread"
632                             CXXFLAGS="$CXXFLAGS -pthread"
633                 ;;
634                 esac
635                 fi
636         fi
637         rm -f conftest*
638     AC_MSG_RESULT($ac_cv_have_dash_pthread)
640         dnl
641         dnl See if -pthreads is supported.
642         dnl
643     ac_cv_have_dash_pthreads=no
644     if test "$ac_cv_have_dash_pthread" = "no"; then
645             AC_MSG_CHECKING(whether ${CC-cc} accepts -pthreads)
646         echo 'int main() { return 0; }' | cat > conftest.c
647             ${CC-cc} -pthreads -o conftest conftest.c > conftest.out 2>&1
648         if test $? -eq 0; then
649                 if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthreads`" -a -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
650                             ac_cv_have_dash_pthreads=yes
651                             CFLAGS="$CFLAGS -pthreads"
652                             CXXFLAGS="$CXXFLAGS -pthreads"
653                     fi
654             fi
655             rm -f conftest*
656         AC_MSG_RESULT($ac_cv_have_dash_pthreads)
657     fi
659         case "$target" in
660             *-*-freebsd*)
661                         AC_DEFINE(_REENTRANT)
662                         AC_DEFINE(_THREAD_SAFE)
663                         dnl -pthread links in -lpthread, so don't specify it explicitly.
664                         if test "$ac_cv_have_dash_pthread" = "yes"; then
665                                 _PTHREAD_LDFLAGS="-pthread"
666                         fi
667                         ;;
669             *-*-openbsd*|*-*-bsdi*)
670                         AC_DEFINE(_REENTRANT)
671                         AC_DEFINE(_THREAD_SAFE)
672                         dnl -pthread links in -lc_r, so don't specify it explicitly.
673                         if test "$ac_cv_have_dash_pthread" = "yes"; then
674                 _PTHREAD_LDFLAGS="-pthread"
675                         fi
676                         ;;
678             *-*-linux*|*-*-kfreebsd*-gnu|*-*-gnu*)
679                         AC_DEFINE(_REENTRANT)
680                         ;;
682         esac
683     LDFLAGS="${_PTHREAD_LDFLAGS} ${LDFLAGS}"
687 dnl Checks for library functions.
688 dnl ========================================================
690 dnl check for clock_gettime(), the CLOCK_MONOTONIC clock
691 AC_CACHE_CHECK(for clock_gettime(CLOCK_MONOTONIC),
692                ac_cv_clock_monotonic,
693                [for libs in "" -lrt; do
694                     _SAVE_LIBS="$LIBS"
695                     LIBS="$LIBS $libs"
696 dnl clock_gettime is available on OSX since 10.12, so depending on MACOSX_DEPLOYMENT_TARGET,
697 dnl we should or not be able to use it. To detect if we can, we need to make the
698 dnl availability attribute strict, so that compilation fails when the target is < 10.12.
699                     AC_TRY_LINK([#define availability(os, ...) availability(os, strict, __VA_ARGS)
700                                  #include <time.h>],
701                                  [ struct timespec ts;
702                                    clock_gettime(CLOCK_MONOTONIC, &ts); ],
703                                  ac_cv_clock_monotonic=$libs
704                                  LIBS="$_SAVE_LIBS"
705                                  break,
706                                  ac_cv_clock_monotonic=no)
707                     LIBS="$_SAVE_LIBS"
708                 done])
709 if test "$ac_cv_clock_monotonic" != "no"; then
710     HAVE_CLOCK_MONOTONIC=1
711     REALTIME_LIBS=$ac_cv_clock_monotonic
712     AC_DEFINE(HAVE_CLOCK_MONOTONIC)
713     AC_SUBST(HAVE_CLOCK_MONOTONIC)
714     AC_SUBST_LIST(REALTIME_LIBS)
717 dnl Checks for math functions.
718 dnl ========================================================
719 AC_CHECK_LIB(m, sin)
721 AC_CACHE_CHECK(
722     [for res_ninit()],
723     ac_cv_func_res_ninit,
724     [if test "$OS_TARGET" = NetBSD -o "$OS_TARGET" = OpenBSD; then
725         dnl no need for res_ninit() on NetBSD and OpenBSD
726         ac_cv_func_res_ninit=no
727      else
728        AC_TRY_LINK([
729             #ifdef linux
730             #define _BSD_SOURCE 1
731             #endif
732             #include <sys/types.h>
733             #include <netinet/in.h>
734             #include <arpa/nameser.h>
735             #include <resolv.h>
736             ],
737             [int foo = res_ninit(&_res);],
738             [ac_cv_func_res_ninit=yes],
739             [ac_cv_func_res_ninit=no])
740      fi
741     ])
743 if test "$ac_cv_func_res_ninit" = "yes"; then
744     AC_DEFINE(HAVE_RES_NINIT)
745 dnl must add the link line we do something as foolish as this... dougt
746 dnl else
747 dnl    AC_CHECK_LIB(bind, res_ninit, AC_DEFINE(HAVE_RES_NINIT),
748 dnl        AC_CHECK_LIB(resolv, res_ninit, AC_DEFINE(HAVE_RES_NINIT)))
751 AM_LANGINFO_CODESET
753 AC_LANG_C
755 dnl ===================================================================
756 dnl ========================================================
757 dnl Put your C++ language/feature checks below
758 dnl ========================================================
759 AC_LANG_CPLUSPLUS
761 ARM_ABI_PREFIX=
762 if test "$GNU_CC"; then
763   if test "$CPU_ARCH" = "arm" ; then
764     AC_CACHE_CHECK(for ARM EABI,
765         ac_cv_gcc_arm_eabi,
766         [AC_TRY_COMPILE([],
767                         [
768 #if defined(__ARM_EABI__)
769   return 0;
770 #else
771 #error Not ARM EABI.
772 #endif
773                         ],
774                         ac_cv_gcc_arm_eabi="yes",
775                         ac_cv_gcc_arm_eabi="no")])
776     if test "$ac_cv_gcc_arm_eabi" = "yes"; then
777         HAVE_ARM_EABI=1
778         ARM_ABI_PREFIX=eabi-
779     else
780         ARM_ABI_PREFIX=oabi-
781     fi
782   fi
784   TARGET_COMPILER_ABI="${TARGET_COMPILER_ABI-${ARM_ABI_PREFIX}gcc3}"
787 # try harder, when checking for __thread support, see bug 521750 comment #33 and below
788 # We pass MOZ_OPTIMIZE_LDFLAGS to the linker because if dead_strip is
789 # enabled, the linker in xcode 4.1 will crash. Without this it would crash when
790 # linking XUL.
791 _SAVE_LDFLAGS=$LDFLAGS
792 LDFLAGS="$LDFLAGS $DSO_LDOPTS $MOZ_OPTIMIZE_LDFLAGS"
793 AC_CACHE_CHECK(for __thread keyword for TLS variables,
794                ac_cv_thread_keyword,
795                [AC_TRY_LINK([__thread bool tlsIsMainThread = false;],
796                             [return tlsIsMainThread;],
797                             ac_cv_thread_keyword=yes,
798                             ac_cv_thread_keyword=no)])
799 LDFLAGS=$_SAVE_LDFLAGS
800 if test "$ac_cv_thread_keyword" = yes; then
801   # mips builds fail with TLS variables because of a binutils bug.
802   # See bug 528687
803   case "${target}" in
804     mips*-*)
805       :
806       ;;
807     *-android*|*-linuxandroid*)
808       :
809       ;;
810     *)
811       AC_DEFINE(HAVE_THREAD_TLS_KEYWORD)
812       ;;
813   esac
816 dnl End of C++ language/feature checks
817 AC_LANG_C
819 fi # ! SKIP_COMPILER_CHECKS
821 TARGET_XPCOM_ABI=
822 if test -n "${CPU_ARCH}" -a -n "${TARGET_COMPILER_ABI}"; then
823     TARGET_XPCOM_ABI="${CPU_ARCH}-${TARGET_COMPILER_ABI}"
826 dnl We can't run TRY_COMPILE tests on Windows, so hard-code some
827 dnl features that Windows actually does support.
829 if test -n "$SKIP_COMPILER_CHECKS"; then
830    dnl Windows has malloc.h
831    AC_DEFINE(MALLOC_H, [<malloc.h>])
832    AC_DEFINE(HAVE_FORCEINLINE)
833 fi # SKIP_COMPILER_CHECKS
835 dnl Mozilla specific options
836 dnl ========================================================
837 dnl The macros used for command line options
838 dnl are defined in build/autoconf/altoptions.m4.
840 dnl ========================================================
841 dnl = Enable code optimization. ON by default.
842 dnl ========================================================
844 # Use value from moz.configure if one is defined. Else use our computed
845 # value.
846 if test -n "${MOZ_CONFIGURE_OPTIMIZE_FLAGS}"; then
847     MOZ_OPTIMIZE_FLAGS=${MOZ_CONFIGURE_OPTIMIZE_FLAGS}
850 if test "$COMPILE_ENVIRONMENT"; then
851 if test -n "$MOZ_OPTIMIZE"; then
852     AC_MSG_CHECKING([for valid optimization flags])
853     _SAVE_CFLAGS=$CFLAGS
854     CFLAGS="$CFLAGS $MOZ_OPTIMIZE_FLAGS"
855     AC_TRY_COMPILE([#include <stdio.h>],
856         [printf("Hello World\n");],
857         _results=yes,
858         _results=no)
859     AC_MSG_RESULT([$_results])
860     if test "$_results" = "no"; then
861         AC_MSG_ERROR([These compiler flags are invalid: $MOZ_OPTIMIZE_FLAGS])
862     fi
863     CFLAGS=$_SAVE_CFLAGS
864     if test -n "$MOZ_LTO" -a -n "$CLANG_CC"; then
865         # When using llvm-based LTO, non numeric optimization levels are
866         # not supported by the linker, so force the linker to use -O2 (
867         # which doesn't influence the level compilation units are actually
868         # compiled at).
869         case " $MOZ_OPTIMIZE_FLAGS " in
870         *\ -Os\ *|*\ -Oz\ *)
871             MOZ_OPTIMIZE_LDFLAGS="$MOZ_OPTIMIZE_LDFLAGS -O2"
872             ;;
873         esac
874     fi
876 fi # COMPILE_ENVIRONMENT
878 AC_SUBST_LIST(MOZ_OPTIMIZE_FLAGS)
879 AC_SUBST_LIST(MOZ_OPTIMIZE_LDFLAGS)
880 AC_SUBST_LIST(MOZ_PGO_OPTIMIZE_FLAGS)
882 dnl ========================================================
883 dnl = Enable jemalloc
884 dnl ========================================================
886 if test "$JS_STANDALONE" -a -z "$MOZ_MEMORY"; then
887   MOZ_GLUE_IN_PROGRAM=
888 else
889   case "${OS_TARGET}" in
890   Android|WINNT|Darwin)
891     MOZ_GLUE_IN_PROGRAM=
892     ;;
893   *)
894     dnl On !Android !Windows !OSX, we only want to link executables against mozglue
895     MOZ_GLUE_IN_PROGRAM=1
896     AC_DEFINE(MOZ_GLUE_IN_PROGRAM)
897     ;;
898   esac
901 if test "$MOZ_MEMORY"; then
902   dnl The generic feature tests that determine how to compute ncpus are long and
903   dnl complicated.  Therefore, simply define special cpp variables for the
904   dnl platforms we have special knowledge of.
905   case "${target}" in
906   *-mingw*)
907     export MOZ_NO_DEBUG_RTL=1
908     ;;
909   esac
911 AC_SUBST(MOZ_GLUE_IN_PROGRAM)
913 dnl ========================================================
914 dnl instruments
915 dnl ========================================================
916 if test -n "$MOZ_INSTRUMENTS"; then
917     LIBS="$LIBS -framework CoreFoundation"
920 dnl ========================================================
921 dnl = Enable using the clang plugin to build
922 dnl ========================================================
924 if test -n "$COMPILE_ENVIRONMENT"; then
925 MOZ_CONFIG_CLANG_PLUGIN
926 fi # COMPILE_ENVIRONMENT
928 if test -z "$SKIP_COMPILER_CHECKS"; then
930 dnl ========================================================
931 dnl Check for gcc -pipe support
932 dnl ========================================================
933 AC_MSG_CHECKING([for -pipe support])
934 if test -n "$GNU_CC" -a -n "$GNU_CXX"; then
935     dnl Any gcc that supports firefox supports -pipe.
936     CFLAGS="$CFLAGS -pipe"
937     CXXFLAGS="$CXXFLAGS -pipe"
938     AC_MSG_RESULT([yes])
939 else
940     AC_MSG_RESULT([no])
943 fi # ! SKIP_COMPILER_CHECKS
945 MOZ_EXPAND_LIBS
947 dnl ========================================================
948 dnl =
949 dnl = Maintainer debug option (no --enable equivalent)
950 dnl =
951 dnl ========================================================
953 AC_SUBST_LIST(ASFLAGS)
954 AC_SUBST_LIST(MOZ_DEBUG_LDFLAGS)
956 AC_SUBST_LIST(MOZ_FIX_LINK_PATHS)
958 AC_SUBST(MOZ_POST_PROGRAM_COMMAND)
960 AC_SUBST(MOZ_APP_DISPLAYNAME)
962 AC_SUBST(MOZ_PKG_SPECIAL)
964 dnl Echo the CFLAGS to remove extra whitespace.
965 CFLAGS=`echo \
966         $_COMPILATION_CFLAGS \
967         $CFLAGS`
969 CXXFLAGS=`echo \
970         $_COMPILATION_CXXFLAGS \
971         $CXXFLAGS`
973 COMPILE_CFLAGS=`echo \
974     $_DEFINES_CFLAGS \
975     $COMPILE_CFLAGS`
977 COMPILE_CXXFLAGS=`echo \
978     $_DEFINES_CXXFLAGS \
979     $COMPILE_CXXFLAGS`
981 HOST_CFLAGS=`echo \
982     $_COMPILATION_HOST_CFLAGS \
983     $HOST_CFLAGS`
985 HOST_CXXFLAGS=`echo \
986     $_COMPILATION_HOST_CXXFLAGS \
987     $HOST_CXXFLAGS`
989 OS_CFLAGS="$CFLAGS"
990 OS_CXXFLAGS="$CXXFLAGS"
991 OS_CPPFLAGS="$CPPFLAGS"
992 OS_COMPILE_CFLAGS="$COMPILE_CFLAGS"
993 OS_COMPILE_CXXFLAGS="$COMPILE_CXXFLAGS"
994 OS_LDFLAGS="$LDFLAGS"
995 OS_LIBS="$LIBS"
996 AC_SUBST_LIST(OS_CFLAGS)
997 AC_SUBST_LIST(OS_CXXFLAGS)
998 AC_SUBST_LIST(OS_CPPFLAGS)
999 AC_SUBST_LIST(OS_COMPILE_CFLAGS)
1000 AC_SUBST_LIST(OS_COMPILE_CXXFLAGS)
1001 AC_SUBST_LIST(OS_LDFLAGS)
1002 AC_SUBST(OS_LIBS)
1004 AC_SUBST(HOST_CC)
1005 AC_SUBST(HOST_CXX)
1006 AC_SUBST_LIST(HOST_CFLAGS)
1007 AC_SUBST_LIST(HOST_CPPFLAGS)
1008 AC_SUBST_LIST(HOST_CXXFLAGS)
1009 AC_SUBST(HOST_LDFLAGS)
1010 AC_SUBST_LIST(HOST_OPTIMIZE_FLAGS)
1011 AC_SUBST(HOST_BIN_SUFFIX)
1013 AC_SUBST(TARGET_XPCOM_ABI)
1015 AC_SUBST(DSO_LDOPTS)
1016 AC_SUBST(BIN_SUFFIX)
1017 AC_SUBST(USE_N32)
1018 AC_SUBST(WIN32_CONSOLE_EXE_LDFLAGS)
1019 AC_SUBST(WIN32_GUI_EXE_LDFLAGS)
1021 dnl Set various defines and substitutions
1022 dnl ========================================================
1024 AC_SUBST(MOZ_DEV_EDITION)
1025 if test -n "$MOZ_DEV_EDITION"; then
1026     AC_DEFINE(MOZ_DEV_EDITION)
1029 dnl ========================================================
1030 dnl JavaScript shell
1031 dnl ========================================================
1033 MOZ_CHECK_ALLOCATOR
1035 if test -n "$JS_STANDALONE"; then
1036 JS_LIBRARY_NAME="mozjs-$MOZILLA_SYMBOLVERSION"
1037 else
1038 JS_LIBRARY_NAME="mozjs"
1040 JS_CONFIG_LIBS="$NSPR_LIBS $LIBS"
1041 if test -n "$GNU_CC"; then
1042 JS_CONFIG_MOZ_JS_LIBS='-L${libdir} -l${JS_LIBRARY_NAME}'
1043 else
1044 JS_CONFIG_MOZ_JS_LIBS='${libdir}/${JS_LIBRARY_NAME}.lib'
1046 AC_SUBST(JS_LIBRARY_NAME)
1047 AC_SUBST(JS_CONFIG_MOZ_JS_LIBS)
1048 AC_SUBST(JS_CONFIG_LIBS)
1050 # Avoid using obsolete NSPR features
1051 AC_DEFINE(NO_NSPR_10_SUPPORT)
1053 dnl Spit out some output
1054 dnl ========================================================
1055 MOZ_CREATE_CONFIG_STATUS()
1057 rm -fr confdefs* $ac_clean_files