-
Notifications
You must be signed in to change notification settings - Fork 23
/
configure
executable file
·314 lines (263 loc) · 10 KB
/
configure
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#! /bin/bash
cd $(dirname "$0")
################################################################################
function error () {
echo "$@" 1>&2
exit 1
}
function usage () {
echo "$@" 1>&2
error "Usage: $0 [ OPTIONS... ]
-bindir <dir> Directory where the binaries will be installed
(default: /usr/local/bin)
-libdir <dir> Directory where the OCaml library will be installed
(default: /usr/local/lib/omicrob)
-libexecdir <dir> Directory where the OCaml library executable files will be installed
(default: /usr/local/libexec/omicrob)
-includedir <dir> Directory where the OCaml virtual machine will be installed
(default: /usr/local/include/omicrob)
-mandir <dir> Directory where the manual pages will be installed
(default: /usr/local/man)
-prefix <dir> Set bindir, libdir, libexecdir includedir and mandir to <dir>/bin, <dir>/lib/omicrob,
<dir>/libexec/omicrob, <dir>/include/omicrob and <dir>/man respectively
-target <opt> Select one target for which OMicroB will be installed
(e.g. -target avr|pic32|microbit)"
}
function check_command () {
which "$1" > /dev/null
if [ $? -ne 0 ]; then
error "Error: \"$1\" not installed"
fi
}
function check_absolute_path () {
case "$1" in
/*);;
*) error "Error: \"$1\" is not an absolute path";;
esac
}
function check_directory() {
if [ ! -d "$1" ]; then
error "-e" "Error: directory \"$1\" not found.\nPlease install $2."
fi
}
function remove_trailing_slash () {
echo "$1" | sed 'sX^\(.*[^/]\)/*$X\1X'
}
################################################################################
check_command "gcc"
check_command "ocaml"
check_command "ocamlc"
check_command "ocamlopt"
check_command "ocamlbuild"
check_command "ocamldep"
check_command "ocamldoc"
check_command "ocamlclean"
check_command "mkdir"
check_command "rmdir"
check_command "chmod"
check_command "grep"
check_command "echo"
check_command "cat"
check_command "sed"
check_command "cp"
check_command "rm"
check_command "ar"
check_command "cp"
check_directory "$(ocamlc -where)/../obytelib" "the OByteLib library (ex: opam install obytelib)"
################################################################################
GXX="$(which g++)"
AVR_GXX="$(which avr-g++ 2> /dev/null)"
AVR_OBJCOPY="$(which avr-objcopy 2> /dev/null)"
AVRDUDE="$(which avrdude 2> /dev/null)"
XC32_GXX="$(which xc32-g++ 2> /dev/null)"
XC32_BIN2HEX="$(which xc32-bin2hex 2> /dev/null)"
PIC32PROG="$(which pic32prog 2> /dev/null)"
ARM_GXX="$(which arm-none-eabi-gcc 2> /dev/null)"
ARM_OBJCOPY="$(which arm-none-eabi-objcopy 2> /dev/null)"
OCAML="$(which ocaml.opt 2> /dev/null || which ocaml)"
OCAMLOPT="$(which ocamlopt.opt 2> /dev/null || which ocamlopt)"
OCAMLC="$(which ocamlc.opt 2> /dev/null || which ocamlc)"
OCAMLDOC="$(which ocamldoc.opt 2> /dev/null || which ocamldoc)"
OCAMLBUILD="$(which ocamlbuild)"
OCAMLCLEAN="$(which ocamlclean)"
OCAMLWHERE="$(ocamlc -where)"
VERSION="$(cat VERSION)"
ROOT="$(pwd)"
################################################################################
BINDIR=/usr/local/bin
LIBDIR=/usr/local/lib/omicrob
LIBEXECDIR=/usr/local/libexec/omicrob
INCLUDEDIR=/usr/local/include/omicrob
MANDIR=/usr/local/man
TARGETS=()
while [ $# -ne 0 ]; do
case "$1" in
-bindir)
check_absolute_path "$2"
BINDIR="$(remove_trailing_slash "$2")" ;;
-libdir)
check_absolute_path "$2"
LIBDIR="$(remove_trailing_slash "$2")" ;;
-libexecdir)
check_absolute_path "$2"
LIBEXECDIR="$(remove_trailing_slash "$2")" ;;
-includedir)
check_absolute_path "$2"
INCLUDEDIR="$(remove_trailing_slash "$2")" ;;
-mandir)
check_absolute_path "$2"
MANDIR="$(remove_trailing_slash "$2")" ;;
-prefix)
check_absolute_path "$2"
PREFIX="$(remove_trailing_slash "$2")"
BINDIR="$PREFIX/bin"
LIBDIR="$PREFIX/lib/omicrob"
LIBEXECDIR="$PREFIX/libexec/omicrob"
INCLUDEDIR="$PREFIX/include/omicrob"
MANDIR="$PREFIX/man" ;;
-target)
TARGETS+=($2);;
*)
usage "Don't know what to do with \"$1\""
esac
shift
shift
done
################################################################################
echo -n "\
VERSION := $VERSION
OCAMLCLEAN := $OCAMLCLEAN
BINDIR := $BINDIR
LIBDIR := $LIBDIR
LIBEXECDIR := $LIBEXECDIR
INCLUDEDIR := $INCLUDEDIR
MAN1DIR := $MANDIR/man1
MAN3DIR := $MANDIR/man3
GXX := $GXX
AVR_GXX := $AVR_GXX
AVR_OBJCOPY := $AVR_OBJCOPY
AVRDUDE := $AVRDUDE
XC32_GXX := $XC32_GXX
XC32_BIN2HEX:= $XC32_BIN2HEX
PIC32PROG := $PIC32PROG
ARM_GXX := $ARM_GXX
ARM_OBJCOPY := $ARM_OBJCOPY
OCAMLC := $OCAMLC -w A-4-58-70 -warn-error A -safe-string -strict-formats -strict-sequence
OCAMLOPT := $OCAMLOPT -w A-4-58-70 -warn-error A -safe-string -strict-formats -strict-sequence
OCAMLDOC := $OCAMLDOC
OCAMLBUILD := $OCAMLBUILD -cflags -w,A-4-58-70,-warn-error,A,-safe-string,-strict-formats,-strict-sequence -lflags -w,A-4-58-70,-warn-error,A,-safe-string,-strict-formats,-strict-sequence -no-links -classic-display -build-dir .build
OCAMLWHERE := $OCAMLWHERE
SRC := $ROOT/src
BIN := $ROOT/bin
LIB := $ROOT/lib
ETC := $ROOT/etc
define compile
@\$(MAKE) --no-print-directory -q -C \$1 && \$(MAKE) --no-print-directory -C \$1 || \$(MAKE) -C \$1
endef
define clean
@\$(MAKE) --no-print-directory -C \$1 clean > /dev/null
endef
ARCHS :=
ARCHLIBS :=
" > etc/Makefile.conf
################################################################################
echo -n "\
let builddir = \"$ROOT\"
let libdir = \"$LIBDIR\"
let libexecdir = \"$LIBEXECDIR\"
let includedir = \"$INCLUDEDIR\"
let bindir = \"$BINDIR\"
let ocaml = \"$OCAML\"
let ocamlc = \"$OCAMLC\"
let ocamlclean = \"$OCAMLCLEAN\"
let cxx = \"$GXX\"
let avr_cxx = \"$AVR_GXX\"
let avr_objcopy = \"$AVR_OBJCOPY\"
let avrdude = \"$AVRDUDE\"
let xc32_cxx = \"$XC32_GXX\"
let xc32_bin2hex= \"$XC32_BIN2HEX\"
let pic32prog = \"$PIC32PROG\"
let arm_cxx = \"$ARM_GXX\"
let arm_objcopy = \"$ARM_OBJCOPY\"
let version = \"$VERSION\"
" > etc/config.ml
################################################################################
# Refresh targets files
function reset_targets() {
cp "targets/device_config.ml" "src/omicrob/device_config.ml"
cp "targets/simul_config.ml" "src/simulators/simul_config.ml"
cat "src/byterun/prims/indep-prims.h" > "src/byterun/prims/prims.h"
cat "src/byterun/prims/indep-bindings.c" > "src/byterun/prims/bindings.c"
cat "src/byterun/simul/indep-sf-regs.h" > "src/byterun/simul/sf-regs.h"
cat "src/byterun/simul/indep-sf-regs.c" > "src/byterun/simul/sf-regs.c"
rm -rf "src/byterun/avr/"
rm -rf "src/byterun/pic32"
rm -rf "src/byterun/microbit"
}
reset_targets
function target_avr () {
check_command "avr-g++"
check_command "avr-objcopy"
check_command "avrdude"
check_directory "targets/avr"
cat "targets/avr/device_config.ml" >> "src/omicrob/device_config.ml"
cat "targets/avr/simul_config.ml" >> "src/simulators/simul_config.ml"
mkdir -p "src/byterun/avr"
cp -f "targets/avr/arch-specific.c" "src/byterun/avr/"
cp -f "targets/avr/arch-specific.h" "src/byterun/avr/"
cat "targets/avr/prims/prims.h" >> "src/byterun/prims/prims.h"
cat "targets/avr/prims/bindings.c" >> "src/byterun/prims/bindings.c"
cat "targets/avr/prims/prims.h" >> "src/byterun/simul/sf-regs.h"
cat "targets/avr/simul/sf-regs.c" >> "src/byterun/simul/sf-regs.c"
for f in "arduboy" "arduino_uno" "arduino_mega_2560"
do
mkdir -p "src/byterun/avr/$f/"
cp -f "targets/avr/$f/avrlib.c" "src/byterun/avr/$f/"
done
echo "ARCHS := avr \$(ARCHS)" >> etc/Makefile.conf
echo "ARCHLIBS := avr/arduino_uno avr/arduino_mega_2560 avr/arduboy \$(ARCHLIBS)" >> etc/Makefile.conf
}
function target_pic32 () {
check_command "xc32-g++"
check_command "xc32-bin2hex"
check_command "pic32prog"
check_directory "targets/pic32"
cat "targets/pic32/device_config.ml" >> "src/omicrob/device_config.ml"
mkdir -p "src/byterun/pic32"
cp -f "targets/pic32/arch-specific.c" "src/byterun/pic32/"
cp -f "targets/pic32/arch-specific.h" "src/byterun/pic32/"
cp -fr "targets/pic32/ld" "src/byterun/pic32/"
cat "targets/pic32/prims/prims.h" >> "src/byterun/prims/prims.h"
cat "targets/pic32/prims/bindings.c" >> "src/byterun/prims/bindings.c"
cat "targets/pic32/prims/prims.h" >> "src/byterun/simul/sf-regs.h"
cat "targets/pic32/simul/sf-regs.c" >> "src/byterun/simul/sf-regs.c"
for f in "fubarino_mini" "lchip" "pro_mx7"
do
mkdir -p "src/byterun/pic32/$f/"
cp -f "targets/pic32/$f/pic32lib.c" "src/byterun/pic32/$f/"
done
echo "ARCHS := pic32 \$(ARCHS)" >> etc/Makefile.conf
}
function target_microbit () {
check_command "arm-none-eabi-gcc"
cat "targets/microbit/device_config.ml" >> "src/omicrob/device_config.ml"
cat "targets/microbit/byterun/prims/prims.h" >> "src/byterun/prims/prims.h"
cat "targets/microbit/byterun/prims/bindings.c" >> "src/byterun/prims/bindings.c"
cat "targets/microbit/byterun/prims/prims.h" >> "src/byterun/simul/sf-regs.h"
cat "targets/microbit/byterun/simul/sf-regs.c" >> "src/byterun/simul/sf-regs.c"
cp -rf "targets/microbit/byterun" "src/byterun/microbit"
echo "ARCHS := microbit \$(ARCHS)" >> "etc/Makefile.conf"
}
################################################################################
## Choose targets
for target in ${TARGETS[@]}
do
case "$target" in
avr) target_avr;;
pic32) target_pic32;;
microbit) target_microbit;;
*) echo "Unsupported target \"$target\""
esac
done
################################################################################
echo "** OMicroB configuration completed successfully **"