In LLVM 2.0 we won't use the runtime libraries as llvm-gcc3 support will
[oota-llvm.git] / autoconf / configure.ac
1 dnl === configure.ac --------------------------------------------------------===
2 dnl                     The LLVM Compiler Infrastructure
3 dnl
4 dnl This file was developed by the LLVM research group and is distributed under
5 dnl the University of Illinois Open Source License. See LICENSE.TXT for details.
6 dnl 
7 dnl===-----------------------------------------------------------------------===
8 dnl This is the LLVM configuration script. It is processed by the autoconf
9 dnl program to produce a script named configure. This script contains the 
10 dnl configuration checks that LLVM needs in order to support multiple platforms.
11 dnl This file is composed of 10 sections per the recommended organization of
12 dnl autoconf input defined in the autoconf documentation. As this file evolves,
13 dnl please keep the various types of checks within their sections. The sections
14 dnl are as follows:
15 dnl
16 dnl SECTION 1: Initialization & Setup
17 dnl SECTION 2: Architecture, target, and host checks
18 dnl SECTION 3: Command line arguments for the configure script.
19 dnl SECTION 4: Check for programs we need and that they are the right version
20 dnl SECTION 5: Check for libraries
21 dnl SECTION 6: Check for header files
22 dnl SECTION 7: Check for types and structures
23 dnl SECTION 8: Check for specific functions needed
24 dnl SECTION 9: Additional checks, variables, etc.
25 dnl SECTION 10: Specify the output files and generate it
26 dnl
27 dnl===-----------------------------------------------------------------------===
28 dnl===
29 dnl=== SECTION 1: Initialization & Setup
30 dnl===
31 dnl===-----------------------------------------------------------------------===
32 dnl Initialize autoconf and define the package name, version number and
33 dnl email address for reporting bugs.
34 AC_INIT([[llvm]],[[2.0cvs]],[llvmbugs@cs.uiuc.edu])
35
36 dnl Provide a copyright substitution and ensure the copyright notice is included
37 dnl in the output of --version option of the generated configure script.
38 AC_SUBST(LLVM_COPYRIGHT,["Copyright (c) 2003-2005 University of Illinois at Urbana-Champaign."])
39 AC_COPYRIGHT([Copyright (c) 2003-2005 University of Illinois at Urbana-Champaign.])
40
41 dnl Indicate that we require autoconf 2.59 or later. Ths is needed because we
42 dnl use some autoconf macros only available in 2.59.
43 AC_PREREQ(2.59)
44
45 dnl Verify that the source directory is valid. This makes sure that we are
46 dnl configuring LLVM and not some other package (it validates --srcdir argument)
47 AC_CONFIG_SRCDIR([lib/VMCore/Module.cpp])
48
49 dnl Place all of the extra autoconf files into the config subdirectory. Tell 
50 dnl various tools where the m4 autoconf macros are. 
51 AC_CONFIG_AUX_DIR([autoconf])
52
53 dnl Quit if the source directory has already been configured.
54 dnl NOTE: This relies upon undocumented autoconf behavior.
55 if test ${srcdir} != "." ; then
56   if test -f ${srcdir}/include/llvm/Config/config.h ; then
57     AC_MSG_ERROR([Already configured in ${srcdir}])
58   fi
59 fi
60
61 dnl Configure all of the projects present in our source tree. While we could
62 dnl just AC_CONFIG_SUBDIRS on the set of directories in projects that have a
63 dnl configure script, that usage of the AC_CONFIG_SUBDIRS macro is deprecated.
64 dnl Instead we match on the known projects.
65 for i in `ls ${srcdir}/projects`
66 do
67   if test -d ${srcdir}/projects/${i} ; then
68     case ${i} in
69       "CVS") ;;
70       "sample")       AC_CONFIG_SUBDIRS([projects/sample])    ;;
71       "Stacker")      AC_CONFIG_SUBDIRS([projects/Stacker])   ;;
72       "privbracket")  AC_CONFIG_SUBDIRS([projects/privbracket]) ;;
73       "llvm-test")    AC_CONFIG_SUBDIRS([projects/llvm-test]) ;;
74       "llvm-reopt")   AC_CONFIG_SUBDIRS([projects/llvm-reopt]);;
75       "llvm-gcc")     AC_CONFIG_SUBDIRS([projects/llvm-gcc])  ;;
76       "llvm-java")    AC_CONFIG_SUBDIRS([projects/llvm-java]) ;;
77       "llvm-tv")      AC_CONFIG_SUBDIRS([projects/llvm-tv])   ;;
78       "llvm-poolalloc") AC_CONFIG_SUBDIRS([projects/llvm-poolalloc]) ;;
79       "llvm-kernel")  AC_CONFIG_SUBDIRS([projects/llvm-kernel]) ;;
80       *)              
81         AC_MSG_WARN([Unknown project (${i}) won't be configured automatically])
82         ;;
83     esac
84   fi
85 done
86
87 dnl===-----------------------------------------------------------------------===
88 dnl===
89 dnl=== SECTION 2: Architecture, target, and host checks
90 dnl===
91 dnl===-----------------------------------------------------------------------===
92
93 dnl Check the target for which we're compiling and the host that will do the
94 dnl compilations. This will tell us which LLVM compiler will be used for 
95 dnl compiling SSA into object code. This needs to be done early because 
96 dnl following tests depend on it.
97 AC_CANONICAL_TARGET
98
99 dnl Determine the platform type and cache its value. This helps us configure
100 dnl the System library to the correct build platform.
101 AC_CACHE_CHECK([type of operating system we're going to host on],
102                [llvm_cv_os_type],
103 [case $host in
104   *-*-aix*) 
105     llvm_cv_link_all_option="-Wl,--whole-archive"
106     llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
107     llvm_cv_os_type="AIX" 
108     llvm_cv_platform_type="Unix" ;;
109   *-*-irix*) 
110     llvm_cv_link_all_option="-Wl,--whole-archive"
111     llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
112     llvm_cv_os_type="IRIX" 
113     llvm_cv_platform_type="Unix" ;;
114   *-*-cygwin*) 
115     llvm_cv_link_all_option="-Wl,--whole-archive"
116     llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
117     llvm_cv_os_type="Cygwin" 
118     llvm_cv_platform_type="Unix" ;;
119   *-*-darwin*) 
120     llvm_cv_link_all_option="-Wl,-all_load"
121     llvm_cv_link_all_option="-Wl,-noall_load"
122     llvm_cv_os_type="Darwin"
123     llvm_cv_platform_type="Unix" ;;
124   *-*-freebsd*) 
125     llvm_cv_link_all_option="-Wl,--whole-archive"
126     llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
127     llvm_cv_os_type="FreeBSD" 
128     llvm_cv_platform_type="Unix" ;;
129   *-*-openbsd*) 
130     llvm_cv_link_all_option="-Wl,--whole-archive"
131     llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
132     llvm_cv_os_type="OpenBSD" 
133     llvm_cv_platform_type="Unix" ;;
134   *-*-hpux*) 
135     llvm_cv_link_all_option="-Wl,--whole-archive"
136     llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
137     llvm_cv_os_type="HP-UX" 
138     llvm_cv_platform_type="Unix" ;;
139   *-*-interix*) 
140     llvm_cv_link_all_option="-Wl,--whole-archive"
141     llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
142     llvm_cv_os_type="Interix"
143     llvm_cv_platform_type="Unix" ;;
144   *-*-linux*) 
145     llvm_cv_link_all_option="-Wl,--whole-archive"
146     llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
147     llvm_cv_os_type="Linux"
148     llvm_cv_platform_type="Unix" ;;
149   *-*-solaris*) 
150     llvm_cv_link_all_option="-Wl,-z,allextract"
151     llvm_cv_no_link_all_option="-Wl,-z,defaultextract"
152     llvm_cv_os_type="SunOS"
153     llvm_cv_platform_type="Unix" ;;
154   *-*-win32*) 
155     llvm_cv_link_all_option="-Wl,--whole-archive"
156     llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
157     llvm_cv_os_type="Win32"
158     llvm_cv_platform_type="Win32" ;;
159   *-*-mingw*) 
160     llvm_cv_link_all_option="-Wl,--whole-archive"
161     llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
162     llvm_cv_os_type="MingW" 
163     llvm_cv_platform_type="Win32" ;;
164   *) 
165     llvm_cv_link_all_option="" 
166     llvm_cv_no_link_all_option=""
167     llvm_cv_os_type="Unknown" 
168     llvm_cv_platform_type="Unknown" ;;
169 esac])
170
171 dnl Make sure we aren't attempting to configure for an unknown system
172 if test "$llvm_cv_os_type" = "Unknown" ; then
173   AC_MSG_ERROR([Operating system is unknown, configure can't continue])
174 fi
175
176 dnl Set the "OS" Makefile variable based on the platform type so the
177 dnl makefile can configure itself to specific build hosts
178 AC_SUBST(OS,$llvm_cv_os_type)
179
180 dnl Set the LINKALL and NOLINKALL Makefile variables based on the platform
181 AC_SUBST(LINKALL,$llvm_cv_link_all_option)
182 AC_SUBST(NOLINKALL,$llvm_cv_no_link_all_option)
183
184 dnl Set the "LLVM_ON_*" variables based on llvm_cvs_platform_type
185 dnl This is used by lib/System to determine the basic kind of implementation
186 dnl to use.
187 case $llvm_cv_platform_type in
188   Unix)  
189     AC_DEFINE([LLVM_ON_UNIX],[1],[Define if this is Unixish platform]) 
190     AC_SUBST(LLVM_ON_UNIX,[1])
191     AC_SUBST(LLVM_ON_WIN32,[0])
192     ;;
193   Win32) 
194     AC_DEFINE([LLVM_ON_WIN32],[1],[Define if this is Win32ish platform]) 
195     AC_SUBST(LLVM_ON_UNIX,[0])
196     AC_SUBST(LLVM_ON_WIN32,[1])
197     ;;
198 esac
199
200 dnl Determine what our target architecture is and configure accordingly.
201 dnl This will allow Makefiles to make a distinction between the hardware and
202 dnl the OS.
203 AC_CACHE_CHECK([target architecture],[llvm_cv_target_arch],
204 [case $target in
205   i?86-*)                 llvm_cv_target_arch="x86" ;;
206   amd64-* | x86_64-*)     llvm_cv_target_arch="x86_64" ;;
207   sparc*-*)               llvm_cv_target_arch="Sparc" ;;
208   powerpc*-*)             llvm_cv_target_arch="PowerPC" ;;
209   alpha*-*)               llvm_cv_target_arch="Alpha" ;;
210   ia64-*)                 llvm_cv_target_arch="IA64" ;;
211   *)                      llvm_cv_target_arch="Unknown" ;;
212 esac])
213
214 if test "$llvm_cv_target_arch" = "Unknown" ; then
215   AC_MSG_WARN([Configuring LLVM for an unknown target archicture])
216 fi
217
218 dnl Define a substitution, ARCH, for the target architecture
219 AC_SUBST(ARCH,$llvm_cv_target_arch)
220
221 dnl Check for the endianness of the target
222 AC_C_BIGENDIAN(AC_SUBST([ENDIAN],[big]),AC_SUBST([ENDIAN],[little]))
223
224 dnl Check for build platform executable suffix if we're crosscompiling
225 if test "$cross_compiling" = yes; then
226   AC_SUBST(LLVM_CROSS_COMPILING, [1])  
227   AC_BUILD_EXEEXT
228 else
229   AC_SUBST(LLVM_CROSS_COMPILING, [0])
230 fi
231
232 dnl Check to see if there's a "CVS" directory indicating that this build is
233 dnl being done from a CVS checkout. This sets up several defaults for the
234 dnl command line switches. When we build with a CVS directory, we get a 
235 dnl debug with assertions turned on. Without, we assume a source release and we
236 dnl get an optimized build without assertions. See --enable-optimized and
237 dnl --enable-assertions below
238 if test -d "CVS" -o -d "${srcdir}/CVS"; then
239   cvsbuild="yes"
240   optimize="no"
241   AC_SUBST(CVSBUILD,[[CVSBUILD=1]])
242 else
243   cvsbuild="no"
244   optimize="yes"
245 fi
246
247 dnl===-----------------------------------------------------------------------===
248 dnl===
249 dnl=== SECTION 3: Command line arguments for the configure script.
250 dnl===
251 dnl===-----------------------------------------------------------------------===
252
253 dnl --enable-optimized : check whether they want to do an optimized build:
254 AC_ARG_ENABLE(optimized, AS_HELP_STRING(
255  [--enable-optimized,Compile with optimizations enabled (default is NO)]),,enableval=$optimize)
256 if test ${enableval} = "no" ; then
257   AC_SUBST(ENABLE_OPTIMIZED,[[]])
258 else
259   AC_SUBST(ENABLE_OPTIMIZED,[[ENABLE_OPTIMIZED=1]])
260 fi
261
262 dnl --enable-assertions : check whether they want to turn on assertions or not:
263 AC_ARG_ENABLE(assertions,AS_HELP_STRING(
264   [--enable-assertions,Compile with assertion checks enabled (default is YES)]),, enableval="yes")
265 if test ${enableval} = "yes" ; then
266   AC_SUBST(DISABLE_ASSERTIONS,[[]])
267 else
268   AC_SUBST(DISABLE_ASSERTIONS,[[DISABLE_ASSERTIONS=1]])
269 fi
270
271 dnl --enable-jit: check whether they want to enable the jit
272 AC_ARG_ENABLE(jit,
273   AS_HELP_STRING(--enable-jit,
274                  [Enable Just In Time Compiling (default is YES)]),,
275   enableval=default)
276 if test ${enableval} = "no"
277 then
278   AC_SUBST(JIT,[[]])
279 else
280   case "$llvm_cv_target_arch" in
281     x86)     AC_SUBST(TARGET_HAS_JIT,1) ;;
282     Sparc)   AC_SUBST(TARGET_HAS_JIT,1) ;;
283     PowerPC) AC_SUBST(TARGET_HAS_JIT,1) ;;
284     x86_64)  AC_SUBST(TARGET_HAS_JIT,0) ;;
285     Alpha)   AC_SUBST(TARGET_HAS_JIT,1) ;;
286     IA64)    AC_SUBST(TARGET_HAS_JIT,0) ;;
287     *)       AC_SUBST(TARGET_HAS_JIT,0) ;;
288   esac
289 fi
290
291 dnl Allow enablement of doxygen generated documentation
292 AC_ARG_ENABLE(doxygen,
293               AS_HELP_STRING([--enable-doxygen],
294                              [Build doxygen documentation (default is NO)]),,
295                              enableval=default)
296 case "$enableval" in
297   yes) AC_SUBST(ENABLE_DOXYGEN,[1]) ;;
298   no)  AC_SUBST(ENABLE_DOXYGEN,[0]) ;;
299   default) AC_SUBST(ENABLE_DOXYGEN,[0]) ;;
300   *) AC_MSG_ERROR([Invalid setting for --enable-doxygen. Use "yes" or "no"]) ;;
301 esac
302
303 dnl Allow disablement of threads
304 AC_ARG_ENABLE(threads,
305               AS_HELP_STRING([--enable-threads],
306                              [Use threads if available (default is YES)]),,
307                              enableval=default)
308 case "$enableval" in
309   yes) AC_SUBST(ENABLE_THREADS,[1]) ;;
310   no)  AC_SUBST(ENABLE_THREADS,[0]) ;;
311   default) AC_SUBST(ENABLE_THREADS,[1]) ;;
312   *) AC_MSG_ERROR([Invalid setting for --enable-threads. Use "yes" or "no"]) ;;
313 esac
314 AC_DEFINE_UNQUOTED([ENABLE_THREADS],$ENABLE_THREADS,[Define if threads enabled])
315
316 dnl Allow specific targets to be specified for building (or not)
317 TARGETS_TO_BUILD=""
318 AC_ARG_ENABLE([targets],AS_HELP_STRING([--enable-targets],
319     [Build specific host targets: all,host-only,{target-name} (default=all)]),,
320     enableval=all)
321 case "$enableval" in
322   all) TARGETS_TO_BUILD="X86 Sparc PowerPC Alpha IA64 ARM" ;;
323   host-only)
324     case "$llvm_cv_target_arch" in
325       x86)     TARGETS_TO_BUILD="X86" ;;
326       x86_64)  TARGETS_TO_BUILD="X86" ;;
327       Sparc)   TARGETS_TO_BUILD="Sparc" ;;
328       PowerPC) TARGETS_TO_BUILD="PowerPC" ;;
329       Alpha)   TARGETS_TO_BUILD="Alpha" ;;
330       IA64)    TARGETS_TO_BUILD="IA64" ;;
331       *)       AC_MSG_ERROR([Can not set target to build]) ;;
332     esac 
333     ;;
334   *)for a_target in `echo $enableval|sed -e 's/,/ /g' ` ; do
335       case "$a_target" in
336         x86)     TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
337         x86_64)  TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
338         sparc)   TARGETS_TO_BUILD="Sparc $TARGETS_TO_BUILD" ;;
339         powerpc) TARGETS_TO_BUILD="PowerPC $TARGETS_TO_BUILD" ;;
340         alpha)   TARGETS_TO_BUILD="Alpha $TARGETS_TO_BUILD" ;;
341         ia64)    TARGETS_TO_BUILD="IA64 $TARGETS_TO_BUILD" ;;
342         *) AC_MSG_ERROR([Unrecognized target $a_target]) ;;
343       esac
344   done 
345   ;;
346 esac
347 TARGETS_TO_BUILD="CBackend $TARGETS_TO_BUILD"
348 AC_SUBST(TARGETS_TO_BUILD,$TARGETS_TO_BUILD)
349
350 dnl Prevent the CBackend from using printf("%a") for floating point so older
351 dnl C compilers that cannot deal with the 0x0p+0 hex floating point format
352 dnl can still compile the CBE's output
353 AC_ARG_ENABLE([cbe-printf-a],AS_HELP_STRING([--enable-cbe-printf-a],
354   [Enable C Backend output with hex floating point via %a  (default is YES)]),,
355   enableval=default)
356 case "$enableval" in
357   yes) AC_SUBST(ENABLE_CBE_PRINTF_A,[1]) ;;
358   no)  AC_SUBST(ENABLE_CBE_PRINTF_A,[0]) ;;
359   default)  AC_SUBST(ENABLE_CBE_PRINTF_A,[1]) ;;
360   *) AC_MSG_ERROR([Invalid setting for --enable-cbe-printf-a. Use "yes" or "no"]) ;;
361 esac
362 AC_DEFINE_UNQUOTED([ENABLE_CBE_PRINTF_A],$ENABLE_CBE_PRINTF_A,
363                    [Define if CBE is enabled for printf %a output])
364
365 dnl Allow a specific llvm-gcc/llvm-g++ pair to be used with this LLVM config.
366 AC_ARG_WITH(llvmgccdir,
367   AS_HELP_STRING([--with-llvmgccdir],
368     [Specify location of llvm-gcc install dir (default searches PATH)]),,
369     withval=default)
370 case "$withval" in
371   default) WITH_LLVMGCCDIR=default ;;
372   /* | [[A-Za-z]]:[[\\/]]*)      WITH_LLVMGCCDIR=$withval ;;
373   *) AC_MSG_ERROR([Invalid path for --with-llvmgccdir. Provide full path]) ;;
374 esac
375
376 dnl Specify extra build options
377 AC_ARG_WITH(extra-options,
378   AS_HELP_STRING([--with-extra-options],
379                  [Specify addtional options to compile LLVM with]),,
380                  withval=default)
381 case "$withval" in
382   default) EXTRA_OPTIONS= ;;
383   *) EXTRA_OPTIONS=$withval ;;
384 esac
385 AC_SUBST(EXTRA_OPTIONS,$EXTRA_OPTIONS)
386
387 dnl===-----------------------------------------------------------------------===
388 dnl===
389 dnl=== SECTION 4: Check for programs we need and that they are the right version
390 dnl===
391 dnl===-----------------------------------------------------------------------===
392
393 dnl Check for compilation tools
394 AC_PROG_CPP
395 AC_PROG_CC(gcc)
396 AC_PROG_CXX(g++)
397 AC_PROG_FLEX
398 AC_PROG_BISON
399
400 AC_PROG_NM
401 AC_SUBST(NM)
402
403 dnl Check for the tools that the makefiles require
404 AC_CHECK_GNU_MAKE
405 AC_PROG_LN_S
406 AC_PATH_PROG(CMP, [cmp], [cmp])
407 AC_PATH_PROG(CP, [cp], [cp])
408 AC_PATH_PROG(DATE, [date], [date])
409 AC_PATH_PROG(FIND, [find], [find])
410 AC_PATH_PROG(GREP, [grep], [grep])
411 AC_PATH_PROG(MKDIR,[mkdir],[mkdir])
412 AC_PATH_PROG(MV,   [mv],   [mv])
413 AC_PROG_RANLIB
414 AC_PATH_PROG(RM,   [rm],   [rm])
415 AC_PATH_PROG(SED,  [sed],  [sed])
416 AC_PATH_PROG(TAR,  [tar],  [gtar])
417 AC_PATH_PROG(BINPWD,[pwd],  [pwd])
418
419 dnl Looking for misc. graph plotting software
420 AC_PATH_PROG(GRAPHVIZ, [Graphviz], [echo Graphviz])
421 if test "$GRAPHVIZ" != "echo Graphviz" ; then
422   AC_DEFINE([HAVE_GRAPHVIZ],[1],[Define if the Graphviz program is available])
423   dnl If we're targeting for mingw we should emit windows paths, not msys
424   if test "$llvm_cv_os_type" == "MingW" ; then
425     GRAPHVIZ=`echo $GRAPHVIZ | sed 's/^\/\([[A-Za-z]]\)\//\1:\//' `
426   fi
427   AC_DEFINE_UNQUOTED([LLVM_PATH_GRAPHVIZ],"$GRAPHVIZ${EXEEXT}",
428    [Define to path to Graphviz program if found or 'echo Graphviz' otherwise])
429 fi
430 AC_PATH_PROG(DOT, [dot], [echo dot])
431 if test "$DOT" != "echo dot" ; then
432   AC_DEFINE([HAVE_DOT],[1],[Define if the dot program is available])
433   dnl If we're targeting for mingw we should emit windows paths, not msys
434   if test "$llvm_cv_os_type" == "MingW" ; then
435     DOT=`echo $DOT | sed 's/^\/\([[A-Za-z]]\)\//\1:\//' `
436   fi
437   AC_DEFINE_UNQUOTED([LLVM_PATH_DOT],"$DOT${EXEEXT}",
438    [Define to path to dot program if found or 'echo dot' otherwise])
439 fi
440 AC_PATH_PROGS(GV, [gv gsview32], [echo gv])
441 if test "$GV" != "echo gv" ; then
442   AC_DEFINE([HAVE_GV],[1],[Define if the gv program is available])
443   dnl If we're targeting for mingw we should emit windows paths, not msys
444   if test "$llvm_cv_os_type" == "MingW" ; then
445     GV=`echo $GV | sed 's/^\/\([[A-Za-z]]\)\//\1:\//' `
446   fi
447   AC_DEFINE_UNQUOTED([LLVM_PATH_GV],"$GV${EXEEXT}",
448    [Define to path to gv program if found or 'echo gv' otherwise])
449 fi
450 AC_PATH_PROG(DOTTY, [dotty], [echo dotty])
451 if test "$DOTTY" != "echo dotty" ; then
452   AC_DEFINE([HAVE_DOTTY],[1],[Define if the dotty program is available])
453   dnl If we're targeting for mingw we should emit windows paths, not msys
454   if test "$llvm_cv_os_type" == "MingW" ; then
455     DOTTY=`echo $DOTTY | sed 's/^\/\([[A-Za-z]]\)\//\1:\//' `
456   fi
457   AC_DEFINE_UNQUOTED([LLVM_PATH_DOTTY],"$DOTTY${EXEEXT}",
458    [Define to path to dotty program if found or 'echo dotty' otherwise])
459 fi
460
461 dnl Look for a sufficiently recent version of Perl.
462 LLVM_PROG_PERL([5.006])
463 AC_SUBST(PERL)
464 if test x"$PERL" = xnone; then
465    AC_SUBST(HAVE_PERL,0)
466 else
467    AC_SUBST(HAVE_PERL,1)
468 fi
469
470 dnl Find the install program
471 AC_PROG_INSTALL
472
473 dnl Checks for documentation and testing tools that we can do without. If these
474 dnl are not found then they are set to "true" which always succeeds but does
475 dnl nothing. This just lets the build output show that we could have done 
476 dnl something if the tool was available. 
477 AC_PATH_PROG(BZIP2,[bzip2],[echo "Skipped: bzip2 not found"])
478 AC_PATH_PROG(DOXYGEN,[doxygen],[echo "Skipped: doxygen not found"])
479 AC_PATH_PROG(GROFF,[groff],[echo "Skipped: groff not found"])
480 AC_PATH_PROG(GZIP,[gzip],[echo "Skipped: gzip not found"])
481 AC_PATH_PROG(POD2HTML,[pod2html],[echo "Skipped: pod2html not found"])
482 AC_PATH_PROG(POD2MAN,[pod2man],[echo "Skipped: pod2man not found"])
483 AC_PATH_PROG(RUNTEST,[runtest],[echo "Skipped: runtest not found"])
484 DJ_AC_PATH_TCLSH
485 AC_PATH_PROG(ZIP,[zip],[echo "Skipped: zip not found"])
486
487 dnl Determine if the linker supports the -R option.
488 AC_LINK_USE_R
489
490 dnl Check for libtool and the library that has dlopen function (which must come
491 dnl before the AC_PROG_LIBTOOL check in order to enable dlopening libraries with
492 dnl libtool).
493 AC_LIBTOOL_DLOPEN
494 AC_LIB_LTDL
495 AC_PROG_LIBTOOL
496
497 if test "$lt_cv_dlopen_self" = "yes" ; then
498   AC_DEFINE([CAN_DLOPEN_SELF],[1],
499               [Define if dlopen(0) will open the symbols of the program])
500 fi
501
502 dnl Check if we know how to tell etags we are using C++:
503 etags_version=`$ETAGS --version 2>&1`
504 case "$etags_version" in
505         *[Ee]xuberant*) ETAGSFLAGS="--language-force=c++" ;;
506         *GNU\ Emacs*) ETAGSFLAGS="-l c++" ;;
507         *) ETAGSFLAGS="" ;;
508 esac
509 AC_SUBST(ETAGSFLAGS,$ETAGSFLAGS)
510
511 if test "$WITH_LLVMGCCDIR" = "default" ; then
512   LLVMGCC="llvm-gcc${EXEEXT}"
513   LLVMGXX="llvm-g++${EXEEXT}"
514   AC_PATH_PROG(LLVMGCC, $LLVMGCC, [])
515   AC_PATH_PROG(LLVMGXX, $LLVMGXX, [])
516 else
517   LLVMGCC="$WITH_LLVMGCCDIR/bin/llvm-gcc${EXEEXT}"
518   LLVMGXX="$WITH_LLVMGCCDIR/bin/llvm-g++${EXEEXT}"
519   AC_SUBST(LLVMGCC,$LLVMGCC)
520   AC_SUBST(LLVMGXX,$LLVMGXX)
521 fi
522   
523 AC_MSG_CHECKING([tool compatibility])
524
525 dnl Ensure that compilation tools are GCC or a GNU compatible compiler such as
526 dnl ICC; we use GCC specific options in the makefiles so the compiler needs
527 dnl to support those options.
528 dnl "icc" emits gcc signatures
529 dnl "icc -no-gcc" emits no gcc signature BUT is still compatible
530 ICC=no
531 IXX=no
532 case $CC in
533   icc*|icpc*) 
534     ICC=yes
535     IXX=yes
536     ;;
537    *)
538     ;;
539 esac
540
541 if test "$GCC" != "yes" && test "$ICC" != "yes"
542 then
543   AC_MSG_ERROR([gcc|icc required but not found])
544 fi
545
546 dnl Ensure that compilation tools are GCC; we use GCC specific extensions
547 if test "$GXX" != "yes" && test "$IXX" != "yes"
548 then
549   AC_MSG_ERROR([g++|icc required but not found])
550 fi
551
552 dnl Verify that GCC is version 3.0 or higher
553 if test "$GCC" = "yes"
554 then
555   gccmajor=`$CC --version | head -n 1 | sed 's/[[^0-9]]*\([[0-9.]]\).*/\1/'` 
556   if test "$gccmajor" -lt "3"
557   then
558     AC_MSG_ERROR([gcc 3.x required, but you have a lower version])
559   fi
560 fi
561
562 dnl Check for GNU Make.  We use its extensions, so don't build without it
563 if test -z "$llvm_cv_gnu_make_command"
564 then
565   AC_MSG_ERROR([GNU Make required but not found])
566 fi
567
568 dnl Tool compatibility is okay if we make it here.
569 AC_MSG_RESULT([ok])
570
571 dnl===-----------------------------------------------------------------------===
572 dnl===
573 dnl=== SECTION 5: Check for libraries
574 dnl===
575 dnl===-----------------------------------------------------------------------===
576
577 dnl libelf is for sparc only; we can ignore it if we don't have it
578 AC_CHECK_LIB(elf, elf_begin)
579 AC_CHECK_LIB(m,sin)
580 if test "$llvm_cv_os_type" == "MingW" ; then
581   AC_CHECK_LIB(imagehlp, main)
582   AC_CHECK_LIB(psapi, main)
583 fi
584
585 dnl lt_dlopen may be required for plugin support.
586 AC_SEARCH_LIBS(lt_dlopen,ltdl,AC_DEFINE([HAVE_LT_DLOPEN],[1],
587               [Define if lt_dlopen() is available on this platform]),
588               AC_MSG_WARN([lt_dlopen() not found - plugin support might 
589                            not be available]))
590
591 dnl dlopen() is required for plugin support.
592 AC_SEARCH_LIBS(dlopen,dl,AC_DEFINE([HAVE_DLOPEN],[1],
593                [Define if dlopen() is available on this platform.]),
594                AC_MSG_WARN([dlopen() not found - disabling plugin support]))
595
596 dnl mallinfo is optional; the code can compile (minus features) without it
597 AC_SEARCH_LIBS(mallinfo,malloc,AC_DEFINE([HAVE_MALLINFO],[1],
598                [Define if mallinfo() is available on this platform.]))
599
600 dnl pthread locking functions are optional - but llvm will not be thread-safe
601 dnl without locks.
602 if test "$ENABLE_THREADS" -eq 1 ; then
603   AC_CHECK_LIB(pthread,pthread_mutex_init)
604   AC_SEARCH_LIBS(pthread_mutex_lock,pthread,
605                  AC_DEFINE([HAVE_PTHREAD_MUTEX_LOCK],[1],
606                            [Have pthread_mutex_lock]))
607 fi
608
609 dnl===-----------------------------------------------------------------------===
610 dnl===
611 dnl=== SECTION 6: Check for header files
612 dnl===
613 dnl===-----------------------------------------------------------------------===
614
615 dnl First, use autoconf provided macros for specific headers that we need
616 dnl We don't check for ancient stuff or things that are guaranteed to be there
617 dnl by the C++ standard. We always use the <cfoo> versions of <foo.h> C headers.
618 dnl Generally we're looking for POSIX headers.
619 AC_HEADER_DIRENT
620 AC_HEADER_MMAP_ANONYMOUS
621 AC_HEADER_STAT
622 AC_HEADER_STDC
623 AC_HEADER_SYS_WAIT
624 AC_HEADER_TIME
625
626 AC_CHECK_HEADERS([dlfcn.h execinfo.h fcntl.h inttypes.h limits.h link.h])
627 AC_CHECK_HEADERS([malloc.h setjmp.h signal.h stdint.h unistd.h utime.h])
628 AC_CHECK_HEADERS([windows.h sys/mman.h sys/param.h sys/resource.h sys/time.h])
629 AC_CHECK_HEADERS([sys/types.h malloc/malloc.h mach/mach.h])
630 if test "$ENABLE_THREADS" -eq 1 ; then
631   AC_CHECK_HEADERS(pthread.h)
632 fi
633
634 dnl===-----------------------------------------------------------------------===
635 dnl===
636 dnl=== SECTION 7: Check for types and structures
637 dnl===
638 dnl===-----------------------------------------------------------------------===
639
640 AC_HUGE_VAL_CHECK
641 AC_TYPE_PID_T
642 AC_TYPE_SIZE_T
643 AC_TYPE_SIGNAL
644 AC_STRUCT_TM
645 AC_CHECK_TYPES([int64_t],,AC_MSG_ERROR([Type int64_t required but not found]))
646 AC_CHECK_TYPES([uint64_t],,
647          AC_CHECK_TYPES([u_int64_t],,
648          AC_MSG_ERROR([Type uint64_t or u_int64_t required but not found])))
649
650 dnl===-----------------------------------------------------------------------===
651 dnl===
652 dnl=== SECTION 8: Check for specific functions needed
653 dnl===
654 dnl===-----------------------------------------------------------------------===
655
656 AC_CHECK_FUNCS([backtrace ceilf floorf roundf rintf nearbyintf getcwd ])
657 AC_CHECK_FUNCS([getpagesize getrusage gettimeofday isatty mkdtemp mkstemp ])
658 AC_CHECK_FUNCS([mktemp realpath sbrk setrlimit strdup strerror strerror_r ])
659 AC_CHECK_FUNCS([strtoll strtoq sysconf malloc_zone_statistics ])
660 AC_CHECK_FUNCS([_setjmp _longjmp setjmp longjmp sigsetjmp siglongjmp])
661 AC_C_PRINTF_A
662 AC_FUNC_ALLOCA
663 AC_FUNC_RAND48
664
665 dnl Check for variations in the Standard C++ library and STL. These macros are
666 dnl provided by LLVM in the autoconf/m4 directory.
667 AC_CXX_HAVE_HASH_MAP
668 AC_CXX_HAVE_HASH_SET
669 AC_CXX_HAVE_STD_ITERATOR
670 AC_CXX_HAVE_BI_ITERATOR
671 AC_CXX_HAVE_FWD_ITERATOR
672 AC_FUNC_ISNAN
673 AC_FUNC_ISINF
674
675 dnl Check for mmap and mprotect support. We need both to do the JIT and for
676 dnl bytecode loading, etc. We also need to know if /dev/zero is required to
677 dnl be opened for allocating RWX memory.
678 AC_FUNC_MMAP
679 AC_FUNC_MMAP_FILE
680 AC_NEED_DEV_ZERO_FOR_MMAP
681 AC_CHECK_FUNC(mprotect,,
682               AC_MSG_ERROR([Function mprotect() required but not found]))
683
684 if test "$ac_cv_func_mmap_fixed_mapped" = "no"
685 then
686   AC_MSG_WARN([mmap() of a fixed address required but not supported])
687 fi
688 if test "$ac_cv_func_mmap_file" = "no"
689 then
690   AC_MSG_WARN([mmap() of files required but not found])
691 fi
692
693 dnl===-----------------------------------------------------------------------===
694 dnl===
695 dnl=== SECTION 9: Additional checks, variables, etc.
696 dnl===
697 dnl===-----------------------------------------------------------------------===
698
699 dnl See if the llvm-gcc executable can compile to LLVM assembly
700 AC_CACHE_CHECK([whether llvm-gcc is sane],[llvm_cv_llvmgcc_sanity],
701 [llvm_cv_llvmgcc_sanity="no"
702 if test -x "$LLVMGCC" ; then
703   cp /dev/null conftest.c
704   "$LLVMGCC" -emit-llvm -S -o - conftest.c | grep implementation > /dev/null 2>&1
705   if test $? -eq 0 ; then
706     llvm_cv_llvmgcc_sanity="yes"
707   fi
708   rm conftest.c
709 fi])
710
711 dnl Since we have a sane llvm-gcc, identify it and its sub-tools 
712 if test "$llvm_cv_llvmgcc_sanity" = "yes" ; then
713   llvmcc1path=`"$LLVMGCC" --print-prog-name=cc1`
714   AC_SUBST(LLVMCC1,$llvmcc1path)
715   llvmcc1pluspath=`"$LLVMGCC" --print-prog-name=cc1plus`
716   AC_SUBST(LLVMCC1PLUS,$llvmcc1pluspath)
717   llvmgccdir=`echo "$llvmcc1path" | sed 's,/libexec/.*,,'`
718   AC_SUBST(LLVMGCCDIR,$llvmgccdir)
719   llvmgccversion=[`"$LLVMGCC" -dumpversion 2>&1 | sed 's/^\([0-9.]*\).*/\1/'`]
720   llvmgccmajvers=[`echo $llvmgccversion | sed 's/^\([0-9]\).*/\1/'`]
721   AC_SUBST(LLVMGCC_VERSION,$llvmgccversion)
722   AC_SUBST(LLVMGCC_MAJVERS,$llvmgccmajvers)
723 fi
724
725 dnl Propagate the shared library extension that the libltdl checks did to 
726 dnl the Makefiles so we can use it there too
727 AC_SUBST(SHLIBEXT,$libltdl_cv_shlibext)
728
729 # Translate the various configuration directories and other basic
730 # information into substitutions that will end up in Makefile.config.in 
731 # that these configured values can be used by the makefiles
732 if test "${prefix}" == "NONE" ; then
733   prefix="/usr/local"
734 fi
735 eval LLVM_PREFIX="${prefix}";
736 eval LLVM_BINDIR="${prefix}/bin";
737 eval LLVM_LIBDIR="${prefix}/lib";
738 eval LLVM_DATADIR="${prefix}/share/llvm";
739 eval LLVM_DOCSDIR="${prefix}/docs/llvm";
740 eval LLVM_ETCDIR="${prefix}/etc/llvm";
741 eval LLVM_INCLUDEDIR="${prefix}/include";
742 eval LLVM_INFODIR="${prefix}/info";
743 eval LLVM_MANDIR="${prefix}/man";
744 LLVM_CONFIGTIME=`date`
745 AC_SUBST(LLVM_PREFIX)
746 AC_SUBST(LLVM_BINDIR)
747 AC_SUBST(LLVM_LIBDIR)
748 AC_SUBST(LLVM_DATADIR)
749 AC_SUBST(LLVM_DOCSDIR)
750 AC_SUBST(LLVM_ETCDIR)
751 AC_SUBST(LLVM_INCLUDEDIR)
752 AC_SUBST(LLVM_INFODIR)
753 AC_SUBST(LLVM_MANDIR)
754 AC_SUBST(LLVM_CONFIGTIME)
755
756 # Place the various directores into the config.h file as #defines so that we
757 # can know about the installation paths within LLVM.
758 AC_DEFINE_UNQUOTED(LLVM_PREFIX,"$LLVM_PREFIX", 
759                    [Installation prefix directory])
760 AC_DEFINE_UNQUOTED(LLVM_BINDIR, "$LLVM_BINDIR", 
761                    [Installation directory for binary executables])
762 AC_DEFINE_UNQUOTED(LLVM_LIBDIR, "$LLVM_LIBDIR", 
763                    [Installation directory for libraries])
764 AC_DEFINE_UNQUOTED(LLVM_DATADIR, "$LLVM_DATADIR", 
765                    [Installation directory for data files])
766 AC_DEFINE_UNQUOTED(LLVM_DATADIR, "$LLVM_DOCSDIR", 
767                    [Installation directory for documentation])
768 AC_DEFINE_UNQUOTED(LLVM_ETCDIR, "$LLVM_ETCDIR", 
769                    [Installation directory for config files])
770 AC_DEFINE_UNQUOTED(LLVM_INCLUDEDIR, "$LLVM_INCLUDEDIR", 
771                    [Installation directory for include files])
772 AC_DEFINE_UNQUOTED(LLVM_INFODIR, "$LLVM_INFODIR", 
773                    [Installation directory for .info files])
774 AC_DEFINE_UNQUOTED(LLVM_MANDIR, "$LLVM_MANDIR", 
775                    [Installation directory for man pages])
776 AC_DEFINE_UNQUOTED(LLVM_CONFIGTIME, "$LLVM_CONFIGTIME", 
777                    [Time at which LLVM was configured])
778
779 dnl===-----------------------------------------------------------------------===
780 dnl===
781 dnl=== SECTION 10: Specify the output files and generate it
782 dnl===
783 dnl===-----------------------------------------------------------------------===
784
785 dnl Configure header files
786 dnl WARNING: dnl If you add or remove any of the following config headers, then
787 dnl you MUST also update Makefile.rules so that the variable FilesToConfig
788 dnl contains the same list of files as AC_CONFIG_HEADERS below. This ensures the
789 dnl files can be updated automatically when their *.in sources change.
790 AC_CONFIG_HEADERS([include/llvm/Config/config.h])
791 AC_CONFIG_HEADERS([include/llvm/Support/DataTypes.h])
792 AC_CONFIG_HEADERS([include/llvm/ADT/hash_map])
793 AC_CONFIG_HEADERS([include/llvm/ADT/hash_set])
794 AC_CONFIG_HEADERS([include/llvm/ADT/iterator])
795
796 dnl Configure the makefile's configuration data
797 AC_CONFIG_FILES([Makefile.config])
798
799 dnl Configure the RPM spec file for LLVM
800 AC_CONFIG_FILES([llvm.spec])
801
802 dnl Configure doxygen's configuration file
803 AC_CONFIG_FILES([docs/doxygen.cfg])
804
805 dnl Do the first stage of configuration for llvm-config.in.
806 AC_CONFIG_FILES([tools/llvm-config/llvm-config.in])
807
808 dnl Do special configuration of Makefiles
809 AC_CONFIG_COMMANDS([setup],,[llvm_src="${srcdir}"])
810 AC_CONFIG_MAKEFILE(Makefile)
811 AC_CONFIG_MAKEFILE(Makefile.common)
812 AC_CONFIG_MAKEFILE(examples/Makefile)
813 AC_CONFIG_MAKEFILE(lib/Makefile)
814 AC_CONFIG_MAKEFILE(test/Makefile)
815 AC_CONFIG_MAKEFILE(test/Makefile.tests)
816 AC_CONFIG_MAKEFILE(tools/Makefile)
817 AC_CONFIG_MAKEFILE(utils/Makefile)
818 AC_CONFIG_MAKEFILE(projects/Makefile)
819
820 dnl Finally, crank out the output
821 AC_OUTPUT
822
823 dnl Warn loudly if llvm-gcc was not obviously working
824 if test "$llvm_cv_llvmgcc_sanity" = "no" ; then
825  AC_MSG_WARN([***** llvm-gcc/llvm-g++ was not found, or does not appear to be ])
826  AC_MSG_WARN([***** working. Please make sure you have llvm-gcc and llvm-g++ ])
827  AC_MSG_WARN([***** in your path before configuring LLVM.])
828 fi