-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·423 lines (324 loc) · 9.02 KB
/
configure
File metadata and controls
executable file
·423 lines (324 loc) · 9.02 KB
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
#!/bin/sh
#
# Pseudo-configure script for locating dx build tools
#
# This is intended to look like and mimic the behavior of a normal
# autoconf/configure script; but is really just a simple shell script for
# locating build tools on the local host. As such, it's probably slower,
# buggier and less portable than the usual autoconf/configure tools. On the
# other hand, it's more flexible in terms of cross-compiling, avoids some
# unnecessary (for dx) tests and probably(?) simpler.
#
# This script searches the current PATH + command-line overrides for the
# necessary tools; and inserts those tool paths into the various Makefiles.
# The goal here is to provide some measure of build portability across
# different platforms. At a minimum, this script should work on Linux and
# cygwin. Should probably work under *BSD, too, but not tested. Other
# OS/environments are not supported.
#
# The script assumes the following tools are already in the current PATH:
# - cat
# - chmod
# - rm
# - sed
# - which
# All other dependencies should be resolved by the script itself. The script
# (probably?) also relies on some specific 'bash' features.
#
# See also the documentation under ${DX_ROOT_DIR}/doc/build_process
#
# Usage:
# % configure [options] [tool-definitions]
#
#
# Tools used by the dx build process. Some are required (e.g., for actually
# compiling the code); others are optional (e.g., only used for generating
# documentation)
#
OPTIONAL_TOOLS="DEBUGFS DOXYGEN E2FSCK MKISOFS"
REQUIRED_TOOLS="AR ASM CC CP CXX LD NM OBJCOPY OBJDUMP PATCH SED SHELL STRIP TAR"
#
# These are the makefiles written/updated by this script
#
OUTPUT_FILES="doc/html/Makefile \
media/iso/Makefile \
media/floppy/load-image.sh \
src/Makefile.src"
#
# All script output + debug information is logged here
#
CONFIGURE_LOG="$0.log"
#
# Ensure this tool is available, either via the PATH or via absolute path
#
function find_tool
{
local status=0
log -n "Looking for $1 ... "
local tool=`which $1 2>/dev/null`
if [ -n "${tool}" ]; then
# Found tool in current PATH; or user provided explicit path on
# the command line
log "${tool}"
status=0
else
log "Not found!"
status=1
fi
return $status
}
#
# Show supported options + exit
#
function help
{
cat <<-END_OF_HELP
DX pseudo-configure script
Usage:
$0 [--distclean] [-?|-h|--help] [--host=<HOST-SPEC>] [TOOL-DEFINITIONS]
--distclean deletes any Makefiles generated by this script
-h, --help displays this help message
--host=<HOST-SPEC> enables cross-compilation support. Required on
platforms where the default executable format is not 32b ELF
(e.g, cygwin, 64b Linux, etc). HOST-SPEC should be the usual
"cpu-vendor-os" triplet. For example, if your cross compiler is
i686-pc-elf-gcc, then use '--host=i686-pc-elf'.
TOOL-DEFINITIONS are paths + overrides for specifying tools and tool
locations. For example, if you have gcc installed under
/non/standard/path/to/my-gcc then add CC=/non/standard/path/to/my-gcc
to the command line.
These tools are required (in the PATH, in the environment or on the
command-line):
${REQUIRED_TOOLS}
These tools are optional. If not present, some build features may be
unavailable:
${OPTIONAL_TOOLS}
All script output is logged to ${CONFIGURE_LOG}
END_OF_HELP
exit 1
}
#
# Write a message to the console + the log file
#
function log
{
echo $*
echo $* >> ${CONFIGURE_LOG}
return
}
#
# main() #################################################################
#
# Assume no cross-compiling, by default
CROSS_COMPILE_PREFIX=
HOST=
#
# Parse the command line arguments, if any
#
for argument in $*; do
case ${argument} in
-c|--check)
# Verify that the source tree has been properly configured
for file in ${OUTPUT_FILES}; do
if [ ! -e ${file} ]; then
echo "Must run 'configure' before building."
exit 1
fi
done
exit 0
;;
-d|--debug)
# Enable debug support
set -x
;;
--distclean)
# Clean the output files generated by this script
rm -f ${OUTPUT_FILES} ${CONFIGURE_LOG}
exit 0
;;
-h|-?|--help)
help
;;
--host=*)
# Enable cross-compiling
HOST=${argument}
;;
*=*)
# Assume this is an explicit definition or path to some tool (e.g,
# CC=gcc, etc), so automatically include this definition locally
# to override the defaults below
eval ${argument}
;;
*)
echo "Unrecognized argument: ${argument}"
help
;;
esac
done
#
# At this point, actually want to search for tools and generate the various
# output files
#
#
# Reset/restart the log file
#
cat >${CONFIGURE_LOG} <<-END_OF_LOG_HEADER
DX pseudo-configure script
Last invoked: `date`
Last invoked as: $0 $*
PATH was: `echo ${PATH}`
END_OF_LOG_HEADER
#
# The 'which' tool is required; this script cannot proceed without it
#
WHICH=`which which 2>/dev/null`
if [ -z "${WHICH}" ]; then
log "Unable to find 'which' tool, required for configure operation"
exit 2
fi
#
# Compute cross-compiler prefix, if necessary
#
if [ -n "${HOST}" ]; then
# Ensure sed is available first
SED=${SED:-`which sed 2>/dev/null`}
if [ -z "${SED}" ]; then
log "Error: Cannot process '--host' prefix without 'sed'"
log "Try adding 'SED=/path/to/sed' definition to command line"
exit 1
fi
# Assume the --host value is the prefix on the cross-tools (e.g.,
# i386-elf-gcc)
CROSS_COMPILE_PREFIX=`echo ${HOST} | ${SED} 's/--host=\(.*\)/\1-/' -`
if [ ${CROSS_COMPILE_PREFIX} != "-" ]; then
log "OK, will look for cross-tools (${CROSS_COMPILE_PREFIX})"
else
log "Bad --host value"
help
fi
fi
#
# Establish the basic tool definitions. Values provided on the command line
# override the defaults provided here
#
AR=${AR:-ar}
ASM=${ASM:-${CROSS_COMPILE_PREFIX}gcc} # Use gcc front-end by default
CC=${CC:-${CROSS_COMPILE_PREFIX}gcc}
CP=${CP:-cp}
CXX=${CXX:-${CROSS_COMPILE_PREFIX}gcc} # Use gcc front-end by default
DEBUGFS=${DEBUGFS:-debugfs}
DOXYGEN=${DOXYGEN:-doxygen}
E2FSCK=${E2FSCK:-e2fsck}
LD=${LD:-${CROSS_COMPILE_PREFIX}ld}
MKISOFS=${MKISOFS:-mkisofs}
NM=${NM:-nm}
OBJCOPY=${OBJCOPY:-objcopy}
OBJDUMP=${OBJDUMP:-objdump}
PATCH=${PATCH:-patch}
SED=${SED:-sed}
SHELL=${SHELL:-bash}
SIZET_DEFINITION=${SIZET_DEFINITION}
STRIP=${STRIP:-strip}
TAR=${TAR:-tar}
#
# Ensure the tools actually exist, either in the PATH or via the values given
# on the command line. This does not actually invoke or validate the tools
# themselves -- a significant departure from the usual autoconf/configure
# behavior
#
for tool in ${REQUIRED_TOOLS}; do
eval "find_tool \$${tool}"
if [ $? -ne 0 ]; then
log "Error: Unable to find required tool: ${tool}"
exit 1
fi
done
for tool in ${OPTIONAL_TOOLS}; do
eval "find_tool \$${tool}"
if [ $? -ne 0 ]; then
log "Warning: Unable to find optional tool: ${tool}"
fi
done
#
# As a nicety, attempt to determine the cross-compiler's preferred definition
# of size_t. Typically, it's either 'unsigned long' or 'unsigned int'. See
# the definitions in src/inc/size_t.h
#
TEST_OBJ=test_file.o
TEST_SRC=test_file.cpp
cat >${TEST_SRC} <<END_OF_SOURCE
#ifdef SIZET_IS_ULONG
typedef unsigned long size_t;
#elif SIZET_IS_UINT
typedef unsigned int size_t;
#endif
void*
operator new(size_t n)
{ return (void*)(n + 1234); }
int
main(int argc, char** argv)
{
void* x = operator new(32);
return(x ? 0 : 1);
}
END_OF_SOURCE
# Attempt to compile the sample source, using each definition of size_t
for option in SIZET_IS_UINT SIZET_IS_ULONG; do
${CXX} -c -Wall -D${option} -o ${TEST_OBJ} ${TEST_SRC} > /dev/null 2>&1
if [ $? -eq 0 ]; then
# The compiler will accept this definition of size_t; so save it for
# later use and continue
log "Using definition of size_t: ${option}"
SIZET_DEFINITION=${option}
break
fi
done
rm ${TEST_SRC}
rm ${TEST_OBJ}
if [ -z "${SIZET_DEFINITION}" ]; then
log "Error: unable to determine preferred type of size_t"
exit 1
fi
#
# Generate a sed script to insert the various tool definitions
#
log
log "Generating translation script ..."
SED_PROGRAM="$0.sed.$$"
echo > ${SED_PROGRAM}
for tool in ${REQUIRED_TOOLS} ${OPTIONAL_TOOLS} SIZET_DEFINITION; do
# The script is a series of "s/tool-pattern/tool-path/" commands
eval "echo \"s,@${tool}@,\$${tool},g\" >> ${SED_PROGRAM}"
done
if [ ! -e ${SED_PROGRAM} ]; then
log "Unable to generate 'sed' program!"
exit 1
fi
echo "SED SCRIPT:" >> ${CONFIGURE_LOG}
cat ${SED_PROGRAM} >> ${CONFIGURE_LOG}
echo "END OF SCRIPT" >> ${CONFIGURE_LOG}
echo "" >> ${CONFIGURE_LOG}
#
# Now generate the various makefiles, inserting these tool definitions where
# necessary
#
for output_file in ${OUTPUT_FILES}; do
input_file="${output_file}.in"
if [ ! -e ${input_file} ]; then
log "Skipping missing input file: ${input_file}"
continue
fi
# Create + fixup the output file with the detected tool settings
log "Generating: ${output_file}"
rm -f ${output_file}
${SED} -f ${SED_PROGRAM} --posix ${input_file} > ${output_file}
chmod -w ${output_file}
done
#
# Done. Cleanup + exit
#
rm ${SED_PROGRAM}
log
log "Done!"
log
exit 0