-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·317 lines (252 loc) · 6.44 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
#!/usr/bin/env bash
SET_FLAGS=(
'NONE'
)
SET_FLAG_PREFIX=NONE
INCLUDE_FLAGS=(
'NONE'
)
INCLUDE_FLAG_PREFIX=NONE
CALLEES=(
"make-html"
)
BUILDS_CALL=(
"scripts/${CALLEES[0]}.sh"
)
function print_targets {
local len=${#CALLEES[@]}
for ((i = 0; i < $len; i++))
do
echo "Target[$((i+1))]: ${CALLEES[$i]}"
done
}
case $1 in
'-h'|'--help')
printf "Usage: ./configure [--help -h] [--targets -t] [--start=<level> --stop=<level>] [--only=<level>]
Description: Runs the build script suite for docs.sd
Note: Make sure to call this script from the repository root
Use @\"\"@ notation to pass in values that contain spaces in them, for example:
./configure --cflags=@\"-Wall -glldb\"@ --cc=clang
Targets: To bound the build step, pass in \`--start=<level>' and/or \`--stop=<level>' as the FIRST
and SECOND argument of the ./configure file. The order doesn't matter.
For example, to skip everything after the first target exclusively, you'd run:
./configure --stop=1
To skip everything before the third target exclusively, you'd run:
./configure --start=3
To execute only one target pass in \`--only=<level>'
To get a list of targets, run:
./configure --targets
Run \`make help' to get an explanation of set- and include- flags
"
exit 1
;;
'-t'|'--targets')
print_targets
exit 1
;;
esac
# faux_args are actually one more than the actual faux args
faux_args=1
__level_start=1 # fallbacks
__level_stop=${#CALLEES[@]} # fallbacks
level_start=$__level_start
level_stop=$__level_stop
function check_bounds {
local first="$1"
local second="$2"
# get faux args
if [[ -z $first ]]
then
faux_args=1
elif [[ -z $second ]]
then
faux_args=2
else
faux_args=3
fi
local opt_arg=
local opt_cmd=
# test `--only'; `only' is always the first one
opt_arg=${first%=*}
opt_cmd=${first#*=}
# apply `--only'
{
[[ $opt_arg = '--only' ]]
} && {
if [[ $opt_cmd -ge $level_start && $opt_cmd -le $level_stop ]]
then
level_start=$opt_cmd
level_stop=$opt_cmd
faux_args=2
# sanity check
if [[ "$level_start" -gt "$__level_stop" || "$level_stop" -gt "$__level_stop" ]]
then
return 1
fi
return 0
else
return 1
fi
} || {
opt_arg=
opt_cmd=
}
local isFirst='yes'
local hasStart='no'
local hasStop='no'
for opt in $first $second
do
opt_arg=${opt%=*}
opt_cmd=${opt#*=}
# empty value means wrong syntax
[[ -z $opt_cmd || $opt_cmd = $opt_arg ]] && return 1
if [[ $opt_arg = '--start' ]]
then
if [[ $hasStart = 'yes' ]]
then
return 1
else
hasStart='yes'
fi
if [[ $opt_cmd -ge $level_start && $opt_cmd -le $level_stop ]]
then
level_start=$opt_cmd
else
return 1
fi
elif [[ $opt_arg = '--stop' ]]
then
if [[ $hasStop = 'yes' ]]
then
return 1
else
hasStop='yes'
fi
if [[ $opt_cmd -ge $level_start && $opt_cmd -le $level_stop ]]
then
level_stop=$opt_cmd
else
return 1
fi
# if didn't find to be the first, don't bother with the second
elif [[ $isFirst = 'yes' ]]
then
faux_args=1
return 0
else
faux_args=2
return 0
fi
isFirst='no'
# sanity check
if [[ "$level_start" -gt "$__level_stop" || "$level_stop" -gt "$__level_stop" ]]
then
return 1
fi
done
}
promise_closing='no'
M4FLAGS=
function parse_flags {
for flag in $can_flags
do
if [[ $promise_closing = 'yes' ]]
then
if [[ ${flag:(-1)} = '@' ]] # add to previous entry, then close promise
then
flag=${flag%@} # ignore trailing `@'
M4FLAGS+="${flag}' "
promise_closing='no'
continue
else # continue adding to previous entry
M4FLAGS+="${flag} "
continue
fi
fi
if [[ ${flag:0:2} = '--' ]] # probably setting a set-flag
then
flag=${flag:2} # ignore the '--'
local flag_arg=${flag%=*} # get argument
flag_arg=${flag_arg^^} # make it uppercase
local flag_cmd=${flag#*=} # get value
# set promise for closing `@'
if [[ ${flag_cmd:0:1} = '@' ]]
then
flag_cmd=${flag_cmd#@} # ignore leading `@'
promise_closing='yes'
fi
# empty argument or value throws error; if they are the same it is likely the bash separator did not find the macthing pair
if [[ -z ${flag_arg} || -z ${flag_cmd} || ${flag_arg} = ${flag_cmd} ]]
then
return 1
fi
local found_set_flag='no'
for set_flag in ${SET_FLAGS[@]} # check against `SET_FLAGS' for a match
do
if [[ ${flag_arg} = ${set_flag} ]]
then
found_set_flag='yes'
break
fi
done
[[ ${found_set_flag} = 'yes' ]] || return 1; # the flag was not found
# the flag was found
if [[ $promise_closing = 'yes' ]]
then
M4FLAGS+="-D${SET_FLAG_PREFIX}${flag_arg}='${flag_cmd} "
else
M4FLAGS+="-D${SET_FLAG_PREFIX}${flag_arg}=${flag_cmd} "
fi
elif [[ ${flag:0:1} = '-' || ${flag:0:1} = '+' ]] # probably setting an include-flag
then
local flag_arg=${flag:1} # ignore the '-' or '+' -> get flag
flag_arg=${flag_arg^^} # make it uppercase
local bool=${flag:0:1}
local found_inc_flag='no'
for inc_flag in ${INCLUDE_FLAGS[@]} # check against `SET_FLAGS' for a match
do
if [[ ${flag_arg} = ${inc_flag} ]]
then
found_inc_flag='yes'
break
fi
done
[[ ${found_inc_flag} = 'yes' ]] || return 1; # the flag was not found
# the flag was found
local arg=
[[ ${bool} = '+' ]] && arg=yes || arg=no
M4FLAGS+="-D${INCLUDE_FLAG_PREFIX}${flag_arg}=${arg} " # ... add it to the m4 flags
else
return 1 # we only accept options
fi
done
}
function call {
echo "[ INFO ] starting level: $level_start"
echo "[ INFO ] stopping level: $level_stop"
level_start=$((level_start-1))
level_stop=$((level_stop-1))
for ((i = $level_start; i <= $level_stop; i++))
do
echo "[ .. ] Calling 'scripts/${CALLEES[$i]}.sh'"
eval ${BUILDS_CALL[$i]}
done
}
{
check_bounds "$1" "$2"
} || {
echo "[ !! ] Bad usage. Run ./configure --help"
exit 1
}
can_flags=${@:$faux_args}
{
parse_flags
} || {
echo "[ !! ] Bad usage. Run ./configure --help"
exit 1
}
call
echo "[ OK ] Done! This source tree is ready to compile!"
# echo "----------------------------------------------------------"
# echo "Run \`make help' to get a list of targets to run make with"
# echo "----------------------------------------------------------"