c7a0bfcf6a7eee2201c3d3b2f789a28a0416b349
[oota-llvm.git] / autoconf / configure.ac
1 dnl Initialize autoconf
2 AC_INIT([[LLVM]],[[1.4]],[llvmbugs@cs.uiuc.edu])
3
4 dnl Place all of the extra autoconf files into the config subdirectory
5 dnl Tell various tools where the m4 autoconf macros are
6 dnl Have configure verify that the source directory is valid.
7 AC_CONFIG_AUX_DIR([autoconf])
8 dnl AC_CONFIG_MACRO_DIR(autoconf/m4)
9 dnl Verify that the source directory is valid
10 AC_CONFIG_SRCDIR(["Makefile.config.in"])
11
12 dnl Quit if the source directory has already been configured.
13 dnl NOTE: This relies upon undocumented autoconf behavior.
14 if test ${srcdir} != "." ; then
15         if test -f ${srcdir}/include/llvm/Config/config.h ; then
16                 AC_MSG_ERROR([Already configured in ${srcdir}])
17         fi
18 fi
19
20 dnl Configure all of the projects present in our source tree.
21 for i in `ls ${srcdir}/projects`
22 do
23   if test -d ${srcdir}/projects/${i} ; then
24     case ${i} in
25       "CVS") ;;
26       "sample")       AC_CONFIG_SUBDIRS([projects/sample])    ;;
27       "Stacker")      AC_CONFIG_SUBDIRS([projects/Stacker])   ;;
28       "llvm-test")    AC_CONFIG_SUBDIRS([projects/llvm-test]) ;;
29       "llvm-reopt")   AC_CONFIG_SUBDIRS([projects/llvm-reopt]);;
30       "llvm-gcc")     AC_CONFIG_SUBDIRS([projects/llvm-gcc])  ;;
31       "Java")         AC_CONFIG_SUBDIRS([projects/Java])      ;;
32       "llvm-tv")      AC_CONFIG_SUBDIRS([projects/llvm-tv])   ;;
33       "llvm-fefw")    AC_CONFIG_SUBDIRS([projects/llvm-fefw]) ;;
34       *)              
35         AC_MSG_WARN([Unknown project (${i}) won't be configured automatically])
36         ;;
37     esac
38   fi
39 done
40
41 dnl Configure header files
42 AC_CONFIG_HEADERS(include/llvm/Config/config.h)
43
44 dnl Configure other output file
45 AC_CONFIG_FILES(Makefile.config)
46 AC_CONFIG_HEADERS([include/llvm/Support/DataTypes.h])
47 AC_CONFIG_HEADERS([include/llvm/ADT/hash_map])
48 AC_CONFIG_HEADERS([include/llvm/ADT/hash_set])
49 AC_CONFIG_HEADERS([include/llvm/Support/ThreadSupport.h])
50 AC_CONFIG_HEADERS([include/llvm/ADT/iterator])
51
52 dnl Do special configuration of Makefiles
53 AC_CONFIG_MAKEFILE(Makefile)
54 AC_CONFIG_MAKEFILE(Makefile.common)
55 AC_CONFIG_MAKEFILE(examples/Makefile)
56 AC_CONFIG_MAKEFILE(lib/Makefile)
57 AC_CONFIG_MAKEFILE(runtime/Makefile)
58 AC_CONFIG_MAKEFILE(test/Makefile)
59 AC_CONFIG_MAKEFILE(test/Makefile.tests)
60 AC_CONFIG_MAKEFILE(test/QMTest/llvm.py)
61 AC_CONFIG_MAKEFILE(test/QMTest/llvmdb.py)
62 AC_CONFIG_MAKEFILE(tools/Makefile)
63 AC_CONFIG_MAKEFILE(utils/Makefile)
64 AC_CONFIG_MAKEFILE(projects/Makefile)
65
66 dnl Find the install program (needs to be done before canonical stuff)
67 AC_PROG_INSTALL
68
69 dnl Check which host for which we're compiling.  This will tell us which LLVM
70 dnl compiler will be used for compiling SSA into object code.
71 AC_CANONICAL_TARGET
72
73 dnl Set the "OS" Makefile variable based on the system we are building on.
74 dnl We will use the build machine information to set some variables.
75
76 AC_MSG_CHECKING([support for generic build operating system])
77 case $build in
78         *-*-aix*)
79              AC_SUBST(OS,[AIX])
80              platform_type="AIX"
81              ;;
82         *-*-cygwin*)
83              AC_SUBST(OS,[Cygwin])
84              platform_type="Cygwin"
85              ;;
86         *-*-darwin*)
87              AC_SUBST(OS,[Darwin])
88              platform_type="Darwin"
89              ;;
90         *-*-freebsd*)
91              AC_SUBST(OS,[Linux])
92              platform_type="FreeBSD"
93              ;;
94         *-*-interix*)
95              AC_SUBST(OS,[SunOS])
96              platform_type="Interix"
97              ;;
98         *-*-linux*)
99              AC_SUBST(OS,[Linux])
100              platform_type="Linux"
101              if test -d /home/vadve/lattner/local/x86/llvm-gcc
102              then
103                AC_SUBST(LLVMGCCDIR,[/home/vadve/lattner/local/x86/llvm-gcc/])
104              fi
105              ;;
106         *-*-solaris*)
107              AC_SUBST(OS,[SunOS])
108              platform_type="SunOS"
109              if test -d /home/vadve/lattner/local/sparc/llvm-gcc
110              then
111                AC_SUBST(LLVMGCCDIR,[/home/vadve/lattner/local/sparc/llvm-gcc/])
112              fi
113              ;;
114         *-*-win32*)
115              AC_SUBST(OS,[Win32])
116              platform_type="Win32"
117              ;;
118         *-*-mingw*)
119              AC_SUBST(OS,[Win32])
120              platform_type="Win32"
121              ;;
122         *)   
123              AC_SUBST(OS,[Unknown])
124              platform_type="Unknown"
125              ;;
126 esac
127
128 dnl Make sure we aren't attempting to configure for an unknown system
129 if test "$platform_type" = "Unknown" ; then
130   AC_MSG_ERROR([Platform is unknown, configure can't continue])
131 fi
132
133 dnl Make a link from lib/System/platform to lib/System/$platform_type
134 dnl This helps the #inclusion of the system specific include files
135 dnl for the operating system abstraction library
136 AC_CONFIG_LINKS(lib/System/platform:lib/System/$platform_type)
137
138
139 AC_MSG_CHECKING(target architecture)
140 dnl If we are targetting a Sparc machine running Solaris, pretend that it is
141 dnl V9, since that is all that we support at the moment, and autoconf will only
142 dnl tell us we're a sparc.
143 case $target in
144         sparc*-*-solaris*)  AC_SUBST(target,[[sparcv9-sun-solaris2.8]])
145                             ;;
146 esac
147
148 dnl Determine what our target architecture is and configure accordingly.
149 dnl This will allow Makefiles to make a distinction between the hardware and
150 dnl the OS.
151 case $target in
152         i*86-*)       
153           ARCH="x86"
154           AC_SUBST(ARCH,[x86])
155           ;;
156         sparc*-*)         
157           ARCH="Sparc"
158           AC_SUBST(ARCH,[Sparc])
159           ;;
160         powerpc*-*)       
161           ARCH="PowerPC"
162           AC_SUBST(ARCH,[PowerPC])
163           ;;
164         *)                
165           ARCH="Unknown"
166           AC_SUBST(ARCH,[Unknown])
167           ;;
168 esac
169
170 AC_MSG_RESULT($ARCH)
171
172 dnl Check for compilation tools
173 AC_PROG_CXX
174 AC_PROG_CC(gcc)
175 dnl Ensure that compilation tools are GCC; we use GCC specific extensions
176 if test "$GCC" != "yes"
177 then
178         AC_MSG_ERROR([gcc required but not found])
179 fi
180 AC_PROG_CPP
181 dnl Ensure that compilation tools are GCC; we use GCC specific extensions
182 if test "$GXX" != "yes"
183 then
184         AC_MSG_ERROR([g++ required but not found])
185 fi
186
187 dnl Verify that GCC is version 3.0 or higher
188 gccmajor=`$CC --version | head -n 1 | awk '{print $NF;}' | cut -d. -f1`
189 if test "$gccmajor" -lt "3"
190 then
191         AC_MSG_ERROR([gcc 3.x required, but you have a lower version])
192 fi
193
194 dnl Check for GNU Make.  We use its extensions too, so don't build without it
195 AC_CHECK_GNU_MAKE
196 if test -z "$_cv_gnu_make_command"
197 then
198         AC_MSG_ERROR([GNU Make required but not found])
199 fi
200
201 dnl Checks for other tools
202 AC_PROG_FLEX
203 AC_PROG_BISON
204 AC_PROG_LIBTOOL
205
206 dnl Checks for tools we can get away with not having:
207 AC_PATH_PROG(DOT,[dot],[true dot])
208 AC_PATH_PROG(ETAGS,[etags],[true etags])
209 dnl Check if we know how to tell etags we are using C++:
210 etags_version=`$ETAGS --version 2>&1`
211 case "$etags_version" in
212         *[Ee]xuberant*) ETAGSFLAGS="--language-force=c++" ;;
213         *GNU\ Emacs*) ETAGSFLAGS="-l c++" ;;
214         *) ETAGSFLAGS="" ;;
215 esac
216 AC_SUBST(ETAGSFLAGS,$ETAGSFLAGS)
217 AC_PATH_PROG(PYTHON,[python],[true python])
218 if test "$PYTHON" = "false"
219 then
220         AC_MSG_WARN([Python is required for the test suite, but it was not found])
221 fi
222 AC_PATH_PROG(QMTEST,[qmtest],[true qmtest])
223 if test "$QMTEST" = "false"
224 then
225         AC_MSG_WARN([QMTest is required for the test suite, but it was not found])
226 fi
227
228 dnl Verify that the version of python available is high enough for qmtest
229 pyversion=`$PYTHON -V 2>&1 | cut -d\  -f2`
230 pymajor=`echo $pyversion | cut -d. -f1`
231 pyminor=`echo $pyversion | cut -d. -f2`
232
233 if test "$pymajor" -ge "2"
234 then
235         if test "$pymajor" -eq "2"
236         then
237                 if test "$pyminor" -lt "2"
238                 then
239                         AC_MSG_WARN([QMTest requires Python 2.2 or later])
240                 fi
241         fi
242 else
243         AC_MSG_WARN([QMTest requires Python 2.2 or later])
244 fi
245
246 dnl Checks for libraries:
247 dnl libelf is for sparc only; we can ignore it if we don't have it
248 AC_CHECK_LIB(elf, elf_begin)
249
250 dnl Check for bzip2 and zlib compression libraries needed for archive reading/writing
251 AC_CHECK_LIB(bz2,BZ2_bzCompressInit,[bzip2_found=1],[bzip2_found=0])
252 AC_CHECK_LIB(z,gzopen,[zlib_found=1],[zlib_found=0])
253 AC_SUBST([HAVE_ZLIB],$zlib_found)
254 AC_SUBST([HAVE_BZIP2],$bzip2_found)
255 if test $zlib_found -eq 1 ; then
256   AC_DEFINE([HAVE_ZLIB],[1],[Define if zlib library is available on this platform.])
257 fi
258 if test $bzip2_found -eq 1 ; then
259   AC_DEFINE([HAVE_BZIP2],[1],[Define if bzip2 library is available on this platform.])
260 fi
261 dnl dlopen() is required for plugin support.
262 AC_SEARCH_LIBS(dlopen,dl,AC_DEFINE([HAVE_DLOPEN],[1],[Define if dlopen() is available on this platform.]),AC_MSG_WARN([dlopen() not found - disabling plugin support]))
263
264 dnl mallinfo is optional; the code can compile (minus features) without it
265 AC_SEARCH_LIBS(mallinfo,malloc,AC_DEFINE([HAVE_MALLINFO],[1],[Define if mallinfo() is available on this platform.]))
266
267 dnl pthread locking functions are optional - but llvm will not be thread-safe
268 dnl without locks.
269 AC_SEARCH_LIBS(pthread_mutex_lock,pthread,AC_DEFINE([HAVE_PTHREAD_MUTEX_LOCK],[1],[Have pthread_mutex_lock]))
270 dnl AC_SUBST(HAVE_PTHREAD_MUTEX_LOCK)
271
272 dnl Checks for header files.
273 dnl We don't check for ancient stuff or things that are guaranteed to be there
274 dnl by the C++ standard. We always use the <cfoo> versions of <foo.h> C headers.
275 AC_HEADER_STDC
276 AC_HEADER_SYS_WAIT
277
278 dnl Checks for POSIX and other various system-specific header files
279 AC_CHECK_HEADERS(fcntl.h limits.h sys/time.h unistd.h malloc.h sys/mman.h sys/resource.h dlfcn.h link.h execinfo.h windows.h)
280
281 dnl Check for things that need to be included in public headers, and so
282 dnl for which we may not have access to a HAVE_* preprocessor #define.
283 dnl (primarily used in DataTypes.h)
284 AC_CHECK_HEADER([sys/types.h])
285 AC_CHECK_HEADER([inttypes.h])
286 AC_CHECK_HEADER([stdint.h])
287
288 dnl Check for types
289 AC_TYPE_PID_T
290 AC_TYPE_SIZE_T
291 AC_CHECK_TYPES([int64_t],,AC_MSG_ERROR([Type int64_t required but not found]))
292 AC_CHECK_TYPES([uint64_t],,
293                AC_CHECK_TYPES([u_int64_t],,
294                               AC_MSG_ERROR([Type uint64_t or u_int64_t required but not found])))
295 AC_HEADER_TIME
296 AC_STRUCT_TM
297
298 dnl Check for various C features
299 AC_C_PRINTF_A
300
301 dnl Check for the endianness of the target
302 AC_C_BIGENDIAN(AC_SUBST([ENDIAN],[big]),AC_SUBST([ENDIAN],[little]))
303
304 dnl Check for C++ extensions
305 AC_CXX_HAVE_HASH_MAP
306 AC_CXX_HAVE_HASH_SET
307 AC_CXX_HAVE_STD_ITERATOR
308 AC_CXX_HAVE_BI_ITERATOR
309 AC_CXX_HAVE_FWD_ITERATOR
310
311 AC_FUNC_ISNAN
312 AC_FUNC_ISINF
313
314 dnl Checks for library functions.
315 AC_FUNC_ALLOCA
316 AC_FUNC_MMAP
317 if test "$ac_cv_func_mmap_fixed_mapped" = "no"
318 then
319         AC_MSG_WARN([mmap() required but not found])
320 fi
321 AC_FUNC_MMAP_FILE
322 if test "$ac_cv_func_mmap_file" = "no"
323 then
324         AC_MSG_WARN([mmap() of files required but not found])
325 fi
326 AC_HEADER_MMAP_ANONYMOUS
327 AC_TYPE_SIGNAL
328 AC_CHECK_FUNCS(getcwd gettimeofday strdup strtoq strtoll backtrace isatty mkstemp getrusage)
329 AC_CHECK_FUNC(mprotect,,AC_MSG_ERROR([Function mprotect() required but not found]))
330
331 dnl Determine if the linker supports the -R option.
332 AC_LINK_USE_R
333
334 dnl --enable/--with command-line options:
335 dnl Check whether they want to do an optimized build:
336 AC_ARG_ENABLE(optimized,AS_HELP_STRING(--enable-optimized,Compile with optimizations enabled (default is NO)),,enableval=no)
337 if test ${enableval} = "no"
338 then
339         AC_SUBST(ENABLE_OPTIMIZED,[[]])
340 else
341         AC_SUBST(ENABLE_OPTIMIZED,[[ENABLE_OPTIMIZED=1]])
342 fi
343
344 dnl JIT Option
345 AC_ARG_ENABLE(jit,AS_HELP_STRING(--enable-jit,Enable Just In Time Compiling (default is YES)),,enableval=default)
346 if test ${enableval} = "no"
347 then
348         AC_SUBST(JIT,[[]])
349 else
350         case $target in
351                 *i*86*)
352                         AC_SUBST(JIT,[[TARGET_HAS_JIT=1]])
353                         ;;
354                 *sparc*)
355                         AC_SUBST(JIT,[[TARGET_HAS_JIT=1]])
356                         ;;
357                 *)
358                         AC_SUBST(JIT,[[]])
359                         ;;
360         esac
361 fi
362
363 dnl Find the LLVM GCC-based C/C++ front end
364 AC_ARG_WITH(llvmgccdir,AS_HELP_STRING(--with-llvmgccdir,Location of LLVM GCC front-end),AC_SUBST(LLVMGCCDIR,[$withval]))
365 AC_MSG_CHECKING([for llvm-gcc])
366 LLVM_GCC_CHECK=no
367 if test -d "$LLVMGCCDIR"
368 then
369         if test -x "$LLVMGCCDIR/bin/gcc"
370         then
371                 LLVM_GCC_CHECK="$LLVMGCCDIR/bin/gcc"
372         fi
373 fi
374 llvmgccwarn=no
375 AC_MSG_RESULT($LLVM_GCC_CHECK)
376 if test "$LLVM_GCC_CHECK" = "no"
377 then
378     llvmgccwarn=yes
379 fi
380 AC_MSG_CHECKING([whether llvm-gcc is sane])
381 LLVM_GCC_SANE=no
382 if test -x "$LLVM_GCC_CHECK"
383 then
384         cp /dev/null conftest.c
385     "$LLVM_GCC_CHECK" -S -o - conftest.c | grep implementation > /dev/null 2>&1
386         if test $? -eq 0
387         then
388                 LLVM_GCC_SANE=yes
389         fi
390         rm conftest.c
391         llvmcc1path=`"$LLVM_GCC_CHECK" --print-prog-name=cc1`
392         AC_SUBST(LLVMCC1,$llvmcc1path)
393         llvmcc1pluspath=`"$LLVM_GCC_CHECK" --print-prog-name=cc1plus`
394         AC_SUBST(LLVMCC1PLUS,$llvmcc1pluspath)
395 fi
396 AC_MSG_RESULT($LLVM_GCC_SANE)
397 if test "$LLVM_GCC_SANE" = "no"
398 then
399         llvmgccwarn=yes
400 fi
401
402 dnl Get libtool's idea of what the shared library suffix is.
403 dnl (This is a hack; it relies on undocumented behavior.)
404 AC_MSG_CHECKING([for shared library suffix])
405 eval "SHLIBEXT=$shrext_cmds"
406 AC_MSG_RESULT($SHLIBEXT)
407 dnl Propagate it to the Makefiles and config.h (for gccld & bugpoint).
408 AC_SUBST(SHLIBEXT,$SHLIBEXT)
409 AC_DEFINE_UNQUOTED(SHLIBEXT,"$SHLIBEXT",
410                    [Extension that shared libraries have, e.g., ".so".])
411
412 # Translate the various configuration directories and other basic
413 # information into substitutions that will end up in config.h.in so
414 # that these configured values can be hard-wired into a program.
415 eval LLVM_PREFIX="${prefix}";
416 eval LLVM_BINDIR="${prefix}/bin";
417 eval LLVM_LIBDIR="${prefix}/lib";
418 eval LLVM_DATADIR="${prefix}/data";
419 eval LLVM_DOCSDIR="${prefix}/docs";
420 eval LLVM_ETCDIR="${prefix}/etc";
421 eval LLVM_INCLUDEDIR="${prefix}/include";
422 eval LLVM_INFODIR="${prefix}/info";
423 eval LLVM_MANDIR="${prefix}/man";
424 LLVM_CONFIGTIME=`date`
425 AC_SUBST(LLVM_PREFIX)
426 AC_SUBST(LLVM_BINDIR)
427 AC_SUBST(LLVM_LIBDIR)
428 AC_SUBST(LLVM_DATADIR)
429 AC_SUBST(LLVM_DOCSDIR)
430 AC_SUBST(LLVM_ETCDIR)
431 AC_SUBST(LLVM_INCLUDEDIR)
432 AC_SUBST(LLVM_INFODIR)
433 AC_SUBST(LLVM_MANDIR)
434 AC_SUBST(LLVM_CONFIGTIME)
435 AC_DEFINE_UNQUOTED(LLVM_PREFIX,"$LLVM_PREFIX", [Installation prefix directory])
436 AC_DEFINE_UNQUOTED(LLVM_BINDIR, "$LLVM_BINDIR", [Installation directory for binary executables])
437 AC_DEFINE_UNQUOTED(LLVM_LIBDIR, "$LLVM_LIBDIR", [Installation directory for libraries])
438 AC_DEFINE_UNQUOTED(LLVM_DATADIR, "$LLVM_DATADIR", [Installation directory for data files])
439 AC_DEFINE_UNQUOTED(LLVM_DATADIR, "$LLVM_DOCSDIR", [Installation directory for documentation])
440 AC_DEFINE_UNQUOTED(LLVM_ETCDIR, "$LLVM_ETCDIR", [Installation directory for config files])
441 AC_DEFINE_UNQUOTED(LLVM_INCLUDEDIR, "$LLVM_INCLUDEDIR", [Installation directory for include files])
442 AC_DEFINE_UNQUOTED(LLVM_INFODIR, "$LLVM_INFODIR", [Installation directory for .info files])
443 AC_DEFINE_UNQUOTED(LLVM_MANDIR, "$LLVM_MANDIR", [Installation directory for man pages])
444 AC_DEFINE_UNQUOTED(LLVM_CONFIGTIME, "$LLVM_CONFIGTIME", [Time at which LLVM was configured])
445
446 dnl Create the output files
447 AC_OUTPUT
448
449 dnl Warn if we don't have a compression library
450 if test $bzip2_found -ne 1 ; then
451   if test $zlib_found -ne 1 ; then
452     AC_MSG_WARN([*** Neither zlib nor bzip2 compression libraries were found.])
453     AC_MSG_WARN([*** Bytecode archives will not support compression!])
454     AC_MSG_WARN([*** To correct, install the libraries and and re-run configure.])
455   fi
456 fi
457
458 dnl Warn loudly if llvm-gcc was not obviously working
459 if test $llvmgccwarn = yes
460 then
461         AC_MSG_WARN([***** llvm C/C++ front end was not found, or does not])
462         AC_MSG_WARN([***** appear to be working.])
463         AC_MSG_WARN([***** ])
464         AC_MSG_WARN([***** Please check configure's --with-llvmgccdir option.])
465         AC_MSG_WARN([***** Runtime libraries (in llvm/runtime) will not be built,])
466         AC_MSG_WARN([***** but you should be able to build the llvm tools.])
467 fi
468