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