diff options
Diffstat (limited to 'cil/configure.in')
-rw-r--r-- | cil/configure.in | 600 |
1 files changed, 600 insertions, 0 deletions
diff --git a/cil/configure.in b/cil/configure.in new file mode 100644 index 00000000..aee7ac73 --- /dev/null +++ b/cil/configure.in @@ -0,0 +1,600 @@ +# configure.in for CIL -*- sh -*- +# Process this file with autoconf to produce a configure script. + +# Autoconf runs this through the M4 macroprocessor first; lines +# starting with "dnl" are comments to M4. The result is a bash +# script; any text which isn't an M4/autoconf directive gets +# copied verbatim to that script. + +# also, in general, watch out: the M4 quoting charactes are +# the square brackets: [ and ]. if you want to pass brackets +# to something, you can quote the brackets with more brackets. +# I don't know how to pass a single (unbalanced) bracket .. + +# sm: changed this file to use '#' for comments, since that's +# just as good (since this becomes an 'sh' script) + + +# We must put these AC_SUBST very early, and in this order. See below where we +# define NEWLINE +AC_SUBST(CIL_FEATURES_DEFINES) +AC_SUBST(NEWLINE) + + +# -------------- usual initial stuff ------------- +# this simply names a file somewhere in the source tree to verify +# we're in the right directory +AC_INIT(src/cil.mli) +AC_CONFIG_HEADERS(config.h) + +# sm: require a late-enough autoconf; this is the version number +# that's on manju, so I assume it's ok +AC_PREREQ(2.50) + +# +# Assign here the CIL version numbers +CIL_VERSION_MAJOR=1 +CIL_VERSION_MINOR=3 +CIL_VERSION_REV=5 +CIL_VERSION=$CIL_VERSION_MAJOR.$CIL_VERSION_MINOR.$CIL_VERSION_REV + + +# make sure I haven't forgotten to run autoconf +if test configure -ot configure.in; then + AC_MSG_ERROR(configure is older than configure.in; you forgot to run autoconf) +fi + +# check for C compiler; this typically finds gcc; it sets the +# variable CC to whatever it finds, which then gets substituted +# for @CC@ in output files; you have to do this even if you don't +# care about @CC@, because system feature tests later on in +# the ./configure script will expect $CC to be set right +AC_PROG_CC + +AC_PROG_INSTALL + + +# find system type (using this macro means we must include +# the files install-sh, config.sub, and config.guess (all from +# the autoconf distribution) in our source tree!) +AC_CANONICAL_SYSTEM + + +# ---------------- generic functions ----------------- +# debugging diagnostic; set to 'echo' to debug or 'true' for production +# (technically you're not supposed to use shell functions in +# configure scripts, because some-obscure-sh somewhere doesn't +# support them.. but they're too convenient to not use) +diagnostic() { + #echo "$@" + true "$@" +} + +# determine if a binary is in the path +binaryExists() { + # on cygwin, 'which' always returns success, so use 'type' instead + if type "$1" >/dev/null 2>&1; then + return 0 + else + return 1 + fi +} + + +# -------------- portable configuration ---------------- +# this specifies the root of the source tree; it's just the +# directory where ./configure runs, except on cygwin, which +# overrides this below +CILHOME=`pwd` + +DEFAULT_COMPILER=_GNUCC +DEFAULT_CIL_MODE=GNUCC + +# is the microsoft compiler available? +# hmm.. I think we should check the version or something, because +# sometimes people have Common Lisp's interpreter called 'cl' .. +AC_MSG_CHECKING(for msvc cl.exe (optional)) +# See if CC points to the MS compiler +if "$CC" 2>&1 | grep "Microsoft" >/dev/null; then + AC_MSG_RESULT([found, set as default]) + HAS_MSVC=yes + DEFAULT_COMPILER=_MSVC + DEFAULT_CIL_MODE=MSVC +else + if cl 2>&1 | grep "Microsoft" >/dev/null ;then + AC_MSG_RESULT(found) + HAS_MSVC=yes + else + AC_MSG_RESULT(not found) + HAS_MSVC=no + fi +fi + +# is ocaml available? +# needed binaries: ocamllex ocamlyacc ocamldep ocamlopt ocamlc +ocamlDownloadInstructions=" + OCaml can be downloaded from http://caml.inria.fr/ocaml/. + After downloading and unpacking the source distribution, in the ocaml + directory, do + ./configure + make world + make opt + make install + Then come back here and re-run ./configure." + +# required major/minor. +# required major/minor +reqMaj=3 +reqMin=08 +knownMaj=3 +knownMin=09 +AC_MSG_CHECKING(ocaml version is at least $reqMaj.$reqMin) +if binaryExists ocamlc; then + # what version? + ver=`ocamlc -v | grep version | sed 's/^.*version //'` + diagnostic "ver is $ver" + # major: anything before the . + major=`echo $ver | sed 's/\..*$//'` + diagnostic "major is $major" + # minor: numbers after the . + # (the outer level of bracket-quotation protects the inner brackets) + [minor=`echo $ver | sed 's/^[^.]*\.\([0-9][0-9]*\).*$/\1/'`] + diagnostic "minor is $minor" + + # I would think autoconf would already have a facility for doing + # these kinds of major/minor version checks, but I can't find it + if test $major -gt $reqMaj -o $major -ge $reqMaj -a $minor -ge $reqMin; then + AC_MSG_RESULT([version is $ver, ok]) + + # sm: added this test when we found that CCured needed to be changed + # a little when 3.06 came out (it had previously worked with 3.04) + if test "$major" -gt $knownMaj -o "$major" -ge $knownMaj -a "$minor" -gt $knownMin; then + AC_MSG_WARN([Your ocaml version is $ver, but the latest version this program + is known to work with is $knownMaj.$knownMin. If you have + trouble compiling, please try using an earlier version + or see if there is a later version of this program.]) + fi + else + AC_MSG_ERROR([ + I found OCaml version $ver; this program requires at least $reqMaj.$reqMin. + Please download a newer OCaml distribution. + $ocamlDownloadInstructions + ]) + fi + + # check for existence of other binaries + AC_MSG_CHECKING(existence of related ocaml tools) + if binaryExists ocamllex && \ + binaryExists ocamlyacc && \ + binaryExists ocamldep && \ + binaryExists ocamlopt; then + AC_MSG_RESULT(ok) + else + AC_MSG_ERROR([ + At least one of ocamllex, ocamlyacc, ocamldep or ocamlopt is missing. + In particular, ocamlopt requires you to "make opt" when building + OCaml from source. Please make sure all these tools are built and + in the path. + ]) + fi +else + AC_MSG_ERROR([ + The "ocamlc" OCaml compiler was not found in the path: $PATH. + + Most of this program is written in the OCaml language, so its compiler + is required. + $ocamlDownloadInstructions + ]) +fi + +# +# ------------------- Perl ---------------- +# +AC_MSG_CHECKING([for Perl]) + if ! binaryExists perl; then + AC_MSG_ERROR([ + perl not found. + You need perl version 5.6.1 or later for CIL. + You can get perl at http://www.cpan.org/src/index.html . + ]) + fi + + # sm: oh how nice it would be to just say "use English; + # print($PERL_VERSION)", but that appears broken on 5.6.1.. so I'm + # trying to say "caret right-bracket", but then that would run afoul + # of autoconf's quoting characters, so I use the "quadrigraph" @:>@ + # to stand for right-bracket. what a mess. + perlver=`perl -e 'print($@:>@);'` + if perl -e "exit( $perlver >= 5.006001 );"; then + AC_MSG_ERROR([ + Found perl version $perlver, but at least 5.6.1 is required. + You can get a newer perl at http://www.cpan.org/src/index.html . + ]) + fi + + perlport=`perl -e "print $^O;"` + case "$perlport" in + cygwin) + ;; + MSWin32) # ActivePerl + ;; + linux) + ;; + freebsd) + ;; + openbsd) + ;; + darwin) # Mac OS X + ;; + solaris) + ;; + *) + AC_MSG_ERROR([ + Unsupported Perl port $perlport -- sorry. + cygwin, MSWin32 (ActivePerl), linux, freebsd, openbsd, darwin, + and solaris are the supported ports. + ]) + esac +AC_MSG_RESULT([found version $perlver, port $perlport]) + + # The cygwin port has some bugs in the File::Spec module +if test "$perlport" = "cygwin" ;then + AC_MSG_CHECKING([for known cygwin Perl bug in File::Spec]) + perlfixres=[`perl -e ' + use File::Spec; + if(File::Spec->file_name_is_absolute("C:/test")) { + print "no bug found"; exit 0; + } else { + print "bug"; + foreach $d (@INC) { + if(-f "$d/File/Spec/Unix.pm") { + open(IN, "<$d/File/Spec/Unix.pm"); + open(OUT, ">$d/File/Spec/Unix.pm.fixed") + || die "Cannot open $d/File/Spec/Unix.pm.fixed"; + while(<IN>) { + if($_ =~ m|sub file_name_is_absolute|) { + print OUT $_; + print OUT scalar(<IN>); + print OUT <<EOF; + if(\\$^O eq \"cygwin\") { + return scalar(\\$file =~ m{^(\\[a-z\\]:)?\\[\\\\\\\\/\\]}is); +}; +EOF + next; + } + print OUT $_; + } + close(OUT); + close(IN); + system("mv -f $d/File/Spec/Unix.pm.fixed $d/File/Spec/Unix.pm"); + } + } + } + '`] + # See if it was indeed fixed + if test "$perlfixres" = "bug" ;then + perlfixres=`perl -e ' + use File::Spec; + if(File::Spec->file_name_is_absolute("C:/test")) { + print "bug fixed"; exit 0; + } else { + print "cannot fix bug"; exit 1; + }'` + fi + if test "x$perlfixres" = "x" ;then + AC_MSG_ERROR([ + Cannot run perl + ]) + elif test "$perlfixres" = "cannot fix bug" ;then + AC_MSG_ERROR([ + Found a bug but cannot fix it. + ]) + else + AC_MSG_RESULT([$perlfixres]) + fi +fi + +# +# Now setup the performance counters +# +AC_MSG_CHECKING(if performance counters are usable) +# Create a C file from src/perfcount.c.in +rm -f ./cycles.exe +if gcc -DCONFIGURATION_ONLY \ + -x c ocamlutil/perfcount.c.in -lm -o ./cycles.exe >/dev/null 2>&1; then + + if CYCLES_PER_USEC=`./cycles.exe 2>&1` ;then + AC_MSG_RESULT([ok ($CYCLES_PER_USEC cycles per us)]) + else + # Print what we got + AC_MSG_RESULT([no ($CYCLES_PER_USEC)]) + CYCLES_PER_USEC=0 + fi +else + CYCLES_PER_USEC=0 + AC_MSG_RESULT([no (cannot compile perfcount.c)]) +fi +rm -f ./cycles.exe + +# If we are on Linux and we use performance counters try to get +# the processor speed from /proc/cpuinfo +if test "$CYCLES_PER_USEC" != "0" ;then + case "$target" in + # linux + *86*linux*) + AC_MSG_CHECKING(if /proc/cpuinfo has processor speed) + cpuinfo=`cat /proc/cpuinfo 2>/dev/null | grep "cpu MHz"` + [procspeed=`echo $cpuinfo | sed 's/^.*[^0-9]\([0-9]\+\.[0-9]\+\).*$/\1/g'`] + if test "$procspeed"!="" ;then + CYCLES_PER_USEC=$procspeed + AC_MSG_RESULT([got $CYCLES_PER_USEC cycles per us]) + else + AC_MSG_RESULT(no) + fi + ;; + *) + ;; + esac + # Now set HAS_PERFCOUNT + HAS_PERFCOUNT=1 +else + HAS_PERFCOUNT=0 +fi + +# additional tools we might check for: +# - gnu make + +# +# -------------------- GCC -------------- +# + +AC_MSG_CHECKING([for gcc version]) +AC_CHECK_TYPE(__builtin_va_list, + HAVE_BUILTIN_VA_LIST=true, + HAVE_BUILTIN_VA_LIST=false) +AC_MSG_CHECKING([if __thread is a keyword]) +AC_COMPILE_IFELSE([int main(int __thread) { return 0; }], + THREAD_IS_KEYWORD=false, + THREAD_IS_KEYWORD=true) +AC_MSG_RESULT($THREAD_IS_KEYWORD) + +# Does gcc add underscores to identifiers to make assembly labels? +# (I think MSVC always does) +AC_MSG_CHECKING([if gcc adds underscores to assembly labels.]) +AC_LINK_IFELSE([int main() { __asm__("jmp _main"); }], + UNDERSCORE_NAME=true, + UNDERSCORE_NAME=false) +AC_MSG_RESULT($UNDERSCORE_NAME) + + +# ----------- some stuff 'autoscan' put here -------------- +# (autoscan is part of the autoconf distribution) + +# checks for header files +AC_HEADER_STDC +AC_CHECK_HEADERS(stdlib.h strings.h sys/time.h unistd.h wchar.h) + +# checks for typedefs, structures, and compiler characteristics +AC_C_CONST +AC_C_INLINE +AC_HEADER_TIME + +# checks for library functions; more autoscan stuff +AC_FUNC_MEMCMP +AC_CHECK_FUNCS(mkdir select socket __sysv_signal) + + + +# ----------- platform-specific code ------------- +# $target is typically processor-vendor-os +case "$target" in + # linux + *86*linux*|*86*freebsd*|*86*openbsd*|*86*darwin*) + AC_MSG_RESULT(configuring for linux/x86) + + ARCHOS=x86_LINUX + ;; + + # Mac OS X + *powerpc*darwin*) + AC_MSG_RESULT(configuring for powerpc/darwin, which we treat like linux/x86) + + ARCHOS=ppc_DARWIN + ;; + + # cygwin + *86*cygwin*) + AC_MSG_RESULT(configuring for Cygwin on win32/x86) + + ARCHOS=x86_WIN32 + + # override CILHOME; even on cygwin we want forward slashes + # sm: I folded this into what I hope will be the only + # case-analysis of machine type + CILHOME=`cygpath -wa "$CILHOME" | sed -e "s/\\\\\/\\//g"` + CC=`which $CC` + CC=`cygpath -wa "$CC" | sed -e "s/\\\\\/\\//g"` + ;; + + # Solaris + *sparc*solaris*) + AC_MSG_RESULT(configuring for SPARC/Solaris) + + ARCHOS=sparc_SOLARIS + ;; + + *) + AC_MSG_ERROR([ + Unsupported platform $target -- sorry. + ./configure supports these platforms: + on x86: Linux, Win32(with Cygwin), freeBSD, openBSD, and Mac OS X + on PowerPC: Mac OS X + on SPARC: Solaris + ]) + ;; +esac + +# Make the object directory if not already present +AC_CHECK_FILE(obj/$ARCHOS,, AC_MSG_RESULT(creating obj/$ARCHOS); + mkdir -p obj/$ARCHOS) + +AC_MSG_CHECKING([delete the obj/$ARCHOS/feature_config.ml and obj/$ARCHOS/machdep.ml file]) +rm -f obj/$ARCHOS/machdep.ml +rm -f obj/.depend/machdep.d +rm -f obj/$ARCHOS/feature_config.ml +rm -f obj/.depend/feature_config.d +AC_MSG_RESULT([done]) + +# We will use substitution variables whose definition contains newlines. The +# problem is that when config.status runs, it wants to break the series of +# substitution commands for sed into fragments based on line count. We could +# be unlucky and have config.status break the series of substitution in the +# middle of a variable that contains newlines. So, we first create a single +# variable called NEWLINE whose definition is a carriage return. This means +# that there will be exactly one opportunity for this error to happen (in the +# definition of NEWLINE). The occurrence of AC_SUBST for NEWLINE must occur +# after those of the variables that use it! And we want to put all of these +# very early on, to make sure that they are not around the place when the file +# bets broken. + +NEWLINE="\\ +" + + +# +# CIL/CCured features +# +# + +# Set the defaults + + +# Give a space-separated list of features with the defaults +features="blockinggraph=no rand=no arithabs=no zrapp=no" + +AC_ARG_WITH(blockinggraph, + AC_HELP_STRING([--with-blockinggraph], + [enable the blocking graph feature])) +AC_ARG_WITH(rand, + AC_HELP_STRING([--with-rand], + [enable the randomized value numbering])) +AC_ARG_WITH(arithabs, + AC_HELP_STRING([--with-arithabs], + [enable the arithmetic abstraction])) +AC_ARG_WITH(zrapp, + AC_HELP_STRING([--with-zrapp], + [enable the zrapp pretty-printer])) + +# Smalloc.ml is distributed by {matth,nks}@cs.berkeley.edu as part of Scrash. +features="$features smalloc=no" + +# cqualann.ml is used by Matt Harren. Please ignore. +features="$features cqualann=no" + +# Now add any features specified in the command-line + +features="$features $EXTRAFEATURES" + +for f_val in $features +do + # If there is no =, then we default to yes + if ! (echo $f_val | grep "=" >/dev/null) ;then f_val="$f_val=yes"; fi + # echo "Testing feature $f_val" + f=`echo $f_val | sed -e s%=.*$%%` + AC_MSG_CHECKING(whether to use CIL feature $f) + # default value from "features" + defval=`echo $f_val | sed -e s%^.*=%%` + # current value + getcurval="echo \${with_$f:=$defval}" + curval=`eval $getcurval` + AC_MSG_RESULT($curval) + if test $curval = yes ;then + CIL_FEATURES="$CIL_FEATURES $f" + fi +done + +## Now produce the CIL_FEATURES_DEFINES +CIL_FEATURES_DEFINES="" +# Convert to upper case +for f in `echo $CIL_FEATURES | tr a-z A-Z` +do + CIL_FEATURES_DEFINES="${CIL_FEATURES_DEFINES}@NEWLINE@export USE_$f=yes" +done + + +# ----------------- finish up ------------------- +# names of the variables that get substituted in files; for example, +# write @ARCHOS@ somewhere in a written file to get it substituted +AC_SUBST(ARCHOS) +AC_SUBST(CILHOME) +AC_SUBST(HAS_MSVC) +AC_SUBST(DEFAULT_COMPILER) +AC_SUBST(DEFAULT_CIL_MODE) +AC_SUBST(CIL_VERSION_MAJOR) +AC_SUBST(CIL_VERSION_MINOR) +AC_SUBST(CIL_VERSION_REV) +AC_SUBST(CIL_VERSION) +AC_SUBST(CYCLES_PER_USEC) +AC_SUBST(HAS_PERFCOUNT) +AC_SUBST(HAVE_BUILTIN_VA_LIST) +AC_SUBST(THREAD_IS_KEYWORD) +AC_SUBST(UNDERSCORE_NAME) +AC_SUBST(EXTRAFEATURES) +AC_SUBST(EXTRASRCDIRS) + +# finish the configure script and generate various files; ./configure +# will apply variable substitutions to <filename>.in to generate <filename>; +# I find it useful to mark generated files as read-only so I don't +# accidentally edit them (and them lose my changes when ./configure +# runs again); I had originally done the chmod after AC_OUTPUT, but +# the problem is then the chmod doesn't run inside ./config.status + +# MY_AC_CONFIG_FILES(filename) +# do AC_CONFIG_FILES(filename, chmod a-w filename) +define([MY_AC_CONFIG_FILES], +[{ + if test -f [$1].in; then + AC_CONFIG_FILES([$1], chmod a-w [$1]) + else + true + #echo "skipping [$1] because it's not in this distribution" + fi +}]) +define([MY_AC_CONFIG_EXE_FILES], +[{ + if test -f [$1].in; then + AC_CONFIG_FILES([$1], [chmod a-w,a+x $1]) + else + true + #echo "skipping [$1] because it's not in this distribution" + fi +}]) + +MY_AC_CONFIG_FILES(Makefile) +MY_AC_CONFIG_FILES(cil.spec) +MY_AC_CONFIG_FILES(config.mk) +MY_AC_CONFIG_FILES(test/Makefile) +MY_AC_CONFIG_EXE_FILES(bin/cilly.bat) +MY_AC_CONFIG_EXE_FILES(bin/patcher.bat) +MY_AC_CONFIG_FILES(bin/CilConfig.pm) +MY_AC_CONFIG_FILES(doc/index.html) +MY_AC_CONFIG_FILES(doc/header.html) +MY_AC_CONFIG_FILES(ocamlutil/perfcount.c) + +AC_OUTPUT() + +# show the user what the variables have been set to +cat <<EOF + +CIL configuration: + architecture/OS: ARCHOS $ARCHOS + source tree root: CILHOME $CILHOME + (optional) cl.exe found: HAS_MSVC $HAS_MSVC + gcc to use CC $CC + default compiler DEFAULT_COMPILER $DEFAULT_COMPILER + CIL version CIL_VERSION $CIL_VERSION + CIL features CIL_FEATURES $CIL_FEATURES + Extra source directories EXTRASRCDIRS $EXTRASRCDIRS + Cycles per microsecond CYCLES_PER_USEC $CYCLES_PER_USEC +EOF + |