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