mamprobe revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
280N/A### this script contains archaic constructs that work with all sh variants ###
280N/A# mamprobe - generate MAM cc probe info
280N/A# Glenn Fowler <gsf@research.att.com>
280N/A
280N/Acase $-:$BASH_VERSION in
280N/A*x*:[0123456789]*) : bash set -x is broken :; set +ex ;;
280N/Aesac
280N/A
280N/Acommand=mamprobe
280N/A
280N/A# check the options
280N/A
280N/Aopt=
280N/A
280N/Acase `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
280N/A0123) USAGE=$'
280N/A[-?
280N/A@(#)$Id: mamprobe (AT&T Labs Research) 2011-02-11 $
280N/A]
280N/A[+NAME?mamprobe - generate MAM cc probe info]
671N/A[+DESCRIPTION?\bmamprobe\b generates MAM (make abstract machine) \bcc\b(1)
280N/A probe information for use by \bmamake\b(1). \acc-path\a is the
280N/A absolute path of the probed compiler and \ainfo-file\a is where
280N/A the information is placed. \ainfo-file\a is usually
280N/A \b$INSTALLROOT/lib/probe/C/mam/\b\ahash\a, where \ahash\a is a hash
766N/A of \acc-path\a. Any \ainfo-file\a directories are created if needed.
671N/A If \ainfo-file\a is \b-\b then the probe information is written to
671N/A the standard output.]
671N/A[+?\bmamprobe\b and \bmamake\b are used in the bootstrap phase of
618N/A \bpackage\b(1) installation before \bnmake\b(1) is built. The
766N/A probed variable names are the \bnmake\b(1) names with a \bmam_\b
844N/A prefix, \bCC\b converted to \bcc\b, and \b.\b converted to \b_\b.
844N/A Additional variables are:]{
280N/A [+_hosttype_?the \bpackage\b(1) host type]
280N/A [+mam_cc_L?\b-L\b\adir\a supported]
280N/A [+STDCAT?command to execute for \bcat\b(1); prefixed by
280N/A \bexecrate\b(1) on \b.exe\b challenged systems]
280N/A [+STDCHMOD?command to execute for \bchmod\b(1); prefixed by
280N/A \bexecrate\b(1) on \b.exe\b challenged systems]
280N/A [+STDCMP?command to execute for \bcmp\b(1); prefixed by
280N/A \bexecrate\b(1) on \b.exe\b challenged systems]
280N/A [+STDCP?command to execute for \bcp\b(1); prefixed by
280N/A \bexecrate\b(1) on \b.exe\b challenged systems]
280N/A [+STDED?command to execute for \bed\b(1) or \bex\b(1)]
671N/A [+STDEDFLAGS?flags for \bSTDED\b]
671N/A [+STDLN?command to execute for \bln\b(1); prefixed by
280N/A \bexecrate\b(1) on \b.exe\b challenged systems]
747N/A [+STDMV?command to execute for \bmv\b(1); prefixed by
747N/A \bexecrate\b(1) on \b.exe\b challenged systems]
747N/A [+STDRM?command to execute for \brm\b(1); prefixed by
747N/A \bexecrate\b(1) on \b.exe\b challenged systems]
747N/A}
280N/A[d:debug?Enable probe script debug trace.]
280N/A
280N/Ainfo-file cc-path
280N/A
280N/A[+SEE ALSO?\bexecrate\b(1), \bpackage\b(1), \bmamake\b(1), \bnmake\b(1),
280N/A \bprobe\b(1)]
280N/A'
280N/A while getopts -a "$command" "$USAGE" OPT
280N/A do case $OPT in
280N/A d) opt=-d ;;
280N/A esac
280N/A done
280N/A shift `expr $OPTIND - 1`
;;
*) while :
do case $# in
0) break ;;
esac
case $1 in
--) shift
break
;;
-) break
;;
-d) opt=-d
;;
-*) echo $command: $1: unknown option >&2
;;
*) break
;;
esac
set ''
break
done
;;
esac
# check the args
case $1 in
-) ;;
/*) ;;
*) set '' ;;
esac
case $2 in
/*) ;;
*) set '' ;;
esac
case $# in
0|1) echo "Usage: $command info-file cc-path" >&2; exit 2 ;;
esac
info=$1
shift
cc=$*
# find the make probe script
ifs=${IFS-'
'}
IFS=:
set $PATH
IFS=$ifs
script=lib/probe/C/make/probe
while :
do case $# in
0) echo "$0: ../$script: probe script not found on PATH" >&2
exit 1
;;
esac
case $1 in
'') continue ;;
esac
makeprobe=`echo $1 | sed 's,[^/]*$,'$script,`
if test -x $makeprobe
then break
fi
shift
done
# create the info dir if necessary
case $info in
/*) i=X$info
ifs=${IFS-'
'}
IFS=/
set $i
IFS=$ifs
while :
do i=$1
shift
case $i in
X) break ;;
esac
done
case $info in
//*) path=/ ;;
*) path= ;;
esac
while :
do case $# in
0|1) break ;;
esac
comp=$1
shift
case $comp in
'') continue ;;
esac
path=$path/$comp
if test ! -d $path
then mkdir $path || exit
fi
done
;;
esac
# generate info in a tmp file and rename when finished
case $info in
-) ;;
*) tmp=/tmp/mam$$
trap "exec >/dev/null; rm -f $tmp" 0 1 2 3 15
exec > $tmp
echo "probing C language processor $cc for mam information" >&2
;;
esac
echo "note generated by $0 for $cc"
(
set '' $opt $cc
shift
. $makeprobe "$@"
case " $CC_DIALECT " in
*" -L "*) echo "CC.L = 1" ;;
esac
) | sed \
-e '/^CC\./!d' \
-e 's/^CC./setv mam_cc_/' \
-e 's/^\([^=.]*\)\./\1_/' \
-e 's/^\([^=.]*\)\./\1_/' \
-e 's/ =//' \
-e 's/\$("\([^"]*\)")/\1/g' \
-e 's/\$(\([^)]*\))/${\1}/g' \
-e 's/\${CC\./${mam_cc_}/g'
echo 'setv _hosttype_ ${mam_cc_HOSTTYPE}'
# STD* are standard commands/flags with possible execrate(1)
if (
ed <<!
q
!
) < /dev/null > /dev/null 2>&1
then STDED=ed
else STDED=ex
fi
STDEDFLAGS=-
set STDCAT cat STDCHMOD chmod STDCMP cmp STDCP cp STDLN ln STDMV mv STDRM rm
while :
do case $# in
0|1) break ;;
esac
p=$2
for d in /bin /usr/bin /usr/sbin
do if test -x $d/$p
then p=$d/$p
break
fi
done
eval $1=\$p
shift
shift
done
if execrate
then for n in STDCAT STDCHMOD STDCMP STDCP STDLN STDMV STDRM
do eval $n=\"execrate \$$n\"
done
fi
for n in STDCAT STDCHMOD STDCMP STDCP STDED STDEDFLAGS STDLN STDMV STDRM
do eval echo setv \$n \$$n
done
# all done
case $info in
-) ;;
*) exec >/dev/null
test -f $info && rm -f $info
cp $tmp $info
chmod -w $info
;;
esac