C+probe revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes:
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg### this script contains archaic constructs that work with all sh variants ###
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes# Glenn Fowler
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes# AT&T Research
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes#
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes# @(#)C probe (AT&T Research) 2012-02-29
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes#
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes# probe [ -d ] c-compiler-path [ attributes ]
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes#
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes# common C probe preamble for the tool specific probes
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg#
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes# NOTE: some cc -E's do syntax analysis!
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes#
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes# probe_* are first eval'd and then attempted from left to right
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes#
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_binding="-dy -dn -Bdynamic -Bstatic '-Wl,-ashared -Wl,+s' -Wl,-aarchive -call_shared -non_shared -dynamic -static -bshared -bstatic '' -static"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_env="CC_OPTIONS CCOPTS LD_OPTIONS LDOPTS LIBPATH LPATH"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_include="stdio.h iostream.h complex.h ctype.h plot.h stdarg.h varargs.h ranlib.h hash.h sys/types.h stab.h cmath cstdio iostream string"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_longlong="long 'long long'"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_longlong_t="__int64_t _int64_t __int64 _int64 int64"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_l="l yyreject m sin mopt sin"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_lxx="C exit ++ exit g++ exit"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_ppprefix="a n"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_size="size"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_src="cxx C cc c"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_sa=".sa"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_sd=".dll .lib .dll .x"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_sdb=".pdb"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_so=".dylib .so .sl"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_symprefix="_"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_verbose="'-v -v' '-# -#' '-d -d' -dryrun '-V -V'"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprobe_version="--version -V -version -v"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes#
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes# the following are set by the preamble for the tool specific probe
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes#
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholescc=cc
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesdebug=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesdir=.
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesdll=.dll
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesdynamic=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesexe=exe
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesexecutable="test -x"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholeshosted=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesifs=${IFS-'
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes '}
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesobj=o
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesppenv=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesppopt=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholespredef=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesprepred=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholessa=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholessd=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholessdb=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesso=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholessov=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesstatic=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesstdlib=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesstdpp=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholessuffix_command=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesif test "" != "$TMPDIR" -a -d "$TMPDIR"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesthen tmpdir=$TMPDIR
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholeselse tmpdir=/tmp
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesfi
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholestmpdir=$tmpdir/probe$$
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesundef="define defined elif else endif error if ifdef ifndef include line pragma undef __STDC__ __STDPP__ __ARGC__ __BASE__ __BASE_FILE__ __DATE__ __FILE__ __FUNCTION__ __INCLUDE_LEVEL__ __LINE__ __PATH__ __TIME__ __TIMESTAMP__ __VERSION__"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesversion_flags=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesversion_stamp=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesversion_string=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes#
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes# constrain the environment
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes#
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesDISPLAY=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesLC_ALL=C
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesexport DISPLAY LC_ALL
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes#
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes# now the common probes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes#
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholeswhile :
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesdo case $1 in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes -d) debug=1 ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes -*) set ''; break ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes *) break ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes esac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes shift
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesdone
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholescc=$1
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholescase $cc in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes[\\/]*|[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]:\\*)
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes*) echo "Usage: $0 [ -d ] c-compiler-path [ attributes ]" >&2
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes exit 1
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesesac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesATTRIBUTES=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholeseval $2
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes_probe_PATH=$PATH
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesPATH=/usr/bin:/bin:$PATH
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholescase $0 in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes*[\\/]*) dir=`echo $0 | sed -e 's,[\\/][\\/]*[^\\/]*\$,,'` ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesesac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes$executable . 2>/dev/null || executable='test -r'
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholescase $SHELL in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes[\\/]*|[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]:\\*)
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes sh=$SHELL
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes*) sh=/bin/sh
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesesac
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholestrap 'code=$?; cd ..; rm -rf $tmpdir; exit $code' 0 1 2 3
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesmkdir $tmpdir
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholescd $tmpdir
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesexec 3>&1 4>&2 </dev/null
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholescase $debug in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes"") exec >/dev/null 2>&1
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0
0b2a6b63977ab27352a0b525bdad1e1982a1c0b1bnicholes ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes*) PS4='+$LINENO+ '
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes set -x
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesesac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgif (xxx=xxx; unset xxx)
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesthen UNSET=1
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholeselse UNSET=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesfi
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholeseval set x $probe_env
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholeswhile :
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgdo shift
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes case $# in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes 0) break ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes esac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes eval x='$'$1
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes case $x in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes '') continue ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes esac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes case $1 in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes *PATH) _probe_export="$_probe_export $1='$x'" ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes esac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes case $UNSET in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes '') eval $1=
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes export $1
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes *) unset $1
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes esac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesdone
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesif test -f "$dir/probe.ini"
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgthen . "$dir/probe.ini"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes IFS=$ifs
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgfi
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesmkdir suffix
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholescd suffix
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgfor src in $probe_src
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesdo echo "int main(){return 0;}" > ../test.$src
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes rm -f test*
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes if $cc -c ../test.$src
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes then set test.*
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes if test -f "$1"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes then o="$*"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes mv $* ..
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes for i in $o
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes do if $cc -o test.exe ../$i
0b2a6b63977ab27352a0b525bdad1e1982a1c0b1bnicholes then obj=`echo "$i" | sed -e 's,test.,,'`
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes $executable test.exe || executable="test -r"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes set test*
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes rm *
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes if $cc -o test ../$i
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes then rm $*
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes set test.*
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes if $executable "$1"
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes then exe=`echo "$1" | sed -e 's,test.,,'`
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes suffix_command=.$exe
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes fi
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes fi
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes break 2
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes fi
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes done
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes fi
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes fi
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesdone
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholescd ..
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholescase $src in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesc) ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes*) echo '// (
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesint
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesmain()
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes{
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes class { public: int i; } j;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes j.i = 0;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes int k = j.i + 1;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes return k;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes}' > dialect.$src
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes if $cc -c dialect.$src && $cc -o dialect.$exe dialect.$obj && $executable dialect.$exe
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes then mv dialect.$src dialect.c
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes rm -f dialect.$obj dialect.$exe
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes if $cc -c dialect.c && $cc -o dialect.$exe dialect.$obj && $executable dialect.$exe
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes then src=c
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes else set x $cc
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes while :
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes do shift
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg case $# in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes 0) break ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes esac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes case $1 in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes *=*) continue ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes esac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes case `echo $1 | sed -e 's,.*/,,'` in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes *CC*|*++*|*[xX][xX]*|*[pP][lL][uU][sS]*) ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes *) src=c ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes esac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes break
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes done
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes fi
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes else src=c
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes fi
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesesac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesset x x '(' 1 'int x;' 0
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholeswhile :
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesdo shift
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes shift
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg case $# in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes [01]) break ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes esac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes rm -f test.$obj
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg echo "$1" > test.$src
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes $cc -c test.$src
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg r=$?
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg case $r in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes 0) test -f test.$obj || r=1 ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes *) r=1 ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes esac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes case $2:$r in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes 0:0) ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes 0:1) echo "$cc: not a C compiler: failed to compile \`\`$1''" >&4
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg exit 1
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes 1:0) echo "$cc: not a C compiler: successfully compiled \`\`$1''" >&4
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes exit 1
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes esac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesdone
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholeshosttype=`package CC="$cc" || $SHELL -c "package CC='$cc'"`
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholescase $hosttype in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes*[Uu][Ss][Aa][Gg][Ee]:*)
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes hosttype=`PATH=$_probe_PATH; export PATH; package CC="$cc" || $SHELL -c "package CC='$cc'"`
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesesac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesecho '#include <stdio.h>
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgint main(){printf("hello");return 0;}' > dynamic.$src
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesecho 'extern int sfclose() { return 0; }' > fun.$src
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesif $cc -c dynamic.$src && $cc -c fun.$src
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholesthen eval set x $probe_so
f2f3f241c00a7a4bd597e57a19023940e072918abnicholes while :
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg do shift
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes case $# in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes 0) break ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes esac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes for i in foo junk
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes do rm -f dynamic.$exe
0b2a6b63977ab27352a0b525bdad1e1982a1c0b1bnicholes if $cc -L. -o dynamic.$exe dynamic.$obj -l$i
0b2a6b63977ab27352a0b525bdad1e1982a1c0b1bnicholes then : "there's really a -l$i"?
0b2a6b63977ab27352a0b525bdad1e1982a1c0b1bnicholes else rm -f dynamic.$exe
0b2a6b63977ab27352a0b525bdad1e1982a1c0b1bnicholes cat fun.$obj > lib$i$1
0b2a6b63977ab27352a0b525bdad1e1982a1c0b1bnicholes $cc -L. -o dynamic.$exe dynamic.$obj -l$i && $executable dynamic.$exe
0b2a6b63977ab27352a0b525bdad1e1982a1c0b1bnicholes x=$?
0b2a6b63977ab27352a0b525bdad1e1982a1c0b1bnicholes rm lib$i$1
0b2a6b63977ab27352a0b525bdad1e1982a1c0b1bnicholes case $x in
0b2a6b63977ab27352a0b525bdad1e1982a1c0b1bnicholes 0) so=$1
0b2a6b63977ab27352a0b525bdad1e1982a1c0b1bnicholes rm -f dynamic.$exe > lib$i$1.1
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes $cc -L. -o dynamic.$exe dynamic.$obj -l$i && $executable dynamic.$exe
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes x=$?
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes rm lib$i$1.1
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes case $x in
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes 0) sov=1 ;;
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes esac
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes break 2
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes ;;
*) break
;;
esac
fi
done
k=
for i in "" .1 .2 .3 .4 .5 .6 .7 .8 .9
do rm -f dynamic.$exe > libc$1$i
$cc -L. -o dynamic.$exe dynamic.$obj && $executable dynamic.$exe
x=$?
(cd ..; rm $tmpdir/libc$1$i)
case $x in
0) ;;
*) k=X$k
case $k in
XXX) break ;;
esac
;;
esac
done
case $k in
XXX) so=$1
sov=1
break
;;
?*) so=$1
break
;;
esac
done
rm -f dynamic.$exe
if $cc -o dynamic.$exe dynamic.$obj 2>e && $executable dynamic.$exe
then e=`wc -l e`
maybe=
eval set x x $probe_binding
while :
do shift
shift
case $# in
0) break ;;
esac
rm -f dynamic.$exe
$cc -o dynamic.$exe $1 dynamic.$obj 2>e && $executable dynamic.$exe || continue
case $1 in
?*) case $maybe in
"") maybe=$1 ;;
*) maybe=-- ;;
esac
;;
esac
case `wc -l e` in
$e) ;;
*) continue ;;
esac
d=`ls -s dynamic.$exe`
rm -f dynamic.$exe
$cc -o dynamic.$exe $2 dynamic.$obj 2>e && $executable dynamic.$exe || continue
case `wc -l e` in
$e) ;;
*) continue ;;
esac
case `ls -s dynamic.$exe` in
$d) ;;
*) dynamic=$1
static=$2
maybe=
break
;;
esac
done
case $maybe in
""|--) ;;
*) rm -f dynamic.$exe
if $cc -o dynamic.$exe $maybe dynamic.$obj 2>e && $executable dynamic.$exe
then e=`wc -l e`
if $cc -o dynamic.$exe $maybe-bogus-bogus-bogus dynamic.$obj 2>e && $executable dynamic.$exe
then case `wc -l e` in
$e) ;;
*) dynamic=$maybe ;;
esac
else dynamic=$maybe
fi
fi
;;
esac
fi
fi
eval set x $probe_version
shift
for o in "$@"
do if $cc $o > version.out 2>&1
then version_string=`sed -e '/ is /d' -e 's/;/ /g' version.out | sed -e 1q`
case $version_string in
''|*[Ee][Rr][Rr][Oo][Rr]*|*[Ff][Aa][Tt][Aa][Ll]*|*[Ww][Aa][Rr][Nn][Ii][Nn][Gg]*|*[Oo][Pp][Tt][Ii][Oo][Nn]*)
;;
*) version_flags=$o
version_stamp=";VERSION;$o;$version_string;PATH;$cc"
break
;;
esac
fi
done
case $version_stamp in
'') eval set x $probe_version
shift
echo 'int main() { return 0; }' > version.i
for o in "$@"
do if $cc -c $o version.i > version.out 2>&1
then version_string=`sed -e '/ is /d' -e 's/;/ /g' version.out | sed -e 1q`
case $version_string in
''|*[Ee][Rr][Rr][Oo][Rr]*|*[Ff][Aa][Tt][Aa][Ll]*|*[Ww][Aa][Rr][Nn][Ii][Nn][Gg]*|*[Oo][Pp][Tt][Ii][Oo][Nn]*)
;;
*) version_flags=$o
break
;;
esac
fi
done
;;
esac
echo 'int main(){return 0;}' > hosted.$src
$cc -o hosted.$exe hosted.$src && ./hosted.$exe && hosted=1
echo '#!'$sh'
echo "" $@' > cpp
chmod +x cpp
case `./cpp -Dprobe` in
*-Dprobe*)
;;
*) cp /bin/echo cpp
chmod u+w cpp
;;
esac
for prefix in $probe_ppprefix `echo $cc | sed -e '/cc\$/!d' -e 's,cc\$,,' -e 's,.*/,,'`
do cp cpp ${prefix}cpp
done
echo "" > flags.$src
echo '#pragma pp:version' > libpp.$src
if test `realcppC=./cpp $cc -Dprobe -E flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1
then ppenv='realcppC=${ppcmd}'
elif test `cppC=./cpp $cc -Dprobe -E flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1
then ppenv='cppC=${ppcmd}'
elif test `_CPPNAME=./cpp $cc -Dprobe -E flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1
then ppenv='_CPPNAME=${ppcmd}'
elif test `_CPP=./cpp $cc -Dprobe -E flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1
then ppenv='_CPP=${ppcmd}'
elif test `$cc -Dprobe -E -%p+. flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1 && test `$cc -Dprobe -E -%p+. flags.$src | wc -l` -eq 1
then ppopt='-%p+${ppdir}'
elif test `$cc -Dprobe -E -Yp,. flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1
then ppopt='-Yp,${ppdir}'
elif test `$cc -Dprobe -E -Qpath $tmpdir flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1
then ppopt='-Qpath ${ppdir}'
elif test `$cc -Dprobe -E -tp -B./ flags.$src 2>err.out | tee cpp.out | grep -c '[-]Dprobe'` -eq 1 -a ! -s err.out
then ppopt='-tp -B${ppdir}/'
elif test `$cc -Dprobe -E -B./ flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1
then ppopt='-B${ppdir}/'
elif test `$cc -Dprobe -E -tp -h./ -B flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1
then ppopt='-tp -h${ppdir}/ -B'
elif test `$cc -Dprobe -E -t p,./cpp flags.$src | tee cpp.out | grep -c '[-]Dprobe'` -eq 1
then ppopt='-t p,${ppcmd}'
else {
eval set x $probe_verbose
shift
for o in "$@"
do $cc -E $o flags.$src
done
} 2>&1 | sed -e "s/['\"]//g" > cpp.out
fi
set x `sed -e 's,[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]:\\\\,/,g' -e 's,\\\\,/,g' cpp.out`
def=
definclude="-I+C -I-H"
stdinclude=$definclude
case $hosted in
"") usrinclude= ;;
esac
cmdinclude=
while :
do case $# in
0|1) break ;;
esac
shift
case $1 in
-A) case $2 in
*\(*\)) shift
prepred="$prepred `echo $1 | sed 's/\(.*\)(\(.*\))/\1 \2/'`"
;;
esac
;;
-A\(*\))
prepred="$prepred `echo $1 | sed 's/-A\(.*\)(\(.*\))/\1 \2/'`"
;;
-[DI][-+][ABCDEFGHIJKLMNOPQRSTUVWXYZ]*)
stdpp=1
case $1 in
-I?[CH]) case $def in
?*) definclude="$definclude $1" ;;
*) stdinclude="$stdinclude $1" ;;
esac
;;
-I-S*|-YI,*) usrinclude="`echo $1 | sed 's/....//'`" ;;
-Y?,*) ;;
-Y*) usrinclude="`echo $1 | sed 's/..//'`" ;;
esac
;;
-D) shift
case $1 in
[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*=*)
predef="$predef
`echo $1 | sed -e 's/=.*//'`"
;;
[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*)
predef="$predef
$1"
;;
esac
;;
-Dprobe);;
-D*) case $1 in
-D[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*=*)
predef="$predef
`echo $1 | sed -e 's/^-D//' -e 's/=.*//'`"
;;
-D[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]*)
predef="$predef
`echo $1 | sed -e 's/^-D//'`"
;;
esac
;;
-I) shift
case $1 in
/*) case $def in
?*) definclude="$definclude $1" ;;
*) stdinclude="$stdinclude $1" ;;
esac
cmdinclude="$cmdinclude $1"
;;
esac
;;
-I/*) f=`echo X$1 | sed 's/X-I//'`
case $def in
?*) definclude="$definclude $f" ;;
*) stdinclude="$stdinclude $f" ;;
esac
cmdinclude="$cmdinclude $f"
;;
-U) shift
undef="$undef $1"
;;
-U*) undef="$undef `echo $1 | sed 's/^-U//'`"
;;
flags.$src)def=
;;
esac
done
stdinclude="$stdinclude $definclude"
case " $stdinclude " in
*\ $usrinclude\ *)
case $usrinclude in
/usr/include)
usrinclude=
;;
*) case " $stdinclude " in
*\ /usr/include\ *)
usrinclude=
;;
*) usrinclude=/usr/include
;;
esac
;;
esac
;;
esac
tstinclude=`$cc -v -E flags.$src 2>&1 | sed -e '1,/[iI][nN][cC][lL][uU][dD][eE][ ]*<[.][.][.]>/d' -e '/^[eE][nN][dD] [oO][fF] [sS][eE][aA][rR][cC][hH]/,\$d'`
j=$tstinclude
case $j in
*/*) ;;
*) j=$cmdinclude ;;
esac
tstinclude=
good=
nogood=
c_hdr="stdio.h ctype.h"
C_hdr="libc.h"
for i in $j
do if test -d "$i"
then tstinclude="$tstinclude $i"
h=
for f in $c_hdr
do if test -f "$i/$f"
then case $i in
*/CC) nogood=1 ;;
*) good=1 ;;
esac
else h="$h $f"
fi
done
c_hdr=$h
h=
for f in $C_hdr
do if test -f "$i/$f"
then case $i in
*/CC) nogood=1 ;;
*) good=1 ;;
esac
else h="$h $f"
fi
done
C_hdr=$h
fi
done
case $nogood in
1) good=0 ;;
esac
case $good in
1) case $c_hdr in
?*) bad=1
usrinclude=/usr/include
set '' $tstinclude /usr/include
;;
*) set '' $tstinclude
;;
esac
shift
stdinclude=$*
echo "#include <sys/types.h>" > include.$src
$cc -E include.$src | sed -e '/# 1 "[\\/]/!d' -e 's,[^"]*",,' -e 's,[\\/][^\\/]*".*,,' -e 's,[\\/]sys,,' > include.out
for f in `cat include.out`
do if test -d "$f"
then g=`echo $f | sed -e 's,[\\/][\\/]*[^\\/]*$,,'`
case " $stdinclude " in
*\ $f\ *|*\ $g\ *)
;;
*) stdinclude="$stdinclude $f"
case $f in
/usr/include) usrinclude=$f ;;
esac
bad=1
;;
esac
fi
done
;;
*) case $ppopt$ppenv in
?*) echo '#!'$sh'
echo $VIRTUAL_ROOT | sed "s/:.*//"' > cpp
chmod +x cpp
ppcmd=cpp
ppdir=.
eval x='`'$ppenv '$'cc -E $ppopt flags.$src'`'
case $x in
?*) tstinclude=$x/usr/include
;;
esac
cp /bin/echo cpp
chmod u+w cpp
;;
esac
eval set x $probe_include
while :
do shift
case $# in
0) break ;;
esac
echo "#include <$1>" > include.$src
$cc -E include.$src
done > include.out
ccinclude=
x=$stdinclude
stdinclude=
subinclude=
for f in $x $tstinclude `sed -e 's,\\\\,/,g' -e 's,///*,/,g' -e 's,"[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]:/,"/,g' -e '/^#[line ]*[0123456789][0123456789]*[ ][ ]*"[\\/]/!d' -e 's/^#[line ]*[0123456789][0123456789]*[ ][ ]*"\(.*\)[\\/].*".*/\1/' include.out | sort -u`
do case $f in
-*) ;;
*/) f=`echo $f | sed -e 's,//*\$,,'` ;;
*/.) f=`echo $f | sed -e 's,//*.\$,,'` ;;
esac
case $f in
-I*) ;;
*/cc) ccinclude=1
;;
*/sys) continue
;;
*/include/*/*)
;;
*/include/*)
subinclude="$subinclude $f"
continue
;;
esac
if test -d "$f"
then case " $stdinclude " in
*\ $f\ *) ;;
*) stdinclude="$stdinclude $f" ;;
esac
fi
done
rm include.out
case $ccinclude in
?*) eval set x $probe_include
while :
do shift
case $# in
0) break ;;
esac
echo "#include <cc/$1>" > include.$src
if $cc -E include.$src > /dev/null
then break
fi
done
case $# in
0) ;;
*) x=$stdinclude
stdinclude=
for f in $x
do case $f in
*/cc) ;;
*) stdinclude="$stdinclude $f" ;;
esac
done
;;
esac
;;
esac
case $subinclude in
?*) for i in $subinclude
do for j in $stdinclude
do case $i in
$j/*/*) ;;
$j/*) both=
eval set x $probe_include
while :
do shift
case $# in
0) for k in $both
do echo "#include <$k>" > include.$src
$cc -E include.$src > include.out
I=`grep -c $i/$k < include.out`
J=`grep -c $j/$k < include.out`
case $I:$J in
0:*) ;;
*:0) stdinclude="$i $stdinclude"
break
;;
esac
done
continue 3
;;
esac
if test -f $i/$1
then if test ! -f $j/$1
then break 2
fi
both="$both $1"
fi
done
;;
$j) continue 2
;;
esac
done
stdinclude="$i $stdinclude"
done
;;
esac
{
for i in $stdinclude
do
case $i in
$usrinclude) ;;
*) echo $i $i ;;
esac
done
eval set x $probe_include
while :
do shift
case $# in
0) break ;;
esac
echo "#include <$1>" > t.c
p=
for j in `$cc -E t.c | grep "$1" | sed -e 's,\\\\,/,g' -e 's,"[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]:/,"/,g' -e '/^#[line ]*1[ ][ ]*"[\\/]/!d' -e 's/^#[line ]*1[ ][ ]*"\(.*\)[\\/].*".*/\1/'`
do j=`echo $j | sed -e 's,///*,/,g' -e 's,/$,,'`
case $p in
?*) echo $p $j ;;
esac
p=$j
done
done
case $usrinclude in
?*) echo $usrinclude $usrinclude ;;
esac
} | tsort > tmp.tmp
tstinclude=`cat tmp.tmp`
bad=
for i in $stdinclude
do case "
$tstinclude
" in
*"
$i
"*) ;;
*) bad=1
break
;;
esac
done
;;
esac
case $bad in
"") x=$stdinclude
stdinclude=
z=
for i in $tstinclude
do case " $x " in
*" $i "*)
stdinclude="$stdinclude $i"
z=$i
;;
esac
done
case $usrinclude in
'') usrinclude=$z ;;
esac
;;
esac
case $hosted in
"") case $usrinclude in
/usr/include) usrinclude= ;;
esac
;;
esac
case $usrinclude in
?*) case " $stdinclude " in
*\ $usrinclude\ *)
x=$stdinclude
stdinclude=
for f in $x
do case $f in
$usrinclude) ;;
*) stdinclude="$stdinclude $f" ;;
esac
done
;;
esac
;;
esac
# drop dups -- they creep in somehow
x=$stdinclude
stdinclude=
for f in $x
do case " $stdinclude $usrinclude " in
*" $f "*) ;;
*) stdinclude="$stdinclude $f" ;;
esac
done