forked from polyml/polyml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
polyc.in
executable file
·112 lines (98 loc) · 2.69 KB
/
polyc.in
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
#! /bin/sh
prefix=@prefix@
exec_prefix=@exec_prefix@
BINDIR=@bindir@
LINK=@CC@
LIBDIR=@libdir@
LIBS="@LIBS@"
CFLAGS="@CFLAGS@"
# Extra options for Windows. config.status sets these conditionals to either "" or "#".
@NATIVE_WINDOWS_FALSE@EXTRALDFLAGS=""
@NATIVE_WINDOWS_TRUE@@ARCHX86_64_TRUE@EXTRALDFLAGS="-mwindows -Wl,-u,WinMain"
@NATIVE_WINDOWS_TRUE@@ARCHINTERPRET64_TRUE@EXTRALDFLAGS="-mwindows -Wl,-u,WinMain"
@NATIVE_WINDOWS_TRUE@@ARCHI386_TRUE@EXTRALDFLAGS="-mwindows -Wl,-u,_WinMain@16"
@NATIVE_WINDOWS_TRUE@@ARCHINTERPRET_TRUE@EXTRALDFLAGS="-mwindows -Wl,-u,_WinMain@16"
@NATIVE_WINDOWS_TRUE@SUFFIX="obj"
@NATIVE_WINDOWS_FALSE@SUFFIX="o"
# Extra options for Mac OS X
@EXPMACHO_TRUE@EXTRALDFLAGS="-Wl,-no_pie"
TMPSRCFILE=/tmp/polysrc.$$
TMPOBJFILE=/tmp/polyobj.$$.$SUFFIX
trap 'rm -f $TMPSRCFILE $TMPOBJFILE' 0
compile()
{
echo "use \"$1\"; PolyML.export(\"$2\", main);" | ${BINDIR}/poly -q --error-exit
}
link()
{
if [ X"$2" = "X" ]
then
${LINK} ${EXTRALDFLAGS} ${CFLAGS} $1 -L${LIBDIR} -lpolymain -lpolyml ${LIBS}
else
${LINK} ${EXTRALDFLAGS} ${CFLAGS} $1 -o $2 -L${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 " -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=""
objectfile=""
execfile=""
compileonly="no"
while [ $# -gt 0 ]
do
case "$1" in
--help)
printhelp ;;
-c) compileonly="yes";;
-o)
shift
[ $# -eq 0 ] && usage "Expected file name after -o"
execfile="$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)
objectfile=${sourcefile%%.*}
compile $sourcefile $objectfile
;;
no)
if checkml $sourcefile
then
compile $sourcefile $TMPOBJFILE && link $TMPOBJFILE $execfile
else
link $sourcefile $execfile
fi
;;
esac