annotate vext @ 218:eceead3d61be

Ah, I see. Update another platform target & qm-dsp library debug build
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 01 May 2018 10:20:38 +0100
parents 9b30f7f972c9
children
rev   line source
c@187 1 #!/bin/bash
c@187 2
c@187 3 # Disable shellcheck warnings for useless-use-of-cat. UUOC is good
c@187 4 # practice, not bad: clearer, safer, less error-prone.
c@187 5 # shellcheck disable=SC2002
c@187 6
c@187 7 sml="$VEXT_SML"
c@187 8
c@187 9 set -eu
c@187 10
c@187 11 mydir=$(dirname "$0")
c@187 12 program="$mydir/vext.sml"
c@187 13
c@187 14 hasher=
c@187 15 local_install=
c@187 16 if [ -w "$mydir" ]; then
c@187 17 if echo | sha256sum >/dev/null 2>&1 ; then
c@187 18 hasher=sha256sum
c@187 19 local_install=true
c@187 20 elif echo | shasum >/dev/null 2>&1 ; then
c@187 21 hasher=shasum
c@187 22 local_install=true
c@187 23 else
c@187 24 echo "WARNING: sha256sum or shasum program not found" 1>&2
c@187 25 fi
c@187 26 fi
c@187 27
c@187 28 if [ -n "$local_install" ]; then
c@187 29 hash=$(echo "$sml" | cat "$program" - | $hasher | cut -c1-16)
c@187 30 gen_sml=$mydir/.vext-$hash.sml
c@187 31 gen_out=$mydir/.vext-$hash.bin
c@187 32 trap 'rm -f $gen_sml' 0
c@187 33 else
c@187 34 gen_sml=$(mktemp /tmp/vext-XXXXXXXX.sml)
c@187 35 gen_out=$(mktemp /tmp/vext-XXXXXXXX.bin)
c@187 36 trap 'rm -f $gen_sml $gen_out' 0
c@187 37 fi
c@187 38
c@187 39 if [ -x "$gen_out" ]; then
c@187 40 exec "$gen_out" "$@"
c@187 41 fi
c@187 42
c@187 43 # We need one of Poly/ML, SML/NJ, or MLton. Since we're running a
c@187 44 # single-file SML program as if it were a script, our order of
c@187 45 # preference is based on startup speed, except in the local_install
c@187 46 # case where we retain a persistent binary.
c@187 47
c@187 48 if [ -z "$sml" ]; then
c@187 49 if [ -n "$local_install" ] && mlton 2>&1 | grep -q 'MLton'; then
c@187 50 sml="mlton"
c@187 51 elif sml -h 2>&1 | grep -q 'Standard ML of New Jersey'; then
c@187 52 sml="smlnj"
c@187 53 # We would prefer Poly/ML to SML/NJ, except that Poly v5.7 has a
c@187 54 # nasty bug that occasionally causes it to deadlock on startup.
c@187 55 # That appears to be fixed in their repo, so we could promote it
c@187 56 # up the order again at some point in future
c@187 57 elif echo | poly -v 2>/dev/null | grep -q 'Poly/ML'; then
c@187 58 sml="poly"
c@187 59 elif mlton 2>&1 | grep -q 'MLton'; then
c@187 60 sml="mlton"
c@187 61 else cat 1>&2 <<EOF
c@187 62
c@187 63 ERROR: No supported SML compiler or interpreter found
c@187 64 EOF
c@187 65 cat 1>&2 <<EOF
c@187 66
c@187 67 The Vext external source code manager needs a Standard ML (SML)
c@187 68 compiler or interpreter to run.
c@187 69
c@187 70 Please ensure you have one of the following SML implementations
c@187 71 installed and present in your PATH, and try again.
c@187 72
c@187 73 1. Standard ML of New Jersey
c@187 74 - often found in a distribution package called: smlnj
c@187 75 - executable name: sml
c@187 76
c@187 77 2. Poly/ML
c@187 78 - often found in a distribution package called: polyml
c@187 79 - executable name: poly
c@187 80
c@187 81 3. MLton
c@187 82 - often found in a distribution package called: mlton
c@187 83 - executable name: mlton
c@187 84
c@187 85 EOF
c@187 86 exit 2
c@187 87 fi
c@187 88 fi
c@187 89
c@187 90 arglist=""
c@187 91 for arg in "$@"; do
c@187 92 if [ -n "$arglist" ]; then arglist="$arglist,"; fi
c@187 93 if echo "$arg" | grep -q '["'"'"']' ; then
c@187 94 arglist="$arglist\"usage\""
c@187 95 else
c@187 96 arglist="$arglist\"$arg\""
c@187 97 fi
c@187 98 done
c@187 99
c@187 100 case "$sml" in
c@187 101 poly)
c@187 102 if [ -n "$local_install" ] && polyc --help >/dev/null 2>&1 ; then
c@187 103 if [ ! -x "$gen_out" ]; then
c@187 104 polyc -o "$gen_out" "$program"
c@187 105 fi
c@187 106 "$gen_out" "$@"
c@187 107 else
c@187 108 echo 'use "'"$program"'"; vext ['"$arglist"'];' |
c@187 109 poly -q --error-exit
c@187 110 fi ;;
c@187 111 mlton)
c@187 112 if [ ! -x "$gen_out" ]; then
c@187 113 echo "[Precompiling Vext binary...]" 1>&2
c@187 114 echo "val _ = main ()" | cat "$program" - > "$gen_sml"
c@187 115 mlton -output "$gen_out" "$gen_sml"
c@187 116 fi
c@187 117 "$gen_out" "$@" ;;
c@187 118 smlnj)
c@187 119 cat "$program" | (
c@187 120 cat <<EOF
c@187 121 val smlrun__cp =
c@187 122 let val x = !Control.Print.out in
c@187 123 Control.Print.out := { say = fn _ => (), flush = fn () => () };
c@187 124 x
c@187 125 end;
c@187 126 val smlrun__prev = ref "";
c@187 127 Control.Print.out := {
c@187 128 say = fn s =>
c@187 129 (if String.isSubstring " Error" s
c@187 130 then (Control.Print.out := smlrun__cp;
c@187 131 (#say smlrun__cp) (!smlrun__prev);
c@187 132 (#say smlrun__cp) s)
c@187 133 else (smlrun__prev := s; ())),
c@187 134 flush = fn s => ()
c@187 135 };
c@187 136 EOF
c@187 137 cat -
c@187 138 cat <<EOF
c@187 139 val _ = vext [$arglist];
c@187 140 val _ = OS.Process.exit (OS.Process.success);
c@187 141 EOF
c@187 142 ) > "$gen_sml"
c@187 143 CM_VERBOSE=false sml "$gen_sml" ;;
c@187 144 *)
c@187 145 echo "ERROR: Unknown SML implementation name: $sml" 1>&2;
c@187 146 exit 2 ;;
c@187 147 esac
c@187 148