-
Notifications
You must be signed in to change notification settings - Fork 3
/
polybuild
executable file
·71 lines (57 loc) · 1.82 KB
/
polybuild
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
#!/bin/bash
#
# polybuild - compile a SML program defined in a MLB file using Poly/ML
#
# Chris Cannam, 2015-2022. MIT licence
set -e
usage() {
me=$(basename "$0")
echo 1>&2
echo "$me: Compile a SML program defined in a MLB file using Poly/ML" 1>&2
echo 1>&2
echo "Usage: $me [-o output] file.sml" 1>&2
echo " $me [-u] [-o output] file.mlb" 1>&2
echo " where" 1>&2
echo " -u: Unique: \"use\" each file only once, regardless of how many times it" 1>&2
echo " appears in the MLB file and its dependencies. The default is to use" 1>&2
echo " a file again each time it appears." 1>&2
echo " Neither mode complies with the official interpretation for MLB files" 1>&2
echo " in this respect (that's much harder to do). Both modes may compile" 1>&2
echo " code that the other mode does not!" 1>&2
echo " Unique mode is usually faster and is never much slower." 1>&2
echo 1>&2
echo "This script is not part of Poly/ML and has no official status." 1>&2
echo "Written by Chris Cannam, 2015-2022." 1>&2
echo 1>&2
exit 2
}
unique_arg=""
if [ "$1" = "-u" ]; then
unique_arg="-u"
shift
fi
arg="$1"
[ -n "$arg" ] || usage
out=""
if [ t"$arg" = "t-o" ]; then
shift
out="$1"
[ -n "$out" ] || usage
shift
arg="$1"
[ -n "$arg" ] || usage
fi
shift
set -u
mydir=$(dirname "$0")
. "$mydir/smlbuild-include.sh"
if [ -z "$out" ]; then
out=$(get_outfile "$arg")
fi
tmpobj=$(get_tmpobjfile "$arg")
trap "rm -f ${tmpobj}" 0
( expand_arg $unique_arg "$arg" |
sed 's|^\(.*\)$|use "\1";|' ; # wrap filenames in REPL use calls
echo 'PolyML.export("'"$tmpobj"'", main);' ) | # ask poly to export object file
poly -q --error-exit &&
polyc -o "$out" "$tmpobj" # compile object to executable