Import Upstream version 20180207
[hcoop/debian/mlton.git] / bin / mlton-script
... / ...
CommitLineData
1#!/usr/bin/env bash
2
3# This script calls MLton.
4
5set -e
6
7dir=`dirname "$0"`
8lib=`cd "$dir/../lib/mlton" && pwd`
9
10declare -a rargs
11case "$1" in
12@MLton)
13 shift
14 while [ "$#" -gt 0 -a "$1" != "--" ]; do
15 rargs[${#rargs[@]}]="$1"
16 shift
17 done
18 if [ "$#" -gt 0 -a "$1" == "--" ]; then
19 shift
20 else
21 echo '@MLton missing --'
22 exit 1
23 fi
24 ;;
25esac
26
27EXE=
28
29doitMLton () {
30 mlton_mlton="$lib/mlton-compile$EXE"
31 if [ -x "$mlton_mlton" ]; then
32 exec "$mlton_mlton" @MLton ram-slop 0.5 "${rargs[@]}" -- "$@"
33 fi
34}
35doitSMLNJ () {
36 smlnj='sml'
37 if $smlnj -h >/dev/null 2>&1; then
38 smlnj_heap_suffix=`echo 'TextIO.output (TextIO.stdErr, SMLofNJ.SysInfo.getHeapSuffix ());' | $smlnj 2>&1 1> /dev/null`
39 mlton_smlnj_heap="$lib/mlton-smlnj.$smlnj_heap_suffix"
40 if [ -s "$mlton_smlnj_heap" ]; then
41 exec "$smlnj" @SMLload="$mlton_smlnj_heap" "$@"
42 fi
43 fi
44}
45doitPolyML () {
46 mlton_polyml="$lib/mlton-polyml$EXE"
47 if [ -x "$mlton_polyml" ]; then
48 exec "$mlton_polyml" "$@"
49 fi
50}
51
52doit () {
53 doitMLton "$@"
54 doitSMLNJ "$@"
55 doitPolyML "$@"
56 echo 'Unable to run MLton. Check that lib is set properly.' >&2
57 exit 1
58}
59
60CC="gcc"
61
62# You may need to set 'GMP_INC_DIR' so the C compiler can find gmp.h.
63GMP_INC_DIR=
64if [ -n "$GMP_INC_DIR" ]; then
65gmpCCOpts="-cc-opt -I$GMP_INC_DIR"
66fi
67# You may need to set 'GMP_LIB_DIR' so the C compiler can find libgmp.
68GMP_LIB_DIR=
69if [ -n "$GMP_LIB_DIR" ]; then
70gmpLinkOpts="-link-opt -L$GMP_LIB_DIR -target-link-opt netbsd -Wl,-R$GMP_LIB_DIR"
71fi
72
73doit "$lib" \
74 -ar-script "$lib/static-library" \
75 -cc "$CC" \
76 -cc-opt '-std=gnu11 -fno-common' \
77 -cc-opt '-O1 -fomit-frame-pointer -fno-strict-aliasing' \
78 -cc-opt '-w' \
79 -cc-opt-quote "-I$lib/include" \
80 -link-opt '-lm -lgmp' \
81 $gmpCCOpts $gmpLinkOpts \
82 -llvm-llc-opt '-O2' \
83 -llvm-opt-opt '-mem2reg -O2' \
84 -mlb-path-var 'SML_LIB $(LIB_MLTON_DIR)/sml' \
85 -target-as-opt amd64 '-m64' \
86 -target-as-opt x86 '-m32' \
87 -target-cc-opt alpha \
88 '-mieee -mbwx -mtune=ev6 -mfp-rounding-mode=d' \
89 -target-cc-opt amd64 '-m64' \
90 -target-cc-opt aix '-maix64' \
91 -target-cc-opt ia64-hpux "-mlp64" \
92 -target-cc-opt ia64 "-mtune=itanium2" \
93 -target-cc-opt sparc '-m32 -mcpu=v8 -Wa,-xarch=v8plusa' \
94 -target-cc-opt x86 \
95 '-m32
96 -fno-strength-reduce
97 -fschedule-insns
98 -fschedule-insns2
99 -falign-functions=5
100 -falign-jumps=2
101 -falign-loops=2' \
102 -target-link-opt amd64 '-m64' \
103 -target-link-opt alpha \
104 '-mieee -mbwx -mtune=ev6 -mfp-rounding-mode=d' \
105 -target-link-opt aix '-maix64' \
106 -target-link-opt ia64-hpux "-mlp64" \
107 -target-link-opt linux '-Wl,-znoexecstack' \
108 -target-link-opt mingw \
109 '-lws2_32 -lkernel32 -lpsapi -lnetapi32 -lwinmm' \
110 -target-link-opt mingw '-Wl,--enable-stdcall-fixup' \
111 -target-link-opt solaris '-lnsl -lsocket -lrt' \
112 -target-link-opt x86 '-m32' \
113 -profile-exclude '\$\(SML_LIB\)' \
114 "$@"