1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#!/bin/sh
#
# ffi-config [cfgdir] [options...]
#
# -cpu print the supported cpu name or `any'
# -abi print the supported abu name or `libffi'
# -lib print nothing if supported, otherwise `-lffi'
# -query exit with status 0 if supported, 1 if libffi required
cfgdir=../../config
if [ $# -gt 0 ]; then
case $1 in
-*) ;;
*) cfgdir=$1; shift;;
esac
fi
ffidir=.
if [ $# -gt 0 ]; then
case $1 in
-*) ;;
*) ffidir=$1; shift;;
esac
fi
guess=`${cfgdir}/config.guess`
host=`${cfgdir}/config.sub ${guess}`
cpu=`echo ${host} | sed 's/-.*//'`
abi=`echo ${host} | sed 's/[^-]*-[^-]*-//;s/-.*//'`
lib=
case ${cpu} in
powerpc|ppc) cpu=ppc;;
i[3456789]86) cpu=x86;;
*) cpu=any;;
esac
case ${abi} in
linux) abi=sysv;;
darwin*) abi=darwin;;
*) abi=libffi; lib="-lffi";;
esac
if [ ! -f ${ffidir}/${cpu}-${abi}.c ] || [ ! -f ${ffidir}/${cpu}-${abi}-asm.S ]; then
cpu=any
abi=libffi
lib="-lffi"
fi
if [ ! -f ${ffidir}/${cpu}-${abi}.c ] || [ ! -f ${ffidir}/${cpu}-${abi}-asm.S ]; then
echo "Could not find ${cpu}-${abi}.c and ${cpu}-${abi}-asm.S" >&2
exit 1
fi
if [ $# -eq 0 ]; then
echo "${cpu}-${abi}" "${lib}"
else
while [ $# -gt 0 ]; do
case $1 in
-cpu) echo ${cpu};;
-abi) echo ${abi};;
-lib) echo ${lib};;
-cpu-abi) echo ${cpu}-${abi};;
-query) if [ ${abi} = "libffi" ]; then exit 1; else exit 0; fi;;
*) echo "$0: I don't understand \`$1'" >&1; exit 1;;
esac
shift
done
fi
exit 0
|