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