/
configure
executable file
·329 lines (277 loc) · 7.52 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/bin/bash
# Print help and exit with error code 0
function abs_help() {
cat << EOF
Android Beyond the Stratosphere Auto Build System (ABS²)
https://github.com/abs-platform/abs-software
Standard options:
--help Show this help and exit
--full Compile and flash everything
--docs Generate documentation
--bin-dir=PATH Directory to save the output
Arduino options:
--disable-arduino Don't compile sources for Arduino
--flash-arduino Flash Arduino after compilation
Android options:
--disable-android-java Don't compile Java sources for Android
--disable-android-c Don't compile C sources for Android
--flash-android Flash Android after compilation
Advanced options:
--host-cc=CC Host compiler
--host-cflags=FLAGS Host compiler flags
--host-ldflags=FLAGS Host linker flags
--android-cc=CC Android compiler
--android-cflags=FLAGS Android compiler flags
--android-ldflags=FLAGS Android linker flags
--arduino-cc=CC Arduino compiler
--latex-cc=CC Latex compiler
--latex-flags=FLAGS Latex compiler flags
EOF
exit 0
}
# Write error line to log (now stdout) and exit with error code 1
# Argument: the error to log
function log_error() {
if [ "$1" ]; then
echo "[configure] ERROR: $1"
fi
rm -r $TMP_CONF_DIR
exit 1
}
# Write line to log (now stdout)
# Argument: the line to log
function log() {
if [ "$1" ]; then
echo "[configure] $1"
fi
}
# Write variable for Makefile in Makefile configuration file
# Argument: name of variable
function makefile_export() {
if [ -z "$1" ]; then
log_error "Invalid call to makefile_export"
return
fi
if [ "${!1}" ]; then
echo "export $1 = ${!1}" >> $makefile_conf_file
else
echo "export $1" >> $makefile_conf_file
fi
}
# Write boolean variable for Makefile in Makefile configuration file
# Argument: name of variable
function makefile_bool_export() {
if [ -z "$1" ]; then
log_error "Invalid call to makefile_bool_export"
return
fi
if [ ${!1} == 1 ]; then
# Exports without a value fail
echo "export $1 = 1" >> $makefile_conf_file
else
echo "#export $1" >> $makefile_conf_file
fi
}
# Check that folder exists and create it if it doesn't
# Argument: name of the folder
function check_folder() {
if [ -z $1 ]; then
log_error "Invalid call to check_folder"
return
fi
if [ -a $1 -a ! -d $1 ]; then
log_error "Folder $1 cannot be created"
elif [ ! -a $1 ]; then
mkdir -vp $1
fi
}
# Check that compiler exists and can compile
# Argument: compiler
# Argument (optional): flags
function check_cc() {
if [ -z $1 ]; then
log_error "Invalid call to check_cc"
return
fi
cat > $TMPC << EOF
int main() { return 0; }
EOF
$1 $2 -o $TMPE $TMPC
ret=$?
if [[ $ret != 0 ]]; then
log_error "Compiler not valid ($1)"
fi
}
# Check that compiler exists and can compile
# Argument: compiler
function check_latex() {
if [ -z $1 ]; then
log_error "Invalid call to check_latex"
return
fi
cd "$TMP_CONF_DIR"
cat > $TMPTEX << EOF
\documentclass{report} \begin{document} \end{document}
EOF
$1 $2 $TMPTEX
ret=$?
if [[ $ret != 0 ]]; then
log_error "Compiler not valid ($1)"
fi
cd "../"
}
makefile_conf_file=configure.mk
if [ -f "$makefile_conf_file" ]; then
mv -v "$makefile_conf_file" "$makefile_conf_file.old"
fi
echo "# Autogenerated configuration file. Do not modify" > $makefile_conf_file
# Set default values to variables
flash_arduino=0
build_arduino=1
flash_android=0
build_android_java=1
build_android_c=1
gen_docs=0
ROOT_DIR="${PWD}"
BIN_DIR="${ROOT_DIR}/bin"
HOST_CC="gcc"
HOST_CFLAGS=""
HOST_LDFLAGS=""
ANDROID_CC="arm-linux-androideabi-gcc"
ANDROID_CFLAGS=""
ANDROID_LDFLAGS=""
ARDUINO_CC="arduino"
LATEX_CC="pdflatex"
LATEX_CFLAGS="-interaction=nonstopmode"
# Get parameters
for opt in "$@"
do
optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
case $opt in
# Standard options
--help)
abs_help
;;
--full)
flash_arduino=1
flash_android=1
build_arduino=1
build_android_java=1
build_android_c=1
;;
--docs)
gen_docs=1
;;
--bin-dir=*)
BIN_DIR="$optarg"
;;
# Arduino options
--disable-arduino)
build_arduino=0
;;
--flash-arduino)
flash_arduino=1
;;
# Android options
--disable-android-java)
build_android_java=0
;;
--disable-android-c)
build_android_c=0
;;
--flash-android)
flash_android=1
;;
# Advanced options
--host-cc=*)
HOST_CC="$optarg"
;;
--host-cflags=*)
HOST_CFLAGS="$optarg"
;;
--host-ldflags=*)
HOST_LDFLAGS="$optarg"
;;
--android-cc=*)
ANDROID_CC="$optarg"
;;
--android-cflags=*)
ANDROID_CFLAGS="$optarg"
;;
--android-ldflags=*)
ANDROID_LDFLAGS="$optarg"
;;
--arduino-cc=*)
ARDUINO_CC="$optarg"
;;
--latex-cc=*)
LATEX_CC="$optarg"
;;
--latex-flags=*)
LATEX_CFLAGS="$optarg"
;;
*)
echo "Invalid parameter $opt. Check the documentation"
exit 1
;;
esac
shift # past argument or value
done
# Check compilers
TMP_CONF_DIR="${ROOT_DIR}/tmp-conf"
TMPC="$TMP_CONF_DIR/test.c"
TMPE="$TMP_CONF_DIR/test"
TMPTEX="$TMP_CONF_DIR/test.tex"
check_folder $TMP_CONF_DIR
check_cc $HOST_CC
if [[ $build_android_c != 0 ]]; then
check_cc $ANDROID_CC
fi
if [[ $build_arduino != 0 ]]; then
check_cc $ARDUINO_CC
fi
if [[ $gen_docs != 0 ]]; then
check_latex $LATEX_CC $LATEX_CFLAGS
fi
# Export configuration variables
makefile_bool_export flash_arduino
makefile_bool_export build_arduino
makefile_bool_export build_android_java
makefile_bool_export build_android_c
makefile_bool_export flash_android
makefile_bool_export gen_docs
TEST_FILE="ABS-test.log"
makefile_export TEST_FILE
# Export paths and check folders
makefile_export ROOT_DIR
makefile_export BIN_DIR
check_folder $BIN_DIR
LIB_DIR="${BIN_DIR}/Architecture/Libraries"
INCLUDE_DIR_GEN="${BIN_DIR}/Architecture/Include"
INCLUDE_DIR="${ROOT_DIR}/src/Architecture/Include"
makefile_export LIB_DIR
check_folder $LIB_DIR
makefile_export INCLUDE_DIR_GEN
check_folder $INCLUDE_DIR_GEN
makefile_export INCLUDE_DIR
check_folder $INCLUDE_DIR
check_folder "${BIN_DIR}/Architecture/SDB"
# Export compiler options
HOST_CFLAGS="$HOST_CFLAGS -Wall -Wextra -Werror -I$INCLUDE_DIR -I$INCLUDE_DIR_GEN"
HOST_LDFLAGS="$HOST_LDFLAGS -L$LIB_DIR"
ANDROID_CFLAGS="$ANDROID_CFLAGS -Wall -Wextra -Werror -I$INCLUDE_DIR -I$INCLUDE_DIR_GEN"
ANDROID_LDFLAGS="$ANDROID_LDFLAGS -L$LIB_DIR"
makefile_export HOST_CC
makefile_export HOST_CFLAGS
makefile_export HOST_LDFLAGS
makefile_export ANDROID_CC
makefile_export ANDROID_CFLAGS
makefile_export ANDROID_LDFLAGS
makefile_export ARDUINO_CC
makefile_export LATEX_CC
makefile_export LATEX_CFLAGS
# Export system variables
LD_LIBRARY_PATH="$LIB_DIR:$LD_LIBRARY_PATH"
makefile_export LD_LIBRARY_PATH
makefile_export SHELL
rm -rv $TMP_CONF_DIR