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