forked from miking-lang/miking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·189 lines (171 loc) · 4.41 KB
/
make.sh
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/sh
###################################################
# Miking is licensed under the MIT license.
# Copyright (C) David Broman. See file LICENSE.txt
#
# To make the build system platform independent,
# building is done using Dune and called from
# this bash script (on UNIX platforms) or
# using make.bat (on Windows).
###################################################
# Forces the script to exit on error
set -e
BOOT_NAME=boot
MI_NAME=mi
MI_LITE_NAME=mi-lite
MI_TMP_NAME=mi-tmp
prefix="${prefix:-$HOME/.local}"
bindir="${bindir:-$prefix/bin}"
libdir="${libdir:-$prefix/lib}"
opamlibdir="${OPAM_SWITCH_PREFIX:+$OPAM_SWITCH_PREFIX/lib}"
ocamllibdir="${ocamllibdir:-${opamlibdir:-$libdir/ocaml/site-lib}}"
mcoredir=$libdir/mcore
# Setup environment variable to find standard library
# (and set test namespace for testing)
export MCORE_LIBS=stdlib=`pwd`/stdlib:test=`pwd`/test
# Setup dune/ocamlfind to use local boot library when available
# Do preserve existing OCAML_PATH to find linenoise et al.
export OCAMLPATH="$(pwd)/build/lib${OCAMLPATH:+:}$OCAMLPATH"
# Compile and build the boot interpreter
build_boot(){
dune build
dune install --prefix=build --bindir=`pwd`/build > /dev/null 2>&1
}
install_boot(){
dune install --prefix=$prefix --libdir=$ocamllibdir > /dev/null 2>&1
}
# Compile a new version of the compiler using the current one
build_mi() {
if [ -e build/$MI_NAME ]
then
time build/$MI_NAME compile src/main/mi.mc
mv -f $MI_NAME build/$MI_TMP_NAME
else
echo "No existing compiler binary was found."
echo "Try running the bootstrapping phase first!"
fi
}
# Build the Miking compiler. If $1 is 'lite', skip the last stage.
build() {
if [ -e build/$MI_NAME ]
then
echo "Bootstrapped compiler already exists. Run 'make clean' before to recompile. "
else
echo "Bootstrapping the Miking compiler (1st round, might take a few minutes)"
time build/$BOOT_NAME eval src/main/mi-lite.mc -- 0 src/main/mi-lite.mc ./$MI_LITE_NAME
echo "Bootstrapping the Miking compiler (2nd round, might take some more time)"
time ./$MI_LITE_NAME 1 src/main/mi.mc ./$MI_NAME
if [ "$1" != "lite" ]
then
echo "Bootstrapping the Miking compiler (3rd round, might take some more time)"
time ./$MI_NAME compile src/main/mi.mc
fi
mv -f $MI_NAME build/$MI_NAME
rm -f $MI_LITE_NAME
fi
}
# Install the Miking compiler
install() {
if [ -e build/$MI_NAME ]; then
rm -rf $mcoredir/stdlib
mkdir -p $bindir $mcoredir
cp -rf stdlib $mcoredir
cp -f build/$MI_NAME $bindir
else
echo "No existing compiler binary was found."
echo "Try compiling the project first!"
fi
}
# Uninstall the Miking bootstrap interpreter and compiler
uninstall() {
dune uninstall --prefix=$prefix --libdir=$ocamllibdir > /dev/null 2>&1
rm -f $bindir/$MI_NAME
rm -rf $mcoredir/stdlib
}
# Lint ocaml source code
lint () {
dune build @fmt
}
# lints and then fixes ocaml source code
fix () {
dune build @fmt --auto-promote
}
compile_test () {
set +e
binary=$(mktemp)
compile="$2 --output $binary"
output="$($compile "$1" 2>&1)"
exit_code=$?
if [ $exit_code -ne 0 ]
then
printf "$1\n$output\nCommand '$compile $1 2>&1' exited with code $exit_code\n\n"
rm -f $binary
exit 1
else
output="$($binary)"
exit_code=$?
rm $binary
printf "$1\n$output\n\n"
if [ $exit_code -ne 0 ]; then exit 1; fi
fi
set -e
}
run_test() {
set +e
output="$1\n$($2 "$1" 2>&1)"
exit_code=$?
printf "$output\n\n"
if [ $exit_code -ne 0 ]; then exit 1; fi
set -e
}
run_js_test() {
./test/js/make.sh run-test-quiet $1
}
run_js_web_test() {
./test/js/web/make.sh run-test-quiet $1
}
case $1 in
boot)
build_boot
;;
lite)
build lite
;;
install-boot)
install_boot
;;
build-mi)
build_mi
;;
run-test)
run_test "$2" "$3"
;;
compile-test)
compile_test "$2" "$3"
;;
run-js-test)
run_js_test "$2"
;;
run-js-web-test)
run_js_web_test "$2"
;;
lint)
lint
;;
fix)
fix
;;
install)
install
;;
uninstall)
uninstall
;;
clean)
rm -rf _build
rm -rf build
;;
all | *)
build
;;
esac