comparison vext @ 1706:d60b30ea9b80 vext

Make configure use vext
author Chris Cannam
date Wed, 07 Jun 2017 09:00:47 +0100
parents
children 434be2f0509e
comparison
equal deleted inserted replaced
1705:c737c43d64af 1706:d60b30ea9b80
1 #!/bin/bash
2
3 # Disable shellcheck warnings for useless-use-of-cat. UUOC is good
4 # practice, not bad: clearer, safer, less error-prone.
5 # shellcheck disable=SC2002
6
7 sml="$VEXT_SML"
8
9 set -eu
10
11 mydir=$(dirname "$0")
12 program="$mydir/vext.sml"
13
14 # We need one of Poly/ML, SML/NJ, or MLton. Since we're running a
15 # single-file SML program as if it were a script, our order of
16 # preference is based on startup speed.
17
18 if [ -z "$sml" ]; then
19 # I think there may be a race condition in the poly interpreter's
20 # tests for open or closed I/O streams - without the "echo" here,
21 # or with stderr redirection, this pipeline will sometimes hang
22 if echo | poly -v 2>/dev/null | grep -q 'Poly/ML'; then
23 sml="poly"
24 elif sml -h 2>&1 | grep -q 'Standard ML of New Jersey'; then
25 sml="smlnj"
26 elif mlton 2>&1 | grep -q 'MLton'; then
27 sml="mlton"
28 else cat 1>&2 <<EOF
29
30 ERROR: No supported SML compiler or interpreter found
31 EOF
32 cat <<EOF
33
34 The Vext external source code manager needs a Standard ML (SML)
35 compiler or interpreter to run.
36
37 Please ensure you have one of the following SML implementations
38 installed and present in your PATH, and try again. These are listed
39 approximately in order of preference for this task.
40
41 1. Poly/ML
42 - often found in a distribution package called: polyml
43 - executable name: poly
44
45 2. Standard ML of New Jersey
46 - often found in a distribution package called: smlnj
47 - executable name: sml
48
49 3. MLton
50 - often found in a distribution package called: mlton
51 - executable name: mlton
52
53 EOF
54 exit 2
55 fi
56 fi
57
58 tmp_sml=$(mktemp /tmp/vext-XXXXXXXX.sml)
59 tmp_out=$(mktemp /tmp/vext-XXXXXXXX.bin)
60
61 trap 'rm -f $tmp_sml $tmp_out' 0
62
63 arglist=""
64 for arg in "$@"; do
65 if [ -n "$arglist" ]; then arglist="$arglist,"; fi
66 if echo "$arg" | grep -q '[^a-z]' ; then
67 arglist="$arglist\"usage\""
68 else
69 arglist="$arglist\"$arg\""
70 fi
71 done
72
73 case "$sml" in
74 poly) echo 'use "'"$program"'"; vext ['"$arglist"'];' |
75 poly -q --error-exit ;;
76 mlton)
77 cat "$program" > "$tmp_sml"
78 echo 'val _ = main ()' >> "$tmp_sml"
79 mlton -output "$tmp_out" "$tmp_sml"
80 "$tmp_out" "$@" ;;
81 smlnj)
82 cat "$program" | (
83 cat <<EOF
84 val smlrun__cp =
85 let val x = !Control.Print.out in
86 Control.Print.out := { say = fn _ => (), flush = fn () => () };
87 x
88 end;
89 val smlrun__prev = ref "";
90 Control.Print.out := {
91 say = fn s =>
92 (if String.isSubstring " Error" s
93 then (Control.Print.out := smlrun__cp;
94 (#say smlrun__cp) (!smlrun__prev);
95 (#say smlrun__cp) s)
96 else (smlrun__prev := s; ())),
97 flush = fn s => ()
98 };
99 EOF
100 cat -
101 cat <<EOF
102 val _ = vext [$arglist];
103 val _ = OS.Process.exit (OS.Process.success);
104 EOF
105 ) > "$tmp_sml"
106 CM_VERBOSE=false sml "$tmp_sml" ;;
107 *)
108 echo "Unknown SML implementation name: $sml";
109 exit 2 ;;
110 esac
111