xref: /netbsd-src/external/apache2/llvm/autoconf/autoconf/configure.ac (revision 53d1339bf7f9c7367b35a9e1ebe693f9b047a47b)
1dnl === configure.ac --------------------------------------------------------===
2dnl                     The LLVM Compiler Infrastructure
3dnl
4dnl This file is distributed under the University of Illinois Open Source
5dnl License. See LICENSE.TXT for details.
6dnl
7dnl===-----------------------------------------------------------------------===
8dnl This is the LLVM configuration script. It is processed by the autoconf
9dnl program to produce a script named configure. This script contains the
10dnl configuration checks that LLVM needs in order to support multiple platforms.
11dnl This file is composed of 10 sections per the recommended organization of
12dnl autoconf input defined in the autoconf documentation. As this file evolves,
13dnl please keep the various types of checks within their sections. The sections
14dnl are as follows:
15dnl
16dnl SECTION 1: Initialization & Setup
17dnl SECTION 2: Architecture, target, and host checks
18dnl SECTION 3: Command line arguments for the configure script.
19dnl SECTION 4: Check for programs we need and that they are the right version
20dnl SECTION 5: Check for libraries
21dnl SECTION 6: Check for header files
22dnl SECTION 7: Check for types and structures
23dnl SECTION 8: Check for specific functions needed
24dnl SECTION 9: Additional checks, variables, etc.
25dnl SECTION 10: Specify the output files and generate it
26dnl
27dnl===-----------------------------------------------------------------------===
28dnl===
29dnl=== SECTION 1: Initialization & Setup
30dnl===
31dnl===-----------------------------------------------------------------------===
32dnl Initialize autoconf and define the package name, version number and
33dnl address for reporting bugs.
34
35AC_INIT([LLVM],[4.0.0svn],[http://llvm.org/bugs/])
36
37LLVM_VERSION_MAJOR=4
38LLVM_VERSION_MINOR=0
39LLVM_VERSION_PATCH=0
40LLVM_VERSION_SUFFIX=svn
41
42AC_DEFINE_UNQUOTED([LLVM_VERSION_MAJOR], $LLVM_VERSION_MAJOR, [Major version of the LLVM API])
43AC_DEFINE_UNQUOTED([LLVM_VERSION_MINOR], $LLVM_VERSION_MINOR, [Minor version of the LLVM API])
44AC_DEFINE_UNQUOTED([LLVM_VERSION_PATCH], $LLVM_VERSION_PATCH, [Patch version of the LLVM API])
45AC_DEFINE_UNQUOTED([LLVM_VERSION_STRING], "$PACKAGE_VERSION", [LLVM version string])
46if false; then
47  AC_DEFINE_UNQUOTED([LLVM_VERSION_INFO], [], [LLVM version information])
48fi
49
50AC_SUBST([LLVM_VERSION_MAJOR])
51AC_SUBST([LLVM_VERSION_MINOR])
52AC_SUBST([LLVM_VERSION_PATCH])
53AC_SUBST([LLVM_VERSION_SUFFIX])
54
55dnl Provide a copyright substitution and ensure the copyright notice is included
56dnl in the output of --version option of the generated configure script.
57AC_SUBST(LLVM_COPYRIGHT,["Copyright (c) 2003-2015 University of Illinois at Urbana-Champaign."])
58AC_COPYRIGHT([Copyright (c) 2003-2015 University of Illinois at Urbana-Champaign.])
59
60dnl Indicate that we require autoconf 2.60 or later.
61AC_PREREQ(2.60)
62
63dnl Place all of the extra autoconf files into the config subdirectory. Tell
64dnl various tools where the m4 autoconf macros are.
65AC_CONFIG_AUX_DIR([autoconf])
66
67AC_ARG_WITH(llvm-srcdir,
68  AS_HELP_STRING([--with-llvm-srcdir],
69    [Directory to the out-of-tree LLVM source]),,
70    withval="-")
71case "$withval" in
72  -) llvm_srcdir="$srcdir" ;;
73  /* | [[A-Za-z]]:[[\\/]]*) llvm_srcdir="$withval" ;;
74  *) llvm_srcdir="$ac_pwd/$withval" ;;
75esac
76
77dnl Quit if the source directory has already been configured.
78dnl NOTE: This relies upon undocumented autoconf behavior.
79if test ${srcdir} != "." ; then
80  if test -f ${srcdir}/include/llvm/Config/config.h ; then
81    AC_MSG_ERROR([Already configured in ${srcdir}])
82  fi
83fi
84
85dnl Quit if it is an in-source build
86if test ${srcdir} = "." ; then
87  AC_MSG_ERROR([In-source builds are not allowed. Please configure from a separate build directory!])
88fi
89
90dnl Default to empty (i.e. assigning the null string to) CFLAGS and CXXFLAGS,
91dnl instead of the autoconf default (for example, '-g -O2' for CC=gcc).
92: ${CFLAGS=}
93: ${CXXFLAGS=}
94
95dnl We need to check for the compiler up here to avoid anything else
96dnl starting with a different one.
97AC_PROG_CC(clang gcc)
98AC_PROG_CXX(clang++ g++)
99AC_PROG_CPP
100
101dnl If CXX is Clang, check that it can find and parse C++ standard library
102dnl headers.
103if test "$CXX" = "clang++" ; then
104  AC_MSG_CHECKING([whether clang works])
105  AC_LANG_PUSH([C++])
106  dnl Note that space between 'include' and '(' is required.  There's a broken
107  dnl regex in aclocal that otherwise will think that we call m4's include
108  dnl builtin.
109  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <limits>
110#if __has_include (<cxxabi.h>)
111#include <cxxabi.h>
112#endif
113#if __has_include (<unwind.h>)
114#include <unwind.h>
115#endif
116]])],
117[
118  AC_MSG_RESULT([yes])
119],
120[
121  AC_MSG_RESULT([no])
122  AC_MSG_ERROR([Selected compiler could not find or parse C++ standard library headers.  Rerun with CC=c-compiler CXX=c++-compiler LLVM_SRC_DIR/configure ...])
123])
124  AC_LANG_POP([C++])
125fi
126
127dnl Set up variables that track whether the host compiler is GCC or Clang where
128dnl we can effectively sanity check them. We don't try to sanity check all the
129dnl other possible compilers.
130AC_MSG_CHECKING([whether GCC or Clang is our host compiler])
131AC_LANG_PUSH([C++])
132llvm_cv_cxx_compiler=unknown
133AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#if ! __clang__
134                                    #error
135                                    #endif
136                                    ]])],
137                  llvm_cv_cxx_compiler=clang,
138                  [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#if ! __GNUC__
139                                                       #error
140                                                       #endif
141                                                       ]])],
142                                     llvm_cv_cxx_compiler=gcc, [])])
143AC_LANG_POP([C++])
144AC_MSG_RESULT([${llvm_cv_cxx_compiler}])
145AC_SUBST(CXX_COMPILER,$llvm_cv_cxx_compiler)
146
147dnl Disable the build of polly, even if it is checked out into tools/polly.
148AC_ARG_ENABLE(polly,
149              AS_HELP_STRING([--enable-polly],
150                             [Use polly if available (default is YES)]),,
151                             enableval=default)
152case "$enableval" in
153  yes) AC_SUBST(ENABLE_POLLY,[1]) ;;
154  no)  AC_SUBST(ENABLE_POLLY,[0]) ;;
155  default) AC_SUBST(ENABLE_POLLY,[1]) ;;
156  *) AC_MSG_ERROR([Invalid setting for --enable-polly. Use "yes" or "no"]) ;;
157esac
158
159
160dnl Check if polly is checked out into tools/polly and configure it if
161dnl available.
162if (test -d ${srcdir}/tools/polly) && (test $ENABLE_POLLY -eq 1) ; then
163  AC_SUBST(LLVM_HAS_POLLY,1)
164  AC_CONFIG_SUBDIRS([tools/polly])
165fi
166if false; then
167AC_DEFINE([LINK_POLLY_INTO_TOOLS], [], [Define if we link Polly to the tools])
168fi
169
170dnl===-----------------------------------------------------------------------===
171dnl===
172dnl=== SECTION 2: Architecture, target, and host checks
173dnl===
174dnl===-----------------------------------------------------------------------===
175
176dnl Check the target for which we're compiling and the host that will do the
177dnl compilations. This will tell us which LLVM compiler will be used for
178dnl compiling SSA into object code. This needs to be done early because
179dnl following tests depend on it.
180AC_CANONICAL_TARGET
181
182dnl Determine the platform type and cache its value. This helps us configure
183dnl the System library to the correct build platform.
184AC_CACHE_CHECK([type of operating system we're going to host on],
185               [llvm_cv_os_type],
186[case $host in
187  *-*-aix*)
188    llvm_cv_link_all_option="-Wl,--whole-archive"
189    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
190    llvm_cv_os_type="AIX"
191    llvm_cv_platform_type="Unix" ;;
192  *-*-irix*)
193    llvm_cv_link_all_option="-Wl,--whole-archive"
194    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
195    llvm_cv_os_type="IRIX"
196    llvm_cv_platform_type="Unix" ;;
197  *-*-cygwin*)
198    llvm_cv_link_all_option="-Wl,--whole-archive"
199    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
200    llvm_cv_os_type="Cygwin"
201    llvm_cv_platform_type="Unix" ;;
202  *-*-darwin*)
203    llvm_cv_link_all_option="-Wl,-all_load"
204    llvm_cv_no_link_all_option="-Wl,-noall_load"
205    llvm_cv_os_type="Darwin"
206    llvm_cv_platform_type="Unix" ;;
207  *-*-minix*)
208    llvm_cv_link_all_option="-Wl,-all_load"
209    llvm_cv_no_link_all_option="-Wl,-noall_load"
210    llvm_cv_os_type="Minix"
211    llvm_cv_platform_type="Unix" ;;
212  *-*-freebsd*)
213    llvm_cv_link_all_option="-Wl,--whole-archive"
214    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
215    llvm_cv_os_type="FreeBSD"
216    llvm_cv_platform_type="Unix" ;;
217  *-*-kfreebsd-gnu)
218    llvm_cv_link_all_option="-Wl,--whole-archive"
219    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
220    llvm_cv_os_type="GNU/kFreeBSD"
221    llvm_cv_platform_type="Unix" ;;
222  *-*-openbsd*)
223    llvm_cv_link_all_option="-Wl,--whole-archive"
224    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
225    llvm_cv_os_type="OpenBSD"
226    llvm_cv_platform_type="Unix" ;;
227  *-*-netbsd*)
228    llvm_cv_link_all_option="-Wl,--whole-archive"
229    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
230    llvm_cv_os_type="NetBSD"
231    llvm_cv_platform_type="Unix" ;;
232  *-*-dragonfly*)
233    llvm_cv_link_all_option="-Wl,--whole-archive"
234    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
235    llvm_cv_os_type="DragonFly"
236    llvm_cv_platform_type="Unix" ;;
237  *-*-bitrig*)
238    llvm_cv_link_all_option="-Wl,--whole-archive"
239    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
240    llvm_cv_os_type="Bitrig"
241    llvm_cv_platform_type="Unix" ;;
242  *-*-hpux*)
243    llvm_cv_link_all_option="-Wl,--whole-archive"
244    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
245    llvm_cv_os_type="HP-UX"
246    llvm_cv_platform_type="Unix" ;;
247  *-*-interix*)
248    llvm_cv_link_all_option="-Wl,--whole-archive"
249    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
250    llvm_cv_os_type="Interix"
251    llvm_cv_platform_type="Unix" ;;
252  *-*-linux*)
253    llvm_cv_link_all_option="-Wl,--whole-archive"
254    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
255    llvm_cv_os_type="Linux"
256    llvm_cv_platform_type="Unix" ;;
257  *-*-gnu*)
258    llvm_cv_link_all_option="-Wl,--whole-archive"
259    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
260    llvm_cv_os_type="GNU"
261    llvm_cv_platform_type="Unix" ;;
262  *-*-solaris*)
263    llvm_cv_link_all_option="-Wl,-z,allextract"
264    llvm_cv_no_link_all_option="-Wl,-z,defaultextract"
265    llvm_cv_os_type="SunOS"
266    llvm_cv_platform_type="Unix" ;;
267  *-*-win32*)
268    llvm_cv_link_all_option="-Wl,--whole-archive"
269    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
270    llvm_cv_os_type="Win32"
271    llvm_cv_platform_type="Win32" ;;
272  *-*-mingw*)
273    llvm_cv_link_all_option="-Wl,--whole-archive"
274    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
275    llvm_cv_os_type="MingW"
276    llvm_cv_platform_type="Win32" ;;
277  *-*-haiku*)
278    llvm_cv_link_all_option="-Wl,--whole-archive"
279    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
280    llvm_cv_os_type="Haiku"
281    llvm_cv_platform_type="Unix" ;;
282  *-unknown-eabi*)
283    llvm_cv_link_all_option="-Wl,--whole-archive"
284    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
285    llvm_cv_os_type="Freestanding"
286    llvm_cv_platform_type="Unix" ;;
287  *-unknown-elf*)
288    llvm_cv_link_all_option="-Wl,--whole-archive"
289    llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
290    llvm_cv_os_type="Freestanding"
291    llvm_cv_platform_type="Unix" ;;
292  *)
293    llvm_cv_link_all_option=""
294    llvm_cv_no_link_all_option=""
295    llvm_cv_os_type="Unknown"
296    llvm_cv_platform_type="Unknown" ;;
297esac])
298
299AC_CACHE_CHECK([type of operating system we're going to target],
300               [llvm_cv_target_os_type],
301[case $target in
302  *-*-aix*)
303    llvm_cv_target_os_type="AIX" ;;
304  *-*-irix*)
305    llvm_cv_target_os_type="IRIX" ;;
306  *-*-cygwin*)
307    llvm_cv_target_os_type="Cygwin" ;;
308  *-*-darwin*)
309    llvm_cv_target_os_type="Darwin" ;;
310  *-*-minix*)
311    llvm_cv_target_os_type="Minix" ;;
312  *-*-freebsd*)
313    llvm_cv_target_os_type="FreeBSD" ;;
314  *-*-kfreebsd-gnu)
315    llvm_cv_target_os_type="GNU/kFreeBSD" ;;
316  *-*-openbsd*)
317    llvm_cv_target_os_type="OpenBSD" ;;
318  *-*-netbsd*)
319    llvm_cv_target_os_type="NetBSD" ;;
320  *-*-dragonfly*)
321    llvm_cv_target_os_type="DragonFly" ;;
322  *-*-bitrig*)
323    llvm_cv_target_os_type="Bitrig" ;;
324  *-*-hpux*)
325    llvm_cv_target_os_type="HP-UX" ;;
326  *-*-interix*)
327    llvm_cv_target_os_type="Interix" ;;
328  *-*-linux*)
329    llvm_cv_target_os_type="Linux" ;;
330  *-*-gnu*)
331    llvm_cv_target_os_type="GNU" ;;
332  *-*-solaris*)
333    llvm_cv_target_os_type="SunOS" ;;
334  *-*-win32*)
335    llvm_cv_target_os_type="Win32" ;;
336  *-*-mingw*)
337    llvm_cv_target_os_type="MingW" ;;
338  *-*-haiku*)
339    llvm_cv_target_os_type="Haiku" ;;
340  *-*-rtems*)
341    llvm_cv_target_os_type="RTEMS" ;;
342  *-*-nacl*)
343    llvm_cv_target_os_type="NativeClient" ;;
344  *-unknown-eabi*)
345    llvm_cv_target_os_type="Freestanding" ;;
346  *-*-ps4)
347    llvm_cv_target_os_type="PS4" ;;
348  *)
349    llvm_cv_target_os_type="Unknown" ;;
350esac])
351
352dnl Make sure we aren't attempting to configure for an unknown system
353if test "$llvm_cv_os_type" = "Unknown" ; then
354  AC_MSG_ERROR([Operating system is unknown, configure can't continue])
355fi
356
357dnl Set the "OS" Makefile variable based on the platform type so the
358dnl makefile can configure itself to specific build hosts
359AC_SUBST(OS,$llvm_cv_os_type)
360AC_SUBST(HOST_OS,$llvm_cv_os_type)
361AC_SUBST(TARGET_OS,$llvm_cv_target_os_type)
362
363dnl Set the LINKALL and NOLINKALL Makefile variables based on the platform
364AC_SUBST(LINKALL,$llvm_cv_link_all_option)
365AC_SUBST(NOLINKALL,$llvm_cv_no_link_all_option)
366
367dnl Set the "LLVM_ON_*" variables based on llvm_cv_platform_type
368dnl This is used by lib/Support to determine the basic kind of implementation
369dnl to use.
370case $llvm_cv_platform_type in
371  Unix)
372    AC_DEFINE([LLVM_ON_UNIX],[1],[Define if this is Unixish platform])
373    AC_SUBST(LLVM_ON_UNIX,[1])
374    AC_SUBST(LLVM_ON_WIN32,[0])
375    ;;
376  Win32)
377    AC_DEFINE([LLVM_ON_WIN32],[1],[Define if this is Win32ish platform])
378    AC_SUBST(LLVM_ON_UNIX,[0])
379    AC_SUBST(LLVM_ON_WIN32,[1])
380    ;;
381esac
382
383dnl Determine what our target architecture is and configure accordingly.
384dnl This will allow Makefiles to make a distinction between the hardware and
385dnl the OS.
386AC_CACHE_CHECK([target architecture],[llvm_cv_target_arch],
387[case $target in
388  i?86-*)                 llvm_cv_target_arch="x86" ;;
389  amd64-* | x86_64-*)     llvm_cv_target_arch="x86_64" ;;
390  sparc*-*)               llvm_cv_target_arch="Sparc" ;;
391  powerpc*-*)             llvm_cv_target_arch="PowerPC" ;;
392  arm64*-*)               llvm_cv_target_arch="AArch64" ;;
393  arm*-*)                 llvm_cv_target_arch="ARM" ;;
394  aarch64*-*)             llvm_cv_target_arch="AArch64" ;;
395  avr-*)                  llvm_cv_target_arch="AVR" ;;
396  mips-* | mips64-*)      llvm_cv_target_arch="Mips" ;;
397  mipsel-* | mips64el-*)  llvm_cv_target_arch="Mips" ;;
398  xcore-*)                llvm_cv_target_arch="XCore" ;;
399  msp430-*)               llvm_cv_target_arch="MSP430" ;;
400  hexagon-*)              llvm_cv_target_arch="Hexagon" ;;
401  nvptx-*)                llvm_cv_target_arch="NVPTX" ;;
402  s390x-*)                llvm_cv_target_arch="SystemZ" ;;
403  wasm*-*)                llvm_cv_target_arch="WebAssembly" ;;
404  *)                      llvm_cv_target_arch="Unknown" ;;
405esac])
406
407if test "$llvm_cv_target_arch" = "Unknown" ; then
408  AC_MSG_WARN([Configuring LLVM for an unknown target archicture])
409fi
410
411dnl Determine the LLVM native architecture for the target
412case "$llvm_cv_target_arch" in
413    x86)     LLVM_NATIVE_ARCH="X86" ;;
414    x86_64)  LLVM_NATIVE_ARCH="X86" ;;
415    *)       LLVM_NATIVE_ARCH="$llvm_cv_target_arch" ;;
416esac
417
418dnl Define a substitution, ARCH, for the target architecture
419AC_SUBST(ARCH,$llvm_cv_target_arch)
420AC_SUBST(LLVM_NATIVE_ARCH,$LLVM_NATIVE_ARCH)
421
422dnl Determine what our host architecture.
423dnl This will allow MCJIT regress tests runs only for supported
424dnl platforms.
425case $host in
426  i?86-*)                 host_arch="x86" ;;
427  amd64-* | x86_64-*)     host_arch="x86_64" ;;
428  sparc*-*)               host_arch="Sparc" ;;
429  powerpc*-*)             host_arch="PowerPC" ;;
430  arm64*-*)               host_arch="AArch64" ;;
431  arm*-*)                 host_arch="ARM" ;;
432  aarch64*-*)             host_arch="AArch64" ;;
433  avr-*)                  host_arch="AVR" ;;
434  mips-* | mips64-*)      host_arch="Mips" ;;
435  mipsel-* | mips64el-*)  host_arch="Mips" ;;
436  xcore-*)                host_arch="XCore" ;;
437  msp430-*)               host_arch="MSP430" ;;
438  hexagon-*)              host_arch="Hexagon" ;;
439  s390x-*)                host_arch="SystemZ" ;;
440  wasm*-*)                host_arch="WebAssembly" ;;
441  *)                      host_arch="Unknown" ;;
442esac
443
444if test "$host_arch" = "Unknown" ; then
445  AC_MSG_WARN([Configuring LLVM for an unknown host archicture])
446fi
447
448AC_SUBST(HOST_ARCH,$host_arch)
449
450dnl Check for build platform executable suffix if we're cross-compiling
451if test "$cross_compiling" = yes; then
452  AC_SUBST(LLVM_CROSS_COMPILING, [1])
453  AC_BUILD_EXEEXT
454  ac_build_prefix=${build_alias}-
455  AC_CHECK_PROG(BUILD_CXX, ${ac_build_prefix}g++, ${ac_build_prefix}g++)
456  if test -z "$BUILD_CXX"; then
457     AC_CHECK_PROG(BUILD_CXX, g++, g++)
458     if test -z "$BUILD_CXX"; then
459       AC_CHECK_PROG(BUILD_CXX, c++, c++, , , /usr/ucb/c++)
460     fi
461  fi
462else
463  AC_SUBST(LLVM_CROSS_COMPILING, [0])
464fi
465
466dnl Check to see if there's a .svn or .git directory indicating that this
467dnl build is being done from a checkout. This sets up several defaults for
468dnl the command line switches. When we build with a checkout directory,
469dnl we get a debug with assertions turned on. Without, we assume a source
470dnl release and we get an optimized build without assertions.
471dnl See --enable-optimized and --enable-assertions below
472if test -d ".svn" -o -d "${srcdir}/.svn" -o -d ".git" -o -d "${srcdir}/.git"; then
473  cvsbuild="yes"
474  optimize="no"
475  AC_SUBST(CVSBUILD,[[CVSBUILD=1]])
476else
477  cvsbuild="no"
478  optimize="yes"
479fi
480
481dnl===-----------------------------------------------------------------------===
482dnl===
483dnl=== SECTION 3: Command line arguments for the configure script.
484dnl===
485dnl===-----------------------------------------------------------------------===
486
487dnl --enable-libcpp : check whether or not to use libc++ on the command line
488AC_ARG_ENABLE(libcpp,
489              AS_HELP_STRING([--enable-libcpp],
490                             [Use libc++ if available (default is NO)]),,
491                             enableval=default)
492case "$enableval" in
493  yes) AC_SUBST(ENABLE_LIBCPP,[1]) ;;
494  no)  AC_SUBST(ENABLE_LIBCPP,[0]) ;;
495  default) AC_SUBST(ENABLE_LIBCPP,[0]);;
496  *) AC_MSG_ERROR([Invalid setting for --enable-libcpp. Use "yes" or "no"]) ;;
497esac
498
499dnl Check both GCC and Clang for sufficiently modern versions. These checks can
500dnl be bypassed by passing a flag if necessary on a platform. We have to do
501dnl these checks here so that we have the configuration of the standard C++
502dnl library finished.
503AC_ARG_ENABLE(compiler-version-checks,
504              AS_HELP_STRING([--enable-compiler-version-checks],
505                             [Check the version of the host compiler (default is YES)]),,
506                             enableval=default)
507case "$enableval" in
508  no)
509    ;;
510  yes|default)
511    AC_LANG_PUSH([C++])
512    case "$llvm_cv_cxx_compiler" in
513    clang)
514      AC_MSG_CHECKING([whether Clang is new enough])
515      AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
516#if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 1)
517#error This version of Clang is too old to build LLVM
518#endif
519]])],
520          [AC_MSG_RESULT([yes])],
521          [AC_MSG_RESULT([no])
522           AC_MSG_ERROR([
523The selected Clang compiler is not new enough to build LLVM. Please upgrade to
524Clang 3.1. You may pass --disable-compiler-version-checks to configure to
525bypass these sanity checks.])])
526
527      dnl Note that libstdc++4.6 is known broken for C++11 builds. The errors
528      dnl are sometimes deeply confusing though. Here we test for an obvious
529      dnl incomplete feature in 4.6's standard library that was completed in
530      dnl 4.7's. We also have to disable this test if 'ENABLE_LIBCPP' is set
531      dnl because the enable flags don't actually fix CXXFLAGS, they rely on
532      dnl that happening in the Makefile.
533      if test "$ENABLE_LIBCPP" -eq 0 ; then
534        AC_MSG_CHECKING([whether Clang will select a modern C++ standard library])
535        llvm_cv_old_cxxflags="$CXXFLAGS"
536        CXXFLAGS="$CXXFLAGS -std=c++0x"
537        AC_LINK_IFELSE([AC_LANG_SOURCE([[
538#include <atomic>
539std::atomic<float> x(0.0f);
540int main() { return (float)x; }
541]])],
542            [AC_MSG_RESULT([yes])],
543            [AC_MSG_RESULT([no])
544             AC_MSG_ERROR([
545We detected a missing feature in the standard C++ library that was known to be
546missing in libstdc++4.6 and implemented in libstdc++4.7. There are numerous
547C++11 problems with 4.6's library, and we don't support GCCs or libstdc++ older
548than 4.7. You will need to update your system and ensure Clang uses the newer
549standard library.
550
551If this error is incorrect or you need to force things to work, you may pass
552'--disable-compiler-version-checks' to configure to bypass this test.])])
553        CXXFLAGS="$llvm_cv_old_cxxflags"
554      fi
555      ;;
556    gcc)
557      AC_MSG_CHECKING([whether GCC is new enough])
558      AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
559#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
560#error This version of GCC is too old to build LLVM
561#endif
562]])],
563          [AC_MSG_RESULT([yes])],
564          [AC_MSG_RESULT([no])
565           AC_MSG_ERROR([
566The selected GCC C++ compiler is not new enough to build LLVM. Please upgrade
567to GCC 4.7. You may pass --disable-compiler-version-checks to configure to
568bypass these sanity checks.])])
569      ;;
570    unknown)
571      ;;
572    esac
573    AC_LANG_POP([C++])
574    ;;
575  *)
576    AC_MSG_ERROR([Invalid setting for --enable-compiler-version-checks. Use "yes" or "no"])
577    ;;
578esac
579
580dnl --enable-cxx1y : check whether or not to use -std=c++1y on the command line
581AC_ARG_ENABLE(cxx1y,
582              AS_HELP_STRING([--enable-cxx1y],
583                             [Use c++1y if available (default is NO)]),,
584                             enableval=default)
585case "$enableval" in
586  yes) AC_SUBST(ENABLE_CXX1Y,[1]) ;;
587  no)  AC_SUBST(ENABLE_CXX1Y,[0]) ;;
588  default) AC_SUBST(ENABLE_CXX1Y,[0]);;
589  *) AC_MSG_ERROR([Invalid setting for --enable-cxx1y. Use "yes" or "no"]) ;;
590esac
591
592dnl --enable-split-dwarf : check whether or not to use -gsplit-dwarf on the command
593dnl line
594AC_ARG_ENABLE(split-dwarf,
595              AS_HELP_STRING([--enable-split-dwarf],
596                             [Use split-dwarf if available (default is NO)]),,
597                             enableval=default)
598case "$enableval" in
599  yes) AC_SUBST(ENABLE_SPLIT_DWARF,[1]) ;;
600  no)  AC_SUBST(ENABLE_SPLIT_DWARF,[0]) ;;
601  default) AC_SUBST(ENABLE_SPLIT_DWARF,[0]);;
602  *) AC_MSG_ERROR([Invalid setting for --enable-split-dwarf. Use "yes" or "no"]) ;;
603esac
604
605dnl --enable-clang-arcmt: check whether to enable clang arcmt
606clang_arcmt="yes"
607AC_ARG_ENABLE(clang-arcmt,
608              AS_HELP_STRING([--enable-clang-arcmt],
609                             [Enable building of clang ARCMT (default is YES)]),
610                             clang_arcmt="$enableval",
611                             enableval="yes")
612case "$enableval" in
613  yes) AC_SUBST(ENABLE_CLANG_ARCMT,[1]) ;;
614  no)  AC_SUBST(ENABLE_CLANG_ARCMT,[0]) ;;
615  default) AC_SUBST(ENABLE_CLANG_ARCMT,[1]);;
616  *) AC_MSG_ERROR([Invalid setting for --enable-clang-arcmt. Use "yes" or "no"]) ;;
617esac
618
619dnl --enable-clang-plugin-support: check whether to enable plugins in clang
620clang_plugin_support="yes"
621AC_ARG_ENABLE(clang-plugin-support,
622              AS_HELP_STRING([--enable-clang-plugin-support],
623                             [Enable plugin support in clang (default is YES)]),
624                             clang_plugin_support="$enableval",
625                             enableval="yes")
626case "$enableval" in
627  yes) AC_SUBST(CLANG_PLUGIN_SUPPORT,[1]) ;;
628  no)  AC_SUBST(CLANG_PLUGIN_SUPPORT,[0]) ;;
629  default) AC_SUBST(CLANG_PLUGIN_SUPPORT,[1]);;
630  *) AC_MSG_ERROR([Invalid setting for --enable-clang-plugin-support. Use "yes" or "no"]) ;;
631esac
632
633dnl --enable-clang-static-analyzer: check whether to enable static-analyzer
634clang_static_analyzer="yes"
635AC_ARG_ENABLE(clang-static-analyzer,
636              AS_HELP_STRING([--enable-clang-static-analyzer],
637                             [Enable building of clang Static Analyzer (default is YES)]),
638                             clang_static_analyzer="$enableval",
639                             enableval="yes")
640case "$enableval" in
641  yes) AC_SUBST(ENABLE_CLANG_STATIC_ANALYZER,[1]) ;;
642  no)
643    if test ${clang_arcmt} != "no" ; then
644      AC_MSG_ERROR([Cannot enable clang ARC Migration Tool while disabling static analyzer.])
645    fi
646    AC_SUBST(ENABLE_CLANG_STATIC_ANALYZER,[0])
647    ;;
648  default) AC_SUBST(ENABLE_CLANG_STATIC_ANALYZER,[1]);;
649  *) AC_MSG_ERROR([Invalid setting for --enable-clang-static-analyzer. Use "yes" or "no"]) ;;
650esac
651
652dnl --enable-optimized : check whether they want to do an optimized build:
653AC_ARG_ENABLE(optimized, AS_HELP_STRING(
654 --enable-optimized,[Compile with optimizations enabled (default is NO)]),,enableval=$optimize)
655if test ${enableval} = "no" ; then
656  AC_SUBST(ENABLE_OPTIMIZED,[[]])
657else
658  AC_SUBST(ENABLE_OPTIMIZED,[[ENABLE_OPTIMIZED=1]])
659fi
660
661dnl --enable-profiling : check whether they want to do a profile build:
662AC_ARG_ENABLE(profiling, AS_HELP_STRING(
663 --enable-profiling,[Compile with profiling enabled (default is NO)]),,enableval="no")
664if test ${enableval} = "no" ; then
665  AC_SUBST(ENABLE_PROFILING,[[]])
666else
667  AC_SUBST(ENABLE_PROFILING,[[ENABLE_PROFILING=1]])
668fi
669
670dnl --enable-assertions : check whether they want to turn on assertions or not:
671AC_ARG_ENABLE(assertions,AS_HELP_STRING(
672  --enable-assertions,[Compile with assertion checks enabled (default is YES)]),, enableval="yes")
673if test ${enableval} = "yes" ; then
674  AC_SUBST(DISABLE_ASSERTIONS,[[]])
675  assertions_enabled="yes"
676else
677  AC_SUBST(DISABLE_ASSERTIONS,[[DISABLE_ASSERTIONS=1]])
678  assertions_enabled="no"
679fi
680
681dnl --enable-werror : check whether we want Werror on by default
682AC_ARG_ENABLE(werror,AS_HELP_STRING(
683  --enable-werror,[Compile with -Werror enabled (default is NO)]),, enableval="no")
684case "$enableval" in
685  yes) AC_SUBST(ENABLE_WERROR,[1]) ;;
686  no)  AC_SUBST(ENABLE_WERROR,[0]) ;;
687  default) AC_SUBST(ENABLE_WERROR,[0]);;
688  *) AC_MSG_ERROR([Invalid setting for --enable-werror. Use "yes" or "no"]) ;;
689esac
690
691dnl --enable-expensive-checks : check whether they want to turn on expensive debug checks:
692AC_ARG_ENABLE(expensive-checks,AS_HELP_STRING(
693  --enable-expensive-checks,[Compile with expensive debug checks enabled (default is NO)]),, enableval="no")
694if test ${enableval} = "yes" ; then
695  AC_SUBST(ENABLE_EXPENSIVE_CHECKS,[[ENABLE_EXPENSIVE_CHECKS=1]])
696  AC_SUBST(EXPENSIVE_CHECKS,[[yes]])
697else
698  AC_SUBST(ENABLE_EXPENSIVE_CHECKS,[[]])
699  AC_SUBST(EXPENSIVE_CHECKS,[[no]])
700fi
701
702dnl --enable-abi-breaking-checks : decide whether we should compile in asserts and
703dnl checks that make the build ABI incompatible with an llvm built without these
704dnl checks enabled.
705AC_ARG_ENABLE(abi-breaking-checks,AS_HELP_STRING(
706  --enable-abi-breaking-checks,[Compile with abi-breaking asserts support (default is with-asserts)]),, enableval="with-asserts")
707case "$enableval" in
708  with-asserts)  if test ${assertions_enabled} = "yes" ; then
709                   ENABLE_ABI_BREAKING_CHECKS=1
710                 else
711                   ENABLE_ABI_BREAKING_CHECKS=0
712		 fi ;;
713  yes)
714                 ENABLE_ABI_BREAKING_CHECKS=1
715                 ;;
716  no)
717                 ENABLE_ABI_BREAKING_CHECKS=0
718                 ;;
719  *) AC_MSG_ERROR([Invalid setting for --enable-abi-breaking-checks.  Use "with-asserts", "yes" or "no"])
720esac
721AC_SUBST(ENABLE_ABI_BREAKING_CHECKS,[$ENABLE_ABI_BREAKING_CHECKS])
722AC_DEFINE_UNQUOTED([LLVM_ENABLE_ABI_BREAKING_CHECKS],
723                   [$ENABLE_ABI_BREAKING_CHECKS],
724                   [Define to enable checks that alter the LLVM C++ ABI])
725
726dnl --enable-debug-runtime : should runtime libraries have debug symbols?
727AC_ARG_ENABLE(debug-runtime,
728   AS_HELP_STRING(--enable-debug-runtime,[Build runtime libs with debug symbols (default is NO)]),,enableval=no)
729if test ${enableval} = "no" ; then
730  AC_SUBST(DEBUG_RUNTIME,[[]])
731else
732  AC_SUBST(DEBUG_RUNTIME,[[DEBUG_RUNTIME=1]])
733fi
734
735dnl --enable-debug-symbols : should even optimized compiler libraries
736dnl have debug symbols?
737AC_ARG_ENABLE(debug-symbols,
738   AS_HELP_STRING(--enable-debug-symbols,[Build compiler with debug symbols (default is NO if optimization is on and YES if it's off)]),,enableval=no)
739if test ${enableval} = "no" ; then
740  AC_SUBST(DEBUG_SYMBOLS,[[]])
741else
742  AC_SUBST(DEBUG_SYMBOLS,[[DEBUG_SYMBOLS=1]])
743fi
744
745dnl --enable-keep-symbols : do not strip installed executables
746AC_ARG_ENABLE(keep-symbols,
747   AS_HELP_STRING(--enable-keep-symbols,[Do not strip installed executables)]),,enableval=no)
748if test ${enableval} = "no" ; then
749  AC_SUBST(KEEP_SYMBOLS,[[]])
750else
751  AC_SUBST(KEEP_SYMBOLS,[[KEEP_SYMBOLS=1]])
752fi
753
754dnl --enable-jit: check whether they want to enable the jit
755AC_ARG_ENABLE(jit,
756  AS_HELP_STRING(--enable-jit,
757                 [Enable Just In Time Compiling (default is YES)]),,
758  enableval=default)
759if test ${enableval} = "no"
760then
761  AC_SUBST(JIT,[[]])
762else
763  case "$llvm_cv_target_arch" in
764    x86)         AC_SUBST(TARGET_HAS_JIT,1) ;;
765    Sparc)       AC_SUBST(TARGET_HAS_JIT,0) ;;
766    PowerPC)     AC_SUBST(TARGET_HAS_JIT,1) ;;
767    x86_64)      AC_SUBST(TARGET_HAS_JIT,1) ;;
768    ARM)         AC_SUBST(TARGET_HAS_JIT,1) ;;
769    AVR)         AC_SUBST(TARGET_HAS_JIT,0) ;;
770    Mips)        AC_SUBST(TARGET_HAS_JIT,1) ;;
771    XCore)       AC_SUBST(TARGET_HAS_JIT,0) ;;
772    MSP430)      AC_SUBST(TARGET_HAS_JIT,0) ;;
773    Hexagon)     AC_SUBST(TARGET_HAS_JIT,0) ;;
774    NVPTX)       AC_SUBST(TARGET_HAS_JIT,0) ;;
775    SystemZ)     AC_SUBST(TARGET_HAS_JIT,1) ;;
776    WebAssembly) AC_SUBST(TARGET_HAS_JIT,0) ;;
777    *)           AC_SUBST(TARGET_HAS_JIT,0) ;;
778  esac
779fi
780
781TARGETS_WITH_JIT="ARM AArch64 Mips PowerPC SystemZ X86"
782AC_SUBST(TARGETS_WITH_JIT,$TARGETS_WITH_JIT)
783
784dnl Allow enablement of building and installing docs
785AC_ARG_ENABLE(docs,
786              AS_HELP_STRING([--enable-docs],
787                             [Build documents (default is YES)]),,
788                             enableval=default)
789case "$enableval" in
790  yes) AC_SUBST(ENABLE_DOCS,[1]) ;;
791  no)  AC_SUBST(ENABLE_DOCS,[0]) ;;
792  default) AC_SUBST(ENABLE_DOCS,[1]) ;;
793  *) AC_MSG_ERROR([Invalid setting for --enable-docs. Use "yes" or "no"]) ;;
794esac
795
796dnl Allow enablement of doxygen generated documentation
797AC_ARG_ENABLE(doxygen,
798              AS_HELP_STRING([--enable-doxygen],
799                             [Build doxygen documentation (default is NO)]),,
800                             enableval=default)
801case "$enableval" in
802  yes) AC_SUBST(ENABLE_DOXYGEN,[1]) ;;
803  no|default) AC_SUBST(ENABLE_DOXYGEN,[0]) ;;
804  *) AC_MSG_ERROR([Invalid setting for --enable-doxygen. Use "yes" or "no"]) ;;
805esac
806
807dnl Allow enablement of doxygen search engine
808AC_ARG_ENABLE(doxygen-search,
809              AS_HELP_STRING([--enable-doxygen-search],
810                             [Enable doxygen search support (default is NO)]),,
811                             enableval=default)
812ENABLE_DOXYGEN_SEARCH="$enableval"
813
814case "$enableval" in
815  yes|no|default) ;;
816  *) AC_MSG_ERROR([Invalid setting for --enable-doxygen-search. Use "yes" or "no"]) ;;
817esac
818
819AC_ARG_ENABLE(doxygen-external-search,
820              AS_HELP_STRING([--enable-doxygen-external-search],
821                             [Enable doxygen exteranl search (default is NO)]),,
822                             enableval=default)
823ENABLE_DOXYGEN_EXTERNAL_SEARCH="$enableval"
824
825case "$enableval" in
826  yes)
827    dnl To match with the CMake behavior, enable doxygen when
828    dnl --enable-doxygen-external-search is enabled.
829    case "$ENABLE_DOXYGEN_SEARCH" in
830      yes|default) ENABLE_DOXYGEN_SEARCH="yes" ;;
831      no) AC_MSG_ERROR([The option --enable-doxygen-external-search requires --enable-doxygen-search]) ;;
832    esac
833    ;;
834  no|default) ;;
835  *) AC_MSG_ERROR([Invalid setting for --enable-doxygen-external-search. Use "yes" or "no"]) ;;
836esac
837
838AC_ARG_WITH(doxygen-search-engine-url,
839            AS_HELP_STRING([--with-doxygen-search-engine-url],
840                           [Specify the external search engine for doxygen]),,)
841WITH_DOXYGEN_SEARCH_ENGINE_URL="$withval"
842
843AC_ARG_WITH(doxygen-search-mappings,
844            AS_HELP_STRING([--with-doxygen-search-mappings],
845                           [Specify the extra search mapping for doxygen]),,)
846WITH_DOXYGEN_SEARCH_MAPPINGS="$withval"
847
848case "$ENABLE_DOXYGEN_SEARCH" in
849  yes)
850    if test "$ENABLE_DOXYGEN" = "0" ; then
851      AC_MSG_ERROR([The option --enable-doxygen-search requires --enable-doxygen.])
852    fi
853
854    AC_SUBST(enable_searchengine,[YES])
855
856    case "$ENABLE_DOXYGEN_EXTERNAL_SEARCH" in
857      yes)
858        AC_SUBST(enable_external_search,[YES])
859        AC_SUBST(enable_server_based_search,[YES])
860        AC_SUBST(searchengine_url,["$WITH_DOXYGEN_SEARCH_ENGINE_URL"])
861        AC_SUBST(extra_search_mappings,["$WITH_DOXYGEN_SEARCH_MAPPINGS"])
862        ;;
863
864      no|default)
865        AC_SUBST(enable_external_search,[NO])
866        AC_SUBST(enable_server_based_search,[NO])
867        AC_SUBST(searchengine_url,[])
868        AC_SUBST(extra_search_mappings,[])
869        ;;
870    esac
871    ;;
872
873  no|default)
874    AC_SUBST(enable_searchengine,[NO])
875    AC_SUBST(searchengine_url,[])
876    AC_SUBST(enable_server_based_search,[NO])
877    AC_SUBST(enable_external_search,[NO])
878    AC_SUBST(extra_search_mappings,[])
879    ;;
880
881  *)
882    AC_MSG_ERROR([Invalid setting for --enable-doxygen-search. Use "yes" or "no"])
883    ;;
884esac
885
886dnl Allow enablement of doxygen generated Qt help files
887AC_ARG_ENABLE(doxygen-qt-help,
888	      AS_HELP_STRING([--enable-doxygen-qt-help],
889			     [Build Qt help files (default is NO)]),,
890			     enableval=default)
891case "$enableval" in
892  yes)
893    if test "$ENABLE_DOXYGEN" = "0" ; then
894      AC_MSG_ERROR([The option --enable-doxygen-qt-help requires --enable-doxygen.])
895    fi
896
897    AC_PATH_PROG(QHELPGENERATOR, [qhelpgenerator], [qhelpgenerator])
898
899    dnl Qt help file for llvm doxygen documentation
900    AC_SUBST(llvm_doxygen_generate_qhp,[YES])
901    AC_SUBST(llvm_doxygen_qch_filename,[org.llvm.qch])
902    AC_SUBST(llvm_doxygen_qhp_namespace,[org.llvm])
903    AC_SUBST(llvm_doxygen_qhelpgenerator_path,["$QHELPGENERATOR"])
904    AC_SUBST(llvm_doxygen_qhp_cust_filter_name,["$PACKAGE_STRING"])
905    AC_SUBST(llvm_doxygen_qhp_cust_filter_attrs,["$PACKAGE_NAME,$PACKAGE_VERSION"])
906
907    dnl Qt help file for clang doxygen documentation
908    AC_SUBST(clang_doxygen_generate_qhp,[YES])
909    AC_SUBST(clang_doxygen_qch_filename,[org.llvm.clang.qch])
910    AC_SUBST(clang_doxygen_qhp_namespace,[org.llvm.clang])
911    AC_SUBST(clang_doxygen_qhelpgenerator_path,["$QHELPGENERATOR"])
912    AC_SUBST(clang_doxygen_qhp_cust_filter_name,["Clang $PACKAGE_VERSION"])
913    AC_SUBST(clang_doxygen_qhp_cust_filter_attrs,["Clang,$PACKAGE_VERSION"])
914    ;;
915
916  no|default)
917    AC_SUBST(llvm_doxygen_generate_qhp,[NO])
918    AC_SUBST(llvm_doxygen_qch_filename,[])
919    AC_SUBST(llvm_doxygen_qhp_namespace,[])
920    AC_SUBST(llvm_doxygen_qhelpgenerator_path,[])
921    AC_SUBST(llvm_doxygen_qhp_cust_filter_name,[])
922    AC_SUBST(llvm_doxygen_qhp_cust_filter_attrs,[])
923
924    AC_SUBST(clang_doxygen_generate_qhp,[NO])
925    AC_SUBST(clang_doxygen_qch_filename,[])
926    AC_SUBST(clang_doxygen_qhp_namespace,[])
927    AC_SUBST(clang_doxygen_qhelpgenerator_path,[])
928    AC_SUBST(clang_doxygen_qhp_cust_filter_name,["Clang $PACKAGE_VERSION"])
929    AC_SUBST(clang_doxygen_qhp_cust_filter_attrs,["Clang,$PACKAGE_VERSION"])
930    ;;
931
932  *)
933    AC_MSG_ERROR([Invalid setting for --enable-doxygen-qt-help. Use "yes" or "no"]) ;;
934esac
935
936dnl Allow disablement of threads
937AC_ARG_ENABLE(threads,
938              AS_HELP_STRING([--enable-threads],
939                             [Use threads if available (default is YES)]),,
940                             enableval=default)
941case "$enableval" in
942  yes) AC_SUBST(LLVM_ENABLE_THREADS,[1]) ;;
943  no)  AC_SUBST(LLVM_ENABLE_THREADS,[0]) ;;
944  default) AC_SUBST(LLVM_ENABLE_THREADS,[1]) ;;
945  *) AC_MSG_ERROR([Invalid setting for --enable-threads. Use "yes" or "no"]) ;;
946esac
947AC_DEFINE_UNQUOTED([LLVM_ENABLE_THREADS],$LLVM_ENABLE_THREADS,
948                   [Define if threads enabled])
949
950dnl Allow disablement of pthread.h
951AC_ARG_ENABLE(pthreads,
952              AS_HELP_STRING([--enable-pthreads],
953                             [Use pthreads if available (default is YES)]),,
954                             enableval=default)
955case "$enableval" in
956  yes) AC_SUBST(ENABLE_PTHREADS,[1]) ;;
957  no)  AC_SUBST(ENABLE_PTHREADS,[0]) ;;
958  default) AC_SUBST(ENABLE_PTHREADS,[1]) ;;
959  *) AC_MSG_ERROR([Invalid setting for --enable-pthreads. Use "yes" or "no"]) ;;
960esac
961
962dnl Allow disablement of zlib
963AC_ARG_ENABLE(zlib,
964              AS_HELP_STRING([--enable-zlib],
965                             [Use zlib for compression/decompression if
966                              available (default is YES)]),,
967                              enableval=default)
968case "$enableval" in
969  yes) AC_SUBST(LLVM_ENABLE_ZLIB,[1]) ;;
970  no)  AC_SUBST(LLVM_ENABLE_ZLIB,[0]) ;;
971  default) AC_SUBST(LLVM_ENABLE_ZLIB,[1]) ;;
972  *) AC_MSG_ERROR([Invalid setting for --enable-zlib. Use "yes" or "no"]) ;;
973esac
974AC_DEFINE_UNQUOTED([LLVM_ENABLE_ZLIB],$LLVM_ENABLE_ZLIB,
975                   [Define if zlib compression is available])
976
977dnl Allow building a shared library and linking tools against it.
978AC_ARG_ENABLE(shared,
979  AS_HELP_STRING([--enable-shared],
980                 [Build a shared library and link tools against it (default is NO)]),,
981                 enableval=default)
982case "$enableval" in
983  yes) AC_SUBST(ENABLE_SHARED,[1]) ;;
984  no)  AC_SUBST(ENABLE_SHARED,[0]) ;;
985  default) AC_SUBST(ENABLE_SHARED,[0]) ;;
986  *) AC_MSG_ERROR([Invalid setting for --enable-shared. Use "yes" or "no"]) ;;
987esac
988
989dnl Allow libstdc++ is embedded in LLVM.dll.
990AC_ARG_ENABLE(embed-stdcxx,
991  AS_HELP_STRING([--enable-embed-stdcxx],
992                 [Build a shared library with embedded libstdc++ for Win32 DLL (default is NO)]),,
993                 enableval=default)
994case "$enableval" in
995  yes) AC_SUBST(ENABLE_EMBED_STDCXX,[1]) ;;
996  no)  AC_SUBST(ENABLE_EMBED_STDCXX,[0]) ;;
997  default) AC_SUBST(ENABLE_EMBED_STDCXX,[0]) ;;
998  *) AC_MSG_ERROR([Invalid setting for --enable-embed-stdcxx. Use "yes" or "no"]) ;;
999esac
1000
1001dnl Enable support for showing backtraces.
1002AC_ARG_ENABLE(backtraces, AS_HELP_STRING(
1003  [--enable-backtraces],
1004  [Enable embedding backtraces on crash (default is YES)]),
1005  [case "$enableval" in
1006    yes) llvm_cv_enable_backtraces="yes" ;;
1007    no)  llvm_cv_enable_backtraces="no"  ;;
1008    *) AC_MSG_ERROR([Invalid setting for --enable-backtraces. Use "yes" or "no"]) ;;
1009  esac],
1010  llvm_cv_enable_backtraces="yes")
1011if test "$llvm_cv_enable_backtraces" = "yes" ; then
1012  AC_DEFINE([ENABLE_BACKTRACES],[1],
1013            [Define to 1 to enable backtraces, and to 0 otherwise.])
1014fi
1015
1016dnl Enable installing platform specific signal handling overrides, for improved
1017dnl CrashRecovery support or interaction with crash reporting software. This
1018dnl support may be inappropriate for some clients embedding LLVM as a library.
1019AC_ARG_ENABLE(crash-overrides, AS_HELP_STRING(
1020  [--enable-crash-overrides],
1021  [Enable crash handling overrides (default is YES)]),
1022  [case "$enableval" in
1023    yes) llvm_cv_enable_crash_overrides="yes" ;;
1024    no)  llvm_cv_enable_crash_overrides="no"  ;;
1025    *) AC_MSG_ERROR([Invalid setting for --enable-crash-overrides. Use "yes" or "no"]) ;;
1026  esac],
1027  llvm_cv_enable_crash_overrides="yes")
1028if test "$llvm_cv_enable_crash_overrides" = "yes" ; then
1029  AC_DEFINE([ENABLE_CRASH_OVERRIDES],[1],
1030            [Define to 1 to enable crash overrides, and to 0 otherwise.])
1031fi
1032
1033dnl List all possible targets
1034ALL_TARGETS="AArch64 AMDGPU ARM BPF Hexagon Lanai Mips MSP430 NVPTX PowerPC Sparc SystemZ X86 XCore"
1035AC_SUBST(ALL_TARGETS,$ALL_TARGETS)
1036
1037dnl Allow specific targets to be specified for building (or not)
1038TARGETS_TO_BUILD=""
1039AC_ARG_ENABLE([targets],AS_HELP_STRING([--enable-targets],
1040    [Build specific host targets: all or target1,target2,... Valid targets are:
1041     host, x86, x86_64, sparc, powerpc, arm64, arm, aarch64, mips, hexagon,
1042     xcore, msp430, nvptx, systemz, r600, bpf, wasm, and cpp (default=all)]),,
1043    enableval=all)
1044if test "$enableval" = host-only ; then
1045  enableval=host
1046fi
1047case "$enableval" in
1048  all) TARGETS_TO_BUILD="$ALL_TARGETS" ;;
1049  *)for a_target in `echo $enableval|sed -e 's/,/ /g' ` ; do
1050      case "$a_target" in
1051        x86)      TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
1052        x86_64)   TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
1053        sparc)    TARGETS_TO_BUILD="Sparc $TARGETS_TO_BUILD" ;;
1054        powerpc)  TARGETS_TO_BUILD="PowerPC $TARGETS_TO_BUILD" ;;
1055        aarch64)  TARGETS_TO_BUILD="AArch64 $TARGETS_TO_BUILD" ;;
1056        arm64)    TARGETS_TO_BUILD="AArch64 $TARGETS_TO_BUILD" ;;
1057        arm)      TARGETS_TO_BUILD="ARM $TARGETS_TO_BUILD" ;;
1058        bpf)      TARGETS_TO_BUILD="BPF $TARGETS_TO_BUILD" ;;
1059        mips)     TARGETS_TO_BUILD="Mips $TARGETS_TO_BUILD" ;;
1060        mipsel)   TARGETS_TO_BUILD="Mips $TARGETS_TO_BUILD" ;;
1061        mips64)   TARGETS_TO_BUILD="Mips $TARGETS_TO_BUILD" ;;
1062        mips64el) TARGETS_TO_BUILD="Mips $TARGETS_TO_BUILD" ;;
1063        xcore)    TARGETS_TO_BUILD="XCore $TARGETS_TO_BUILD" ;;
1064        msp430)   TARGETS_TO_BUILD="MSP430 $TARGETS_TO_BUILD" ;;
1065        cpp)      TARGETS_TO_BUILD="CppBackend $TARGETS_TO_BUILD" ;;
1066        hexagon)  TARGETS_TO_BUILD="Hexagon $TARGETS_TO_BUILD" ;;
1067        nvptx)    TARGETS_TO_BUILD="NVPTX $TARGETS_TO_BUILD" ;;
1068        systemz)  TARGETS_TO_BUILD="SystemZ $TARGETS_TO_BUILD" ;;
1069        amdgpu)   TARGETS_TO_BUILD="AMDGPU $TARGETS_TO_BUILD" ;;
1070        r600)     TARGETS_TO_BUILD="AMDGPU $TARGETS_TO_BUILD" ;;
1071        wasm)     TARGETS_TO_BUILD="WebAssembly $TARGETS_TO_BUILD" ;;
1072        host) case "$llvm_cv_target_arch" in
1073            x86)         TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
1074            x86_64)      TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
1075            Sparc)       TARGETS_TO_BUILD="Sparc $TARGETS_TO_BUILD" ;;
1076            PowerPC)     TARGETS_TO_BUILD="PowerPC $TARGETS_TO_BUILD" ;;
1077            AArch64)     TARGETS_TO_BUILD="AArch64 $TARGETS_TO_BUILD" ;;
1078            ARM)         TARGETS_TO_BUILD="ARM $TARGETS_TO_BUILD" ;;
1079            Mips)        TARGETS_TO_BUILD="Mips $TARGETS_TO_BUILD" ;;
1080            XCore)       TARGETS_TO_BUILD="XCore $TARGETS_TO_BUILD" ;;
1081            MSP430)      TARGETS_TO_BUILD="MSP430 $TARGETS_TO_BUILD" ;;
1082            Hexagon)     TARGETS_TO_BUILD="Hexagon $TARGETS_TO_BUILD" ;;
1083            NVPTX)       TARGETS_TO_BUILD="NVPTX $TARGETS_TO_BUILD" ;;
1084            SystemZ)     TARGETS_TO_BUILD="SystemZ $TARGETS_TO_BUILD" ;;
1085            WebAssembly) TARGETS_TO_BUILD="WebAssembly $TARGETS_TO_BUILD" ;;
1086            *)       AC_MSG_ERROR([Can not set target to build]) ;;
1087          esac ;;
1088        *) AC_MSG_ERROR([Unrecognized target $a_target]) ;;
1089      esac
1090  done
1091  ;;
1092esac
1093
1094AC_ARG_ENABLE([experimental-targets],AS_HELP_STRING([--enable-experimental-targets],
1095    [Build experimental host targets: disable or target1,target2,...
1096     (default=disable)]),,
1097    enableval=disable)
1098
1099if test ${enableval} != "disable"
1100then
1101  TARGETS_TO_BUILD="$enableval $TARGETS_TO_BUILD"
1102fi
1103
1104AC_SUBST(TARGETS_TO_BUILD,$TARGETS_TO_BUILD)
1105
1106dnl Determine whether we are building LLVM support for the native architecture.
1107dnl If so, define LLVM_NATIVE_ARCH to that LLVM target.
1108for a_target in $TARGETS_TO_BUILD; do
1109  if test "$a_target" = "$LLVM_NATIVE_ARCH"; then
1110    AC_DEFINE_UNQUOTED(LLVM_NATIVE_ARCH, $LLVM_NATIVE_ARCH,
1111      [LLVM architecture name for the native architecture, if available])
1112    LLVM_NATIVE_TARGET="LLVMInitialize${LLVM_NATIVE_ARCH}Target"
1113    LLVM_NATIVE_TARGETINFO="LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo"
1114    LLVM_NATIVE_TARGETMC="LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC"
1115    LLVM_NATIVE_ASMPRINTER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter"
1116    if test -f ${llvm_srcdir}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/CMakeLists.txt ; then
1117      LLVM_NATIVE_ASMPARSER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser"
1118    fi
1119    if test -f ${llvm_srcdir}/lib/Target/${LLVM_NATIVE_ARCH}/Disassembler/CMakeLists.txt ; then
1120      LLVM_NATIVE_DISASSEMBLER="LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler"
1121    fi
1122    AC_DEFINE_UNQUOTED(LLVM_NATIVE_TARGET, $LLVM_NATIVE_TARGET,
1123      [LLVM name for the native Target init function, if available])
1124    AC_DEFINE_UNQUOTED(LLVM_NATIVE_TARGETINFO, $LLVM_NATIVE_TARGETINFO,
1125      [LLVM name for the native TargetInfo init function, if available])
1126    AC_DEFINE_UNQUOTED(LLVM_NATIVE_TARGETMC, $LLVM_NATIVE_TARGETMC,
1127      [LLVM name for the native target MC init function, if available])
1128    AC_DEFINE_UNQUOTED(LLVM_NATIVE_ASMPRINTER, $LLVM_NATIVE_ASMPRINTER,
1129      [LLVM name for the native AsmPrinter init function, if available])
1130    if test -f ${llvm_srcdir}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/CMakeLists.txt ; then
1131      AC_DEFINE_UNQUOTED(LLVM_NATIVE_ASMPARSER, $LLVM_NATIVE_ASMPARSER,
1132       [LLVM name for the native AsmParser init function, if available])
1133    fi
1134    if test -f ${llvm_srcdir}/lib/Target/${LLVM_NATIVE_ARCH}/Disassembler/CMakeLists.txt ; then
1135      AC_DEFINE_UNQUOTED(LLVM_NATIVE_DISASSEMBLER, $LLVM_NATIVE_DISASSEMBLER,
1136       [LLVM name for the native Disassembler init function, if available])
1137    fi
1138  fi
1139done
1140
1141dnl Build the LLVM_TARGET and LLVM_... macros for Targets.def and the individual
1142dnl target feature def files.
1143LLVM_ENUM_TARGETS=""
1144LLVM_ENUM_ASM_PRINTERS=""
1145LLVM_ENUM_ASM_PARSERS=""
1146LLVM_ENUM_DISASSEMBLERS=""
1147for target_to_build in $TARGETS_TO_BUILD; do
1148  LLVM_ENUM_TARGETS="$LLVM_ENUM_TARGETS${as_nl}LLVM_TARGET($target_to_build)"
1149  has_asm_printer=0
1150  for asm_printer in ${llvm_srcdir}/lib/Target/${target_to_build}/*AsmPrinter.cpp; do
1151    if test -f "$asm_printer"; then
1152      has_asm_printer=1
1153    fi
1154  done
1155  if test "$has_asm_printer" = 1; then
1156    LLVM_ENUM_ASM_PRINTERS="$LLVM_ENUM_ASM_PRINTERS${as_nl}LLVM_ASM_PRINTER($target_to_build)";
1157  fi
1158  if test -f ${llvm_srcdir}/lib/Target/${target_to_build}/AsmParser/CMakeLists.txt ; then
1159    LLVM_ENUM_ASM_PARSERS="$LLVM_ENUM_ASM_PARSERS${as_nl}LLVM_ASM_PARSER($target_to_build)";
1160  fi
1161  if test -f ${llvm_srcdir}/lib/Target/${target_to_build}/Disassembler/CMakeLists.txt ; then
1162    LLVM_ENUM_DISASSEMBLERS="$LLVM_ENUM_DISASSEMBLERS${as_nl}LLVM_DISASSEMBLER($target_to_build)";
1163  fi
1164done
1165LLVM_ENUM_TARGETS="${LLVM_ENUM_TARGETS#${as_nl}}${as_nl}"
1166LLVM_ENUM_ASM_PRINTERS="${LLVM_ENUM_ASM_PRINTERS#${as_nl}}${as_nl}"
1167LLVM_ENUM_ASM_PARSERS="${LLVM_ENUM_ASM_PARSERS#${as_nl}}${as_nl}"
1168LLVM_ENUM_DISASSEMBLERS="${LLVM_ENUM_DISASSEMBLERS#${as_nl}}${as_nl}"
1169AC_SUBST(LLVM_ENUM_TARGETS)
1170AC_SUBST(LLVM_ENUM_ASM_PRINTERS)
1171AC_SUBST(LLVM_ENUM_ASM_PARSERS)
1172AC_SUBST(LLVM_ENUM_DISASSEMBLERS)
1173
1174dnl Override the option to use for optimized builds.
1175AC_ARG_WITH(optimize-option,
1176  AS_HELP_STRING([--with-optimize-option],
1177                 [Select the compiler options to use for optimized builds]),,
1178                 withval=default)
1179AC_MSG_CHECKING([optimization flags])
1180case "$withval" in
1181  default)
1182    case "$llvm_cv_os_type" in
1183    FreeBSD) optimize_option=-O2 ;;
1184    MingW) optimize_option=-O2 ;;
1185    *)     optimize_option=-O3 ;;
1186    esac ;;
1187  *) optimize_option="$withval" ;;
1188esac
1189AC_SUBST(OPTIMIZE_OPTION,$optimize_option)
1190AC_MSG_RESULT([$optimize_option])
1191
1192dnl Specify extra build options
1193AC_ARG_WITH(extra-options,
1194  AS_HELP_STRING([--with-extra-options],
1195                 [Specify additional options to compile LLVM with]),,
1196                 withval=default)
1197case "$withval" in
1198  default) EXTRA_OPTIONS= ;;
1199  *) EXTRA_OPTIONS=$withval ;;
1200esac
1201AC_SUBST(EXTRA_OPTIONS,$EXTRA_OPTIONS)
1202
1203dnl Specify extra linker build options
1204AC_ARG_WITH(extra-ld-options,
1205  AS_HELP_STRING([--with-extra-ld-options],
1206                 [Specify additional options to link LLVM with]),,
1207                 withval=default)
1208case "$withval" in
1209  default) EXTRA_LD_OPTIONS= ;;
1210  *) EXTRA_LD_OPTIONS=$withval ;;
1211esac
1212AC_SUBST(EXTRA_LD_OPTIONS,$EXTRA_LD_OPTIONS)
1213
1214dnl Allow specific bindings to be specified for building (or not)
1215AC_ARG_ENABLE([bindings],AS_HELP_STRING([--enable-bindings],
1216    [Build specific language bindings: all,auto,none,{binding-name} (default=auto)]),,
1217    enableval=default)
1218BINDINGS_TO_BUILD=""
1219case "$enableval" in
1220  yes | default | auto) BINDINGS_TO_BUILD="auto" ;;
1221  all ) BINDINGS_TO_BUILD="ocaml" ;;
1222  none | no) BINDINGS_TO_BUILD="" ;;
1223  *)for a_binding in `echo $enableval|sed -e 's/,/ /g' ` ; do
1224      case "$a_binding" in
1225        ocaml) BINDINGS_TO_BUILD="ocaml $BINDINGS_TO_BUILD" ;;
1226        *) AC_MSG_ERROR([Unrecognized binding $a_binding]) ;;
1227      esac
1228  done
1229  ;;
1230esac
1231
1232dnl Allow the ocaml libdir to be overridden. This could go in a configure
1233dnl script for bindings/ocaml/configure, except that its auto value depends on
1234dnl OCAMLC, which is found here to support tests.
1235AC_ARG_WITH([ocaml-libdir],
1236  [AS_HELP_STRING([--with-ocaml-libdir],
1237    [Specify install location for ocaml bindings (default is stdlib)])],
1238  [],
1239  [withval=auto])
1240case "$withval" in
1241  auto) with_ocaml_libdir="$withval" ;;
1242  /* | [[A-Za-z]]:[[\\/]]*) with_ocaml_libdir="$withval" ;;
1243  *) AC_MSG_ERROR([Invalid path for --with-ocaml-libdir. Provide full path]) ;;
1244esac
1245
1246AC_ARG_WITH(clang-srcdir,
1247  AS_HELP_STRING([--with-clang-srcdir],
1248    [Directory to the out-of-tree Clang source]),,
1249    withval="-")
1250case "$withval" in
1251  -) clang_src_root="" ;;
1252  /* | [[A-Za-z]]:[[\\/]]*) clang_src_root="$withval" ;;
1253  *) clang_src_root="$ac_pwd/$withval" ;;
1254esac
1255AC_SUBST(CLANG_SRC_ROOT,[$clang_src_root])
1256
1257AC_ARG_WITH(clang-resource-dir,
1258  AS_HELP_STRING([--with-clang-resource-dir],
1259    [Relative directory from the Clang binary for resource files]),,
1260    withval="")
1261AC_DEFINE_UNQUOTED(CLANG_RESOURCE_DIR,"$withval",
1262                   [Relative directory for resource files])
1263
1264AC_ARG_WITH(c-include-dirs,
1265  AS_HELP_STRING([--with-c-include-dirs],
1266    [Colon separated list of directories clang will search for headers]),,
1267    withval="")
1268AC_DEFINE_UNQUOTED(C_INCLUDE_DIRS,"$withval",
1269                   [Directories clang will search for headers])
1270
1271AC_ARG_WITH(clang-default-openmp-runtime,
1272  AS_HELP_STRING([--with-clang-default-openmp-runtime],
1273    [The default OpenMP runtime for Clang.]),,
1274    withval="libomp")
1275
1276AC_DEFINE_UNQUOTED(CLANG_ENABLE_ARCMT, 1, [Build ARCMT])
1277AC_DEFINE_UNQUOTED(CLANG_ENABLE_OBJC_REWRITER, 1, [Build ObjC rewriter])
1278AC_DEFINE_UNQUOTED(CLANG_ENABLE_STATIC_ANALYZER, 1, [Build Static analyzer])
1279AC_DEFINE_UNQUOTED(CLANG_SPAWN_CC1, 1, [Whether clang should use a new process for the CC1 invocation])
1280
1281AC_DEFINE_UNQUOTED(ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER, 0,
1282                   [Enable the experimental new pass manager by default])
1283AC_DEFINE_UNQUOTED(CLANG_OPENMP_NVPTX_DEFAULT_ARCH, "sm_35",
1284                   [Default architecture for OpenMP offloading to Nvidia GPUs.])
1285
1286AC_DEFINE_UNQUOTED(ENABLE_X86_RELAX_RELOCATIONS, 0,
1287                   [enable x86 relax relocations by default])
1288AC_DEFINE_UNQUOTED(CLANG_DEFAULT_CXX_STDLIB, "",
1289                   [Default C++ stdlib to use.])
1290AC_DEFINE_UNQUOTED(CLANG_DEFAULT_LINKER, "",
1291                   [Default linker to use (linker name or absolute path, empty for platform default)])
1292AC_DEFINE_UNQUOTED(CLANG_DEFAULT_OBJCOPY, "objcopy",
1293                   [Default objcopy to use.])
1294AC_DEFINE_UNQUOTED(CLANG_DEFAULT_RTLIB, "",
1295                   [Default runtime library to use.])
1296AC_DEFINE_UNQUOTED(CLANG_DEFAULT_UNWINDLIB, "none",
1297                   [Default unwind library to use.])
1298AC_DEFINE_UNQUOTED(CLANG_DEFAULT_OPENMP_RUNTIME, "libomp",
1299                   [Default OpenMP runtime used by -fopenmp.])
1300AC_DEFINE_UNQUOTED(CLANG_SYSTEMZ_DEFAULT_ARCH, "z10",
1301                   [SystemZ Default Arch])
1302AC_DEFINE_UNQUOTED(CLANG_LIBDIR_SUFFIX, "",
1303                   [Multilib suffix for libdir.])
1304AC_DEFINE_UNQUOTED(DEFAULT_SYSROOT, "",
1305                   [Default <path> to all compiler invocations for --sysroot=<path>.])
1306AC_DEFINE_UNQUOTED(GCC_INSTALL_PREFIX, "",
1307                   [Directory where gcc is installed.])
1308
1309dnl Allow linking of LLVM with GPLv3 binutils code.
1310AC_ARG_WITH(binutils-include,
1311  AS_HELP_STRING([--with-binutils-include],
1312    [Specify path to binutils/include/ containing plugin-api.h file for gold plugin.]),,
1313  withval=default)
1314case "$withval" in
1315  default) WITH_BINUTILS_INCDIR=default ;;
1316  /* | [[A-Za-z]]:[[\\/]]*)      WITH_BINUTILS_INCDIR=$withval ;;
1317  *) AC_MSG_ERROR([Invalid path for --with-binutils-include. Provide full path]) ;;
1318esac
1319if test "x$WITH_BINUTILS_INCDIR" != xdefault ; then
1320  AC_SUBST(BINUTILS_INCDIR,$WITH_BINUTILS_INCDIR)
1321  if test ! -f "$WITH_BINUTILS_INCDIR/plugin-api.h"; then
1322     echo "$WITH_BINUTILS_INCDIR/plugin-api.h"
1323     AC_MSG_ERROR([Invalid path to directory containing plugin-api.h.]);
1324  fi
1325fi
1326
1327dnl Specify the URL where bug reports should be submitted.
1328AC_ARG_WITH(bug-report-url,
1329  AS_HELP_STRING([--with-bug-report-url],
1330    [Specify the URL where bug reports should be submitted (default=http://llvm.org/bugs/)]),,
1331    withval="http://llvm.org/bugs/")
1332AC_DEFINE_UNQUOTED(BUG_REPORT_URL,"$withval",
1333                   [Bug report URL.])
1334
1335dnl --enable-terminfo: check whether the user wants to control use of terminfo:
1336AC_ARG_ENABLE(terminfo,AS_HELP_STRING(
1337  [--enable-terminfo],
1338  [Query the terminfo database if available (default is YES)]),
1339  [case "$enableval" in
1340    yes) llvm_cv_enable_terminfo="yes" ;;
1341    no)  llvm_cv_enable_terminfo="no"  ;;
1342    *) AC_MSG_ERROR([Invalid setting for --enable-terminfo. Use "yes" or "no"]) ;;
1343  esac],
1344  llvm_cv_enable_terminfo="yes")
1345case "$llvm_cv_enable_terminfo" in
1346  yes) AC_SUBST(ENABLE_TERMINFO,[1]) ;;
1347  no)  AC_SUBST(ENABLE_TERMINFO,[0]) ;;
1348esac
1349
1350dnl --enable-libedit: check whether the user wants to turn off libedit.
1351AC_ARG_ENABLE(libedit,AS_HELP_STRING(
1352  [--enable-libedit],
1353  [Use libedit if available (default is YES)]),
1354  [case "$enableval" in
1355    yes) llvm_cv_enable_libedit="yes" ;;
1356    no)  llvm_cv_enable_libedit="no"  ;;
1357    *) AC_MSG_ERROR([Invalid setting for --enable-libedit. Use "yes" or "no"]) ;;
1358  esac],
1359  llvm_cv_enable_libedit="yes")
1360
1361dnl --enable-libffi : check whether the user wants to turn off libffi:
1362AC_ARG_ENABLE(libffi,AS_HELP_STRING(
1363  --enable-libffi,[Check for the presence of libffi (default is NO)]),
1364  [case "$enableval" in
1365    yes) llvm_cv_enable_libffi="yes" ;;
1366    no)  llvm_cv_enable_libffi="no"  ;;
1367    *) AC_MSG_ERROR([Invalid setting for --enable-libffi. Use "yes" or "no"]) ;;
1368  esac],
1369  llvm_cv_enable_libffi=no)
1370
1371AC_ARG_WITH(internal-prefix,
1372  AS_HELP_STRING([--with-internal-prefix],
1373    [Installation directory for internal files]),,
1374    withval="")
1375AC_SUBST(INTERNAL_PREFIX,[$withval])
1376
1377dnl===-----------------------------------------------------------------------===
1378dnl===
1379dnl=== SECTION 4: Check for programs we need and that they are the right version
1380dnl===
1381dnl===-----------------------------------------------------------------------===
1382
1383dnl Check for the tools that the makefiles require
1384AC_CHECK_GNU_MAKE
1385AC_PROG_LN_S
1386AC_PATH_PROG(NM, [nm], [nm])
1387AC_PATH_PROG(CMP, [cmp], [cmp])
1388AC_PATH_PROG(CP, [cp], [cp])
1389AC_PATH_PROG(DATE, [date], [date])
1390AC_PATH_PROG(FIND, [find], [find])
1391AC_PATH_PROG(GREP, [grep], [grep])
1392AC_PATH_PROG(MKDIR,[mkdir],[mkdir])
1393AC_PATH_PROG(MV,   [mv],   [mv])
1394AC_PROG_RANLIB
1395AC_CHECK_TOOL(AR, ar, false)
1396AC_PATH_PROG(RM,   [rm],   [rm])
1397AC_PATH_PROG(SED,  [sed],  [sed])
1398AC_PATH_PROG(TAR,  [tar],  [gtar])
1399AC_PATH_PROG(BINPWD,[pwd],  [pwd])
1400
1401dnl Looking for misc. graph plotting software
1402AC_PATH_PROG(DOT, [dot], [echo dot])
1403if test "$DOT" != "echo dot" ; then
1404  dnl If we're targeting for mingw we should emit windows paths, not msys
1405  if test "$llvm_cv_os_type" = "MingW" ; then
1406    DOT=`echo $DOT | sed 's/^\/\([[A-Za-z]]\)\//\1:\//' `
1407  fi
1408fi
1409
1410dnl Find the install program
1411AC_PROG_INSTALL
1412dnl Prepend src dir to install path dir if it's a relative path
1413dnl This is a hack for installs that take place in something other
1414dnl than the top level.
1415case "$INSTALL" in
1416 [[\\/$]]* | ?:[[\\/]]* ) ;;
1417 *)  INSTALL="\\\$(TOPSRCDIR)/$INSTALL" ;;
1418esac
1419
1420dnl Checks for documentation and testing tools that we can do without. If these
1421dnl are not found then they are set to "true" which always succeeds but does
1422dnl nothing. This just lets the build output show that we could have done
1423dnl something if the tool was available.
1424AC_PATH_PROG(BZIP2, [bzip2])
1425AC_PATH_PROG(CAT, [cat])
1426AC_PATH_PROG(DOXYGEN, [doxygen])
1427AC_PATH_PROG(GROFF, [groff])
1428AC_PATH_PROG(GZIPBIN, [gzip])
1429AC_PATH_PROG(PDFROFF, [pdfroff])
1430AC_PATH_PROG(ZIP, [zip])
1431AC_PATH_PROG(GO, [go])
1432AC_PATH_PROGS(OCAMLFIND, [ocamlfind])
1433AC_PATH_PROGS(GAS, [gas as])
1434
1435dnl Get the version of the linker in use.
1436AC_LINK_GET_VERSION
1437
1438dnl Determine whether the linker supports the --version-script option.
1439AC_LINK_VERSION_SCRIPT
1440
1441AC_CHECK_HEADERS([errno.h])
1442
1443case "$llvm_cv_os_type" in
1444  Cygwin|MingW|Win32) llvm_shlib_ext=.dll ;;
1445  Darwin) llvm_shlib_ext=.dylib ;;
1446  *) llvm_shlib_ext=.so ;;
1447esac
1448
1449AC_DEFINE_UNQUOTED([LTDL_SHLIB_EXT], ["$llvm_shlib_ext"],
1450                   [Define to the extension used for shared libraries, say, ".so".])
1451
1452AC_MSG_CHECKING([tool compatibility])
1453
1454dnl Ensure that compilation tools are GCC or a GNU compatible compiler such as
1455dnl ICC; we use GCC specific options in the makefiles so the compiler needs
1456dnl to support those options.
1457dnl "icc" emits gcc signatures
1458dnl "icc -no-gcc" emits no gcc signature BUT is still compatible
1459ICC=no
1460IXX=no
1461case $CC in
1462  icc*|icpc*)
1463    ICC=yes
1464    IXX=yes
1465    ;;
1466   *)
1467    ;;
1468esac
1469
1470if test "$GCC" != "yes" && test "$ICC" != "yes"
1471then
1472  AC_MSG_ERROR([gcc|icc required but not found])
1473fi
1474
1475dnl Ensure that compilation tools are compatible with GCC extensions
1476if test "$GXX" != "yes" && test "$IXX" != "yes"
1477then
1478  AC_MSG_ERROR([g++|clang++|icc required but not found])
1479fi
1480
1481dnl Verify that GCC is version 3.0 or higher
1482if test "$GCC" = "yes"
1483then
1484  AC_COMPILE_IFELSE(
1485[
1486  AC_LANG_SOURCE([[
1487    #if !defined(__GNUC__) || __GNUC__ < 3
1488    #error Unsupported GCC version
1489    #endif
1490  ]])
1491],
1492[], [AC_MSG_ERROR([gcc 3.x required, but you have a lower version])])
1493fi
1494
1495dnl Check for GNU Make.  We use its extensions, so don't build without it
1496if test -z "$llvm_cv_gnu_make_command"
1497then
1498  AC_MSG_ERROR([GNU Make required but not found])
1499fi
1500
1501dnl Tool compatibility is okay if we make it here.
1502AC_MSG_RESULT([ok])
1503
1504dnl Check optional compiler flags.
1505AC_MSG_CHECKING([optional compiler flags])
1506case "$llvm_cv_cxx_compiler" in
1507  clang)
1508    CXX_FLAG_CHECK(NO_VARIADIC_MACROS, [-Wno-variadic-macros])
1509    CXX_FLAG_CHECK(MISSING_FIELD_INITIALIZERS, [-Wmissing-field-initializers])
1510    CXX_FLAG_CHECK(COVERED_SWITCH_DEFAULT, [-Wcovered-switch-default])
1511    ;;
1512  gcc)
1513    dnl If we're using gcc check for -Wno-missing-field-initializers as gcc will warn
1514    dnl on plain open brace initializations. clang won't so use -Wmissing-field-initializers
1515    dnl there.
1516    CXX_FLAG_CHECK(MISSING_FIELD_INITIALIZERS, [-Wno-missing-field-initializers])
1517    CXX_FLAG_CHECK(NO_VARIADIC_MACROS, [-Wno-variadic-macros])
1518    CXX_FLAG_CHECK(COVERED_SWITCH_DEFAULT, [-Wcovered-switch-default])
1519    CXX_FLAG_CHECK(NO_MAYBE_UNINITIALIZED, [-Wno-maybe-uninitialized])
1520    dnl gcc 4.7 introduced -Wmaybe-uninitialized to distinguish cases which are
1521    dnl known to be uninitialized from cases which might be uninitialized.  We
1522    dnl still want to catch the first kind of errors.
1523    if test -z "$NO_MAYBE_UNINITIALIZED"
1524    then
1525      CXX_FLAG_CHECK(NO_UNINITIALIZED, [-Wno-uninitialized])
1526    fi
1527    ;;
1528  unknown)
1529    ;;
1530esac
1531
1532dnl Check for misbehaving -Wcomment (gcc-4.7 has this) and maybe add
1533dnl -Wno-comment to the flags.
1534no_comment=
1535llvm_cv_old_cxxflags="$CXXFLAGS"
1536CXXFLAGS="$CXXFLAGS -Wcomment -Werror"
1537AC_COMPILE_IFELSE(
1538[
1539  AC_LANG_SOURCE([[// Comment \o\
1540// Another comment
1541int main() { return 0; }
1542  ]])
1543],
1544[
1545  no_comment=-Wno-comment
1546],
1547[])
1548AC_SUBST(NO_COMMENT, [$no_comment])
1549CXXFLAGS="$llvm_cv_old_cxxflags"
1550
1551AC_MSG_RESULT([$NO_VARIADIC_MACROS $MISSING_FIELD_INITIALIZERS $COVERED_SWITCH_DEFAULT $NO_UNINITIALIZED $NO_MAYBE_UNINITIALIZED $NO_COMMENT])
1552
1553dnl===-----------------------------------------------------------------------===
1554dnl===
1555dnl=== SECTION 5: Check for libraries
1556dnl===
1557dnl===-----------------------------------------------------------------------===
1558
1559if test "$llvm_cv_os_type" = "MingW" ; then
1560  AC_CHECK_LIB(psapi, main)
1561  AC_CHECK_LIB(shell32, main)
1562fi
1563
1564dnl dlopen() is required for plugin support.
1565AC_SEARCH_LIBS(dlopen,dl,LLVM_DEFINE_SUBST([HAVE_DLOPEN],[1],
1566               [Define if dlopen() is available on this platform.]),
1567               AC_MSG_WARN([dlopen() not found - disabling plugin support]))
1568
1569dnl Search for the clock_gettime() function. Note that we rely on the POSIX
1570dnl macros to detect whether clock_gettime is available, this just finds the
1571dnl right libraries to link with.
1572AC_SEARCH_LIBS(clock_gettime,rt)
1573
1574dnl The curses library is optional; used for querying terminal info
1575if test "$llvm_cv_enable_terminfo" = "yes" ; then
1576  dnl We need the has_color functionality in curses for it to be useful.
1577  AC_SEARCH_LIBS(setupterm,tinfo terminfo curses ncurses ncursesw,
1578                 LLVM_DEFINE_SUBST([HAVE_TERMINFO],[1],
1579                                   [Define if the setupterm() function is supported this platform.]))
1580fi
1581
1582dnl The libedit library is optional; used by lib/LineEditor
1583if test "$llvm_cv_enable_libedit" = "yes" ; then
1584  AC_SEARCH_LIBS(el_init,edit,
1585                 AC_DEFINE([HAVE_LIBEDIT],[1],
1586                           [Define to 1 if you have the `edit' library (-ledit).]))
1587fi
1588
1589dnl libffi is optional; used to call external functions from the interpreter
1590if test "$llvm_cv_enable_libffi" = "yes" ; then
1591  AC_SEARCH_LIBS(ffi_call,ffi,AC_DEFINE([HAVE_FFI_CALL],[1],
1592                 [Define if libffi is available on this platform.]),
1593                 AC_MSG_ERROR([libffi not found - configure without --enable-libffi to compile without it]))
1594fi
1595
1596dnl mallinfo and mallctl are optional; the code can compile (minus features) without it
1597AC_CHECK_FUNCS([mallinfo mallctl])
1598
1599dnl pthread locking functions are optional - but llvm will not be thread-safe
1600dnl without locks.
1601if test "$LLVM_ENABLE_THREADS" -eq 1 && test "$ENABLE_PTHREADS" -eq 1 ; then
1602  AC_CHECK_LIB(pthread, pthread_mutex_init)
1603  AC_SEARCH_LIBS(pthread_mutex_lock,pthread,
1604                 AC_DEFINE([HAVE_PTHREAD_MUTEX_LOCK],[1],
1605                           [Have pthread_mutex_lock]))
1606  AC_SEARCH_LIBS(pthread_rwlock_init,pthread,
1607                 AC_DEFINE([HAVE_PTHREAD_RWLOCK_INIT],[1],
1608                 [Have pthread_rwlock_init]))
1609  AC_SEARCH_LIBS(pthread_getspecific,pthread,
1610                 AC_DEFINE([HAVE_PTHREAD_GETSPECIFIC],[1],
1611                 [Have pthread_getspecific]))
1612fi
1613
1614dnl zlib is optional; used for compression/uncompression
1615if test "$LLVM_ENABLE_ZLIB" -eq 1 ; then
1616  AC_CHECK_LIB(z, compress2)
1617fi
1618
1619dnl Allow OProfile support for JIT output.
1620USE_OPROFILE=0
1621AC_ARG_WITH(oprofile,
1622  AS_HELP_STRING([--with-oprofile=<prefix>],
1623    [Tell OProfile >= 0.9.4 how to symbolize JIT output]),
1624    [
1625      case "$withval" in
1626      no) ;;
1627      *)
1628          USE_OPROFILE=1
1629          ;;
1630      esac
1631      case "$withval" in
1632        /usr|yes) llvm_cv_oppath=/usr/lib/oprofile ;;
1633        no) llvm_cv_oppath= ;;
1634        *) llvm_cv_oppath="${withval}/lib/oprofile"
1635           CPPFLAGS="-I${withval}/include";;
1636      esac
1637      case $llvm_cv_os_type in
1638        Linux)
1639          if test -n "$llvm_cv_oppath" ; then
1640            LIBS="$LIBS -lopagent -L${llvm_cv_oppath} -Wl,-rpath,${llvm_cv_oppath}"
1641            dnl Work around http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=537744:
1642            dnl libbfd is not included properly in libopagent in some Debian
1643            dnl versions.  If libbfd isn't found at all, we assume opagent works
1644            dnl anyway.
1645            AC_SEARCH_LIBS(bfd_init, bfd, [], [])
1646            AC_SEARCH_LIBS(op_open_agent, opagent, [], [
1647              echo "Error! You need to have libopagent around."
1648              exit 1
1649            ])
1650            AC_CHECK_HEADER([opagent.h], [], [
1651              echo "Error! You need to have opagent.h around."
1652              exit 1
1653              ])
1654          fi ;;
1655        *)
1656          AC_MSG_ERROR([OProfile support is available on Linux only.]) ;;
1657      esac
1658    ])
1659AC_SUBST(USE_OPROFILE, [$USE_OPROFILE])
1660AC_DEFINE_UNQUOTED([LLVM_USE_OPROFILE],$USE_OPROFILE,
1661                   [Define if we have the oprofile JIT-support library])
1662
1663dnl Enable support for Intel JIT Events API.
1664AC_ARG_WITH(intel-jitevents,
1665  AS_HELP_STRING([--with-intel-jitevents  Notify Intel JIT profiling API of generated code]),
1666    [
1667       case "$withval" in
1668          yes) AC_SUBST(USE_INTEL_JITEVENTS,[1]);;
1669          no)  AC_SUBST(USE_INTEL_JITEVENTS,[0]);;
1670          *) AC_MSG_ERROR([Invalid setting for --with-intel-jitevents. Use "yes" or "no"]);;
1671       esac
1672
1673      case $llvm_cv_os_type in
1674        Linux|Win32|Cygwin|MingW) ;;
1675        *) AC_MSG_ERROR([Intel JIT API support is available on Linux and Windows only.]);;
1676      esac
1677
1678      case "$llvm_cv_target_arch" in
1679        x86|x86_64) ;;
1680        *) AC_MSG_ERROR([Target architecture $llvm_cv_target_arch does not support Intel JIT Events API.]);;
1681      esac
1682    ],
1683    [
1684      AC_SUBST(USE_INTEL_JITEVENTS, [0])
1685    ])
1686AC_DEFINE_UNQUOTED([LLVM_USE_INTEL_JITEVENTS],$USE_INTEL_JITEVENTS,
1687                   [Define if we have the Intel JIT API runtime support library])
1688
1689dnl===-----------------------------------------------------------------------===
1690dnl===
1691dnl=== SECTION 6: Check for header files
1692dnl===
1693dnl===-----------------------------------------------------------------------===
1694
1695dnl First, use autoconf provided macros for specific headers that we need
1696dnl We don't check for ancient stuff or things that are guaranteed to be there
1697dnl by the C++ standard. We always use the <cfoo> versions of <foo.h> C headers.
1698dnl Generally we're looking for POSIX headers.
1699AC_HEADER_DIRENT
1700AC_HEADER_STAT
1701AC_HEADER_TIME
1702
1703AC_CHECK_HEADERS([dlfcn.h execinfo.h fcntl.h inttypes.h link.h])
1704AC_CHECK_HEADERS([signal.h stdint.h sysexits.h termios.h unistd.h])
1705AC_CHECK_HEADERS([sys/mman.h sys/param.h sys/resource.h sys/time.h sys/uio.h])
1706AC_CHECK_HEADERS([sys/ioctl.h malloc/malloc.h mach/mach.h])
1707AC_CHECK_HEADERS([valgrind/valgrind.h])
1708AC_CHECK_HEADERS([fenv.h])
1709AC_CHECK_DECLS([arc4random], [], [], [[#include <stdlib.h>]])
1710AC_CHECK_DECLS([FE_ALL_EXCEPT, FE_INEXACT], [], [], [[#include <fenv.h>]])
1711if test "$LLVM_ENABLE_THREADS" -eq 1 && test "$ENABLE_PTHREADS" -eq 1 ; then
1712  AC_CHECK_HEADERS(pthread.h,
1713                   AC_SUBST(HAVE_PTHREAD, 1),
1714                   AC_SUBST(HAVE_PTHREAD, 0))
1715else
1716  AC_SUBST(HAVE_PTHREAD, 0)
1717fi
1718if test "$LLVM_ENABLE_ZLIB" -eq 1 ; then
1719  AC_CHECK_HEADERS(zlib.h,
1720                   AC_SUBST(HAVE_LIBZ, 1),
1721                   AC_SUBST(HAVE_LIBZ, 0))
1722else
1723  AC_SUBST(HAVE_LIBZ, 0)
1724fi
1725
1726dnl Try to find ffi.h.
1727if test "$llvm_cv_enable_libffi" = "yes" ; then
1728  AC_CHECK_HEADERS([ffi.h ffi/ffi.h])
1729fi
1730
1731dnl Try to find Darwin specific crash reporting libraries.
1732AC_CHECK_HEADERS([CrashReporterClient.h])
1733
1734dnl Try to find Darwin specific crash reporting global.
1735AC_MSG_CHECKING([__crashreporter_info__])
1736AC_LINK_IFELSE(
1737[
1738  AC_LANG_SOURCE([[
1739    extern const char *__crashreporter_info__;
1740    int main() {
1741      __crashreporter_info__ = "test";
1742      return 0;
1743    }
1744  ]])
1745],
1746[
1747  AC_MSG_RESULT([yes])
1748  AC_DEFINE([HAVE_CRASHREPORTER_INFO], [1], [can use __crashreporter_info__])
1749],
1750[
1751  AC_MSG_RESULT([no])
1752  AC_DEFINE([HAVE_CRASHREPORTER_INFO], [0], [can use __crashreporter_info__])
1753])
1754
1755AC_DEFINE([HAVE_DIA_SDK], [0],
1756          [Define to 1 if you have the DIA SDK installed, and to 0 if you don't.])
1757
1758dnl===-----------------------------------------------------------------------===
1759dnl===
1760dnl=== SECTION 7: Check for types and structures
1761dnl===
1762dnl===-----------------------------------------------------------------------===
1763
1764AC_HUGE_VAL_CHECK
1765AC_TYPE_PID_T
1766AC_TYPE_SIZE_T
1767AC_DEFINE_UNQUOTED([RETSIGTYPE],[void],[Define as the return type of signal handlers (`int' or `void').])
1768AC_STRUCT_TM
1769AC_CHECK_TYPES([int64_t],,AC_MSG_ERROR([Type int64_t required but not found]))
1770AC_CHECK_TYPES([uint64_t],,
1771         AC_CHECK_TYPES([u_int64_t],,
1772         AC_MSG_ERROR([Type uint64_t or u_int64_t required but not found])))
1773
1774AC_CHECK_MEMBERS([struct stat.st_mtimensec.tv_nsec, struct stat.st_mtim.tv_nsec],,,
1775	[#include <sys/stat.h>])
1776
1777dnl===-----------------------------------------------------------------------===
1778dnl===
1779dnl=== SECTION 8: Check for specific functions needed
1780dnl===
1781dnl===-----------------------------------------------------------------------===
1782
1783AC_CHECK_FUNCS([_Unwind_Backtrace backtrace getcwd ])
1784AC_CHECK_FUNCS([getpagesize getrusage getrlimit setrlimit gettimeofday ])
1785AC_CHECK_FUNCS([isatty mkdtemp mkstemp ])
1786AC_CHECK_FUNCS([mktemp posix_spawn pread realpath sbrk setrlimit ])
1787AC_CHECK_FUNCS([strerror strerror_r setenv ])
1788AC_CHECK_FUNCS([strtoll sysconf malloc_zone_statistics ])
1789AC_CHECK_FUNCS([sigaltstack writev posix_fallocate])
1790AC_CHECK_FUNCS([futimes futimens _chsize_s])
1791
1792dnl Check for arc4random accessible via AC_INCLUDES_DEFAULT.
1793AC_CHECK_DECLS([arc4random])
1794
1795dnl Check the declaration "Secure API" on Windows environments.
1796AC_CHECK_DECLS([strerror_s])
1797
1798dnl Check symbols in libgcc.a for JIT on Mingw.
1799if test "$llvm_cv_os_type" = "MingW" ; then
1800  AC_CHECK_LIB(gcc,_alloca,AC_DEFINE([HAVE__ALLOCA],[1],[Have host's _alloca]))
1801  AC_CHECK_LIB(gcc,__alloca,AC_DEFINE([HAVE___ALLOCA],[1],[Have host's __alloca]))
1802  AC_CHECK_LIB(gcc,__chkstk,AC_DEFINE([HAVE___CHKSTK],[1],[Have host's __chkstk]))
1803  AC_CHECK_LIB(gcc,__chkstk_ms,AC_DEFINE([HAVE___CHKSTK_MS],[1],[Have host's __chkstk_ms]))
1804  AC_CHECK_LIB(gcc,___chkstk,AC_DEFINE([HAVE____CHKSTK],[1],[Have host's ___chkstk]))
1805  AC_CHECK_LIB(gcc,___chkstk_ms,AC_DEFINE([HAVE____CHKSTK_MS],[1],[Have host's ___chkstk_ms]))
1806
1807  AC_CHECK_LIB(gcc,__ashldi3,AC_DEFINE([HAVE___ASHLDI3],[1],[Have host's __ashldi3]))
1808  AC_CHECK_LIB(gcc,__ashrdi3,AC_DEFINE([HAVE___ASHRDI3],[1],[Have host's __ashrdi3]))
1809  AC_CHECK_LIB(gcc,__divdi3,AC_DEFINE([HAVE___DIVDI3],[1],[Have host's __divdi3]))
1810  AC_CHECK_LIB(gcc,__fixdfdi,AC_DEFINE([HAVE___FIXDFDI],[1],[Have host's __fixdfdi]))
1811  AC_CHECK_LIB(gcc,__fixsfdi,AC_DEFINE([HAVE___FIXSFDI],[1],[Have host's __fixsfdi]))
1812  AC_CHECK_LIB(gcc,__floatdidf,AC_DEFINE([HAVE___FLOATDIDF],[1],[Have host's __floatdidf]))
1813  AC_CHECK_LIB(gcc,__lshrdi3,AC_DEFINE([HAVE___LSHRDI3],[1],[Have host's __lshrdi3]))
1814  AC_CHECK_LIB(gcc,__moddi3,AC_DEFINE([HAVE___MODDI3],[1],[Have host's __moddi3]))
1815  AC_CHECK_LIB(gcc,__udivdi3,AC_DEFINE([HAVE___UDIVDI3],[1],[Have host's __udivdi3]))
1816  AC_CHECK_LIB(gcc,__umoddi3,AC_DEFINE([HAVE___UMODDI3],[1],[Have host's __umoddi3]))
1817
1818  AC_CHECK_LIB(gcc,__main,AC_DEFINE([HAVE___MAIN],[1],[Have host's __main]))
1819  AC_CHECK_LIB(gcc,__cmpdi2,AC_DEFINE([HAVE___CMPDI2],[1],[Have host's __cmpdi2]))
1820fi
1821
1822dnl atomic builtins are required for threading support.
1823AC_MSG_CHECKING(for GCC atomic builtins)
1824dnl Since we'll be using these atomic builtins in C++ files we should test
1825dnl the C++ compiler.
1826AC_LANG_PUSH([C++])
1827AC_LINK_IFELSE(
1828[
1829  AC_LANG_SOURCE([[
1830    int main() {
1831      volatile unsigned long val = 1;
1832      __sync_synchronize();
1833      __sync_val_compare_and_swap(&val, 1, 0);
1834      __sync_add_and_fetch(&val, 1);
1835      __sync_sub_and_fetch(&val, 1);
1836      return 0;
1837    }
1838  ]])
1839],
1840[
1841  AC_MSG_RESULT([yes])
1842  AC_DEFINE([LLVM_HAS_ATOMICS], [1], [Has gcc/MSVC atomic intrinsics])
1843],
1844[
1845  AC_MSG_RESULT([no])
1846  AC_DEFINE([LLVM_HAS_ATOMICS], [0], [Has gcc/MSVC atomic intrinsics])
1847  AC_MSG_WARN([LLVM will be built thread-unsafe because atomic builtins are missing])
1848])
1849AC_LANG_POP([C++])
1850
1851AC_LANG_PUSH([C++])
1852AC_LINK_IFELSE(
1853[
1854  AC_LANG_SOURCE([[
1855#include <type_traits>
1856struct T { int val; };
1857static_assert(std::is_trivially_copyable<T>::value, "ok");
1858int main() { return 0; }
1859  ]])
1860],
1861[
1862  AC_MSG_RESULT([yes])
1863  AC_DEFINE([HAVE_STD_IS_TRIVIALLY_COPYABLE], [1], [Has usable std::is_trivially_copyable])
1864],
1865[
1866  AC_MSG_RESULT([no])
1867  AC_DEFINE([HAVE_STD_IS_TRIVIALLY_COPYABLE], [0], [Has usable std::is_trivially_copyable])
1868])
1869AC_LANG_POP([C++])
1870
1871dnl===-----------------------------------------------------------------------===
1872dnl===
1873dnl=== SECTION 9: Additional checks, variables, etc.
1874dnl===
1875dnl===-----------------------------------------------------------------------===
1876
1877dnl Handle 32-bit linux systems running a 64-bit kernel.
1878dnl This has to come after section 4 because it invokes the compiler.
1879if test "$llvm_cv_os_type" = "Linux" -a "$llvm_cv_target_arch" = "x86_64" ; then
1880  AC_IS_LINUX_MIXED
1881  if test "$llvm_cv_linux_mixed" = "yes"; then
1882    llvm_cv_target_arch="x86"
1883    ARCH="x86"
1884  fi
1885fi
1886
1887dnl Propagate the shared library extension that the libltdl checks did to
1888dnl the Makefiles so we can use it there too
1889AC_SUBST(SHLIBEXT,$llvm_shlib_ext)
1890
1891dnl Translate the various configuration directories and other basic
1892dnl information into substitutions that will end up in Makefile.config.in
1893dnl that these configured values can be used by the makefiles
1894if test "${prefix}" = "NONE" ; then
1895  prefix="/usr/local"
1896fi
1897eval LLVM_PREFIX="${prefix}";
1898
1899dnl Place the various directories into the config.h file as #defines so that we
1900dnl can know about the installation paths within LLVM.
1901AC_DEFINE_UNQUOTED(LLVM_PREFIX,"$LLVM_PREFIX",
1902                   [Installation prefix directory])
1903AC_DEFINE_UNQUOTED(LLVM_HOST_TRIPLE, "$host",
1904                   [Host triple LLVM will be executed on])
1905AC_DEFINE_UNQUOTED(LLVM_DEFAULT_TARGET_TRIPLE, "$target",
1906                   [Target triple LLVM will generate code for by default])
1907
1908dnl Determine which bindings to build.
1909if test "$BINDINGS_TO_BUILD" = auto ; then
1910  BINDINGS_TO_BUILD=""
1911  if test "x$OCAMLFIND" != x ; then
1912    BINDINGS_TO_BUILD="ocaml $BINDINGS_TO_BUILD"
1913  fi
1914  if test "x$GO" != x ; then
1915    if $GO run ${srcdir}/bindings/go/conftest.go ; then
1916      BINDINGS_TO_BUILD="go $BINDINGS_TO_BUILD"
1917    fi
1918  fi
1919fi
1920AC_SUBST(BINDINGS_TO_BUILD,$BINDINGS_TO_BUILD)
1921
1922dnl Do any work necessary to ensure that bindings have what they need.
1923binding_prereqs_failed=0
1924for a_binding in $BINDINGS_TO_BUILD ; do
1925  case "$a_binding" in
1926  ocaml)
1927    if test "x$OCAMLFIND" = x ; then
1928      AC_MSG_WARN([--enable-bindings=ocaml specified, but ocamlfind not found. Try configure OCAMLFIND=/path/to/ocamlfind])
1929      binding_prereqs_failed=1
1930    fi
1931
1932    if $OCAMLFIND opt -version >/dev/null 2>/dev/null ; then
1933      HAVE_OCAMLOPT=1
1934    else
1935      HAVE_OCAMLOPT=0
1936    fi
1937    AC_SUBST(HAVE_OCAMLOPT)
1938
1939    if ! $OCAMLFIND query ctypes >/dev/null 2>/dev/null; then
1940      AC_MSG_WARN([--enable-bindings=ocaml specified, but ctypes is not installed])
1941      binding_prereqs_failed=1
1942    fi
1943
1944    if $OCAMLFIND query oUnit >/dev/null 2>/dev/null; then
1945      HAVE_OCAML_OUNIT=1
1946    else
1947      HAVE_OCAML_OUNIT=0
1948      AC_MSG_WARN([--enable-bindings=ocaml specified, but OUnit 2 is not installed. Tests will not run])
1949      dnl oUnit is optional!
1950    fi
1951    AC_SUBST(HAVE_OCAML_OUNIT)
1952
1953    if test "x$with_ocaml_libdir" != xauto ; then
1954      AC_SUBST(OCAML_LIBDIR,$with_ocaml_libdir)
1955    else
1956      ocaml_stdlib="`"$OCAMLFIND" ocamlc -where`"
1957      if test "$LLVM_PREFIX" '<' "$ocaml_stdlib" -a "$ocaml_stdlib" '<' "$LLVM_PREFIX~"
1958      then
1959        # ocaml stdlib is beneath our prefix; use stdlib
1960        AC_SUBST(OCAML_LIBDIR,$ocaml_stdlib)
1961      else
1962        # ocaml stdlib is outside our prefix; use libdir/ocaml
1963        AC_SUBST(OCAML_LIBDIR,${prefix}/lib/ocaml)
1964      fi
1965    fi
1966    ;;
1967  go)
1968    if test "x$GO" = x ; then
1969      AC_MSG_WARN([--enable-bindings=go specified, but go not found. Try configure GO=/path/to/go])
1970      binding_prereqs_failed=1
1971    else
1972      if $GO run ${srcdir}/bindings/go/conftest.go ; then
1973        :
1974      else
1975        AC_MSG_WARN([--enable-bindings=go specified, but need at least Go 1.2. Try configure GO=/path/to/go])
1976        binding_prereqs_failed=1
1977      fi
1978    fi
1979    ;;
1980  esac
1981done
1982if test "$binding_prereqs_failed" = 1 ; then
1983  AC_MSG_ERROR([Prequisites for bindings not satisfied. Fix them or use configure --disable-bindings.])
1984fi
1985
1986dnl Determine whether the compiler supports -fvisibility-inlines-hidden.
1987AC_CXX_USE_VISIBILITY_INLINES_HIDDEN
1988
1989dnl Determine linker rpath flag
1990if test "$llvm_cv_link_use_r" = "yes" ; then
1991  RPATH="-Wl,-R"
1992else
1993  RPATH="-Wl,-rpath"
1994fi
1995AC_SUBST(RPATH)
1996
1997dnl Determine linker rdynamic flag
1998if test "$llvm_cv_link_use_export_dynamic" = "yes" ; then
1999  RDYNAMIC="-rdynamic"
2000else
2001  RDYNAMIC=""
2002fi
2003AC_SUBST(RDYNAMIC)
2004
2005AC_DEFINE([LLVM_ENABLE_ABI_BREAKING_CHECKS],[0],
2006          [Define to 1 to checks for ABI changes, and to 0 otherwise.])
2007AC_DEFINE_UNQUOTED([BACKTRACE_HEADER], [<execinfo.h>], [Header containing the backtrace function])
2008
2009AC_DEFINE([LLVM_ENABLE_CRASH_DUMPS], [0], [Enable crash memory dumps (Windows-only)])
2010AC_DEFINE([LLVM_SUPPORT_XCODE_SIGNPOSTS], [0], [Enable support for Xcode signposts (disabled)])
2011
2012dnl===-----------------------------------------------------------------------===
2013dnl===
2014dnl=== SECTION 10: Specify the output files and generate it
2015dnl===
2016dnl===-----------------------------------------------------------------------===
2017
2018dnl Configure header files
2019dnl WARNING: dnl If you add or remove any of the following config headers, then
2020dnl you MUST also update Makefile so that the variable FilesToConfig
2021dnl contains the same list of files as AC_CONFIG_HEADERS below. This ensures the
2022dnl files can be updated automatically when their *.in sources change.
2023AC_CONFIG_HEADERS([include/llvm/Config/config.h include/llvm/Config/llvm-config.h include/llvm/Config/abi-breaking.h])
2024AH_TOP([#ifndef CONFIG_H
2025#define CONFIG_H
2026
2027/* Exported configuration */
2028#include "llvm/Config/llvm-config.h"])
2029AH_BOTTOM([#endif])
2030
2031AC_CONFIG_FILES([include/llvm/Config/Targets.def])
2032AC_CONFIG_FILES([include/llvm/Config/AsmPrinters.def])
2033AC_CONFIG_FILES([include/llvm/Config/AsmParsers.def])
2034AC_CONFIG_FILES([include/llvm/Config/Disassemblers.def])
2035AC_CONFIG_HEADERS([include/llvm/Support/DataTypes.h])
2036
2037dnl Configure clang, if present
2038if test "${clang_src_root}" = ""; then
2039  clang_src_root="$srcdir/tools/clang"
2040fi
2041if test -f ${clang_src_root}/README.txt; then
2042  AC_CONFIG_HEADERS([include/clang/Config/config.h])
2043fi
2044
2045dnl Finally, crank out the output
2046AC_OUTPUT
2047