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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
#! /bin/sh
prefix=@prefix@
exec_prefix=@exec_prefix@
BINDIR=@bindir@
LINK=@CXX@
LIBDIR=@libdir@
LIBS="@LIBS@"
CFLAGS="@polyc_CFLAGS@"
DEFAULT_COMPILER="${BINDIR}/poly"
COMPILER=${DEFAULT_COMPILER}
# Extra options for Windows. config.status sets these conditionals to either "" or "#".
@NATIVE_WINDOWS_FALSE@EXTRALDFLAGS="-Wl,-z,notext"
@NATIVE_WINDOWS_TRUE@@ARCHX86_64_TRUE@EXTRALDFLAGS="-Wl,-u,WinMain"
@NATIVE_WINDOWS_TRUE@@ARCHINTERPRET64_TRUE@EXTRALDFLAGS="-Wl,-u,WinMain"
@NATIVE_WINDOWS_TRUE@@ARCHI386_TRUE@EXTRALDFLAGS="-Wl,-u,_WinMain@16 -Wl,--large-address-aware"
@NATIVE_WINDOWS_TRUE@@ARCHINTERPRET_TRUE@EXTRALDFLAGS="-Wl,-u,_WinMain@16 -Wl,--large-address-aware"
@NATIVE_WINDOWS_TRUE@@WINDOWSGUI_TRUE@EXTRALDFLAGS+=" -mwindows"
@NATIVE_WINDOWS_TRUE@@WINDOWSGUI_FALSE@EXTRALDFLAGS+=" -mconsole"
@NATIVE_WINDOWS_TRUE@SUFFIX="obj"
@NATIVE_WINDOWS_FALSE@SUFFIX="o"
# Msys passes the Windows TEMP in temp (lower case)
# On other systems allow TMPDIR to override /tmp.
@NATIVE_WINDOWS_TRUE@TEMPORARYDIR=${temp:-/tmp}
@NATIVE_WINDOWS_FALSE@TEMPORARYDIR=${TMPDIR:-/tmp}
# Extra options for Mac OS X
@EXPMACHO_TRUE@EXTRALDFLAGS="-Wl,-no_pie"
TMPOBJFILE=${TEMPORARYDIR}/polyobj.$$.$SUFFIX
trap 'rm -f "$TMPOBJFILE"' 0
compile()
{
echo "val () = use (List.nth(CommandLine.arguments(), 2)); val () = PolyML.export(List.nth(CommandLine.arguments(), 3), main);" | ${COMPILER} -q --error-exit "$1" "$2"
}
link()
{
if [ X"$2" = "X" ]
then
${LINK} ${EXTRALDFLAGS} ${CFLAGS} "$1" -L${LIBDIR} -Wl,-rpath,${LIBDIR} -lpolymain -lpolyml ${LIBS}
else
${LINK} ${EXTRALDFLAGS} ${CFLAGS} "$1" -o "$2" -L${LIBDIR} -Wl,-rpath,${LIBDIR} -lpolymain -lpolyml ${LIBS}
fi
}
printhelp()
{
echo "Usage: polyc [OPTION]... [SOURCEFILE]"
echo Compile and link a Standard ML source file with Poly/ML.
echo
echo " -b poly Use 'poly' as compiler instead of ${DEFAULT_COMPILER}"
echo " -c Compile but do not link. The object file is written to the source file with .$SUFFIX extension."
echo " -o output Write the executable file to 'output'"
echo " --help Write this text and exit"
exit
}
usage()
{
echo "$1"
echo "Usage: polyc [OPTION]... [SOURCEFILE]"
exit 1
}
checkml()
{
extension="${1##*.}"
case "$extension" in
sml|ML)
return 0 ;;
o|obj)
return 1;;
*)
test -r "$1" && file -b "$1" | grep -q text ;;
esac
}
sourcefile=""
outputfile=""
compileonly="no"
while [ $# -gt 0 ]
do
case "$1" in
--help)
printhelp ;;
-b)
shift
[ $# -eq 0 ] && usage "Expected file name after -b"
COMPILER="$1";;
-c) compileonly="yes";;
-o)
shift
[ $# -eq 0 ] && usage "Expected file name after -o"
outputfile="$1";;
*)
[ X"$sourcefile" = "X" ] || usage "Only one source file name allowed"
sourcefile="$1";;
esac
shift
done
[ X"$sourcefile" = "X" ] && usage "No input files"
[ -r "$sourcefile" ] || usage "Error: $sourcefile: No such file"
case "$compileonly" in
yes)
if [ "x$outputfile" = "x" ]; then
basename=${sourcefile##*/}
outputfile=${basename%.*}.o
fi
compile "$sourcefile" "$outputfile"
;;
no)
if checkml "$sourcefile"
then
compile "$sourcefile" "$TMPOBJFILE" && link "$TMPOBJFILE" "$outputfile"
else
link "$sourcefile" "$outputfile"
fi
;;
esac
|