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