-
Notifications
You must be signed in to change notification settings - Fork 2
/
configure
executable file
·485 lines (427 loc) · 12 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
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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#!/bin/bash
# Copyright 2017, Microsoft Research, Daan Leijen
echo "--- Configuring build ---"
configure_options=$*
target_abi=""
target_os=""
cc=gcc
ar=""
link=""
ccoption=''
ccflags=''
asmflags=''
verbose=no
cxx=''
cxxflags=''
# Parse command-line arguments
while : ; do
flag="$1"
case "$flag" in
*=*) flag_arg="${flag#*=}";;
*) flag_arg="yes" ;;
esac
# echo "option: $flag, arg: $flag_arg"
case "$flag" in
"") break;;
-cc-opts*|--cc-opts*)
ccflags=$flag_arg;;
-asm-opts*|--asm-opts*)
asmflags=$flag_arg;;
-cxx-opts*|--cxx-opts*)
cxxflags=$flag_arg;;
-cc*|--cc*)
ccoption=$flag_arg;;
-cxx*|--cxx*)
cxx=$flag_arg;;
-ar*|--ar*)
ar=$flag_arg;;
-link*|--link*)
link=$flag_arg;;
-verbose|--verbose)
verbose="yes";;
-m*|--m*|-abi*|--abi*)
target_abi=$flag_arg;;
-os*|--os*)
target_os=$flag_arg;;
-h|--help|-\?|help|\?)
echo "./configure [options]"
echo " --cc=<ccomp> set the c-compiler (for example 'clang')"
echo " --cxx=<ccomp> set the c++-compiler (for example 'clang++')"
echo " --ar=<libarch> set the library archiver"
echo " --link=<linker> set the linker"
echo " --cc-opts=<options> set extra c-compiler options (for example '-m32')"
echo " --asm-opts=<options> set extra assembler options (for example '-m32')"
echo " --abi=<abi> set target ABI (for example: 'x86' or 'amd64')"
echo " --os=<os> set target OS (for example: 'windows' or 'linux')"
echo " --verbose be verbose"
exit 0;;
*) echo "warning: unknown option \"$1\"." 1>&2
esac
shift
done
echo "use '--help' for help on configuation options."
export verbose
# Generate the files
cd config
echo
echo "--- Check system ---"
# Do we have a c compiler?
if test -z "$ccoption"; then
if sh ./searchpath gcc; then
cc="gcc"
elif sh ./searchpath clang; then
cc="clang"
elif sh ./searchpath cl; then
cc="cl"
else
cc="cc"
fi
else
cc="$ccoption"
fi
ccname="$(basename $cc)"
if test -z "$cxx"; then
case "$ccname" in
gcc) cxx=${cc/%gcc/g++};;
clang) cxx=${cc/%clang/clang++};;
clang-) cxx=${cc/clang-/clang++-};;
*) cxx="$cc";;
esac
fi
# Check if we can run the C-compiler
$cc -v 2>/dev/null 1>/dev/null
case $? in
0) echo "C compiler '$cc' found";;
*) $cc -v
echo "Unable to compile the test program."
echo "Make sure the C compiler '$cc' is properly installed."
exit 2;;
esac
# Determine the target OS
if test -z "$target_os"; then
# check for 32bit compilation on x64 platform.
cctarget=`$cc $ccflags -v 2>&1 | grep -o '^[Tt]arget: *[^ ]*'`
cctarget="${cctarget#*: }"
if test -z "$cctarget"; then
target_os=`uname -s || uname -o`
target_arch=`uname -m || uname -p`
echo "Host is $target_arch-$target_os"
else
echo "Compiler target: $cctarget"
target_os="${cctarget#*-}"
case "$target_os" in
mingw32)
target_arch="x86";;
*)
target_arch="${cctarget%%-*}";;
esac
fi
fi
if test -z "$target_os"; then
echo "Cannot determine the target OS; give it as on option `--os=<os>`"
echo "For example: `configure --os=linux`"
exit 1
fi
# canonical target os
case "$target_os" in
mingw*|windows*|msys*|w64-*|pc-windows*)
echo "Normalize OS from '$target_os' to 'windows'"
target_os="windows";;
esac
# Determine ABI
if test -z "$target_abi"; then
if test -z "$target_arch"; then
target_abi=`uname -m`
else
target_abi="$target_arch"
fi
fi
if test -z "$target_abi"; then
echo "Cannot determine the target ABI; give it as on option '--abi=<abi>'"
echo "For example: './configure --abi=amd64'"
exit 1;
fi
# Canonical target ABI
case "$target_abi,$target_os" in
aarch64,*)
echo "Normalize target ABI from aarch64 to arm64"
target_abi="arm64";;
x86_64,windows)
echo "Normalize target ABI from x86_64 to x64 (as used on Windows)"
target_abi="x64";;
x86_64,*|i686-64,*)
echo "Normalize target ABI from x86_64 to amd64 (used on Linux, etc)"
target_abi="amd64";;
i[3456]86,windows)
echo "Normalize target ABI from $target_abi to x86 (as used on Win32)"
target_abi="x86";;
i[3456]86,*)
echo "Normalize target ABI from $target_abi to amd32 (used on Linux, etc)"
target_abi="amd32";;
armv[67]*,*)
echo "Normalize target ABI from $target_abi to arm (32-bit)"
target_abi="arm";;
armv[89]*,*)
echo "Normalize target ABI from $target_abi to arm (32-bit)"
target_abi="arm";;
x86pc,*|i86pc,*|x86at,*)
echo "Normalize target ABI from $target_abi to amd32 (32-bit)"
target_abi="amd32";;
esac
# Configure the c compiler for the runtime system
if test -z "$link"; then
link=$cc
fi
linkflags=""
linkflagout="-o "
arflags="rcs"
arflagout=""
ccflagout="-o "
asmflagout="-o "
ostype="unix"
exe=""
dll=".dll"
lib=".a"
obj=".o"
asm=".s"
ccflagopt="-O3"
ccflagdebug="-g"
ccflag99=""
ccdepend="$cc -MM "
if test "$target_os" = "windows"; then
echo "target to windows: $target_os"
exe=".exe"
lib=".lib"
fi
case "$target_abi" in
x32) ccflags="$ccflags -mx32";;
esac
# Set final target configuration
target="$target_abi-$target_os"
config="$ccname-$target"
echo ""
echo "Configure for target: $ccname, $target"
echo ""
case "$ccname" in
clang-cl)
cxxflags="-TP -EHa -W3 $ccflags"
ccflags="-TC -W3 $ccflags"
ccflagopt="-O2" # fiber-safe optimize
ccflagdebug="-Z7"
ccdepend="clang -MM "
if test -z "$ar"; then
ar="${cc/%clang-cl/llvm-lib}"
fi
arflags=""
arflagout="-OUT:"
ccflagout="-Fo"
asmflagout="-Fo"
linkflagout="-Fe"
lib=".lib"
obj=".obj"
asm=".s";;
cl)
cclinkflags="-nologo"
cxxflags="-TP -EHa -nologo -W3 -Za $ccflags"
ccflags="-TC -nologo -W3 -Za $ccflags"
ccflagopt="-O2" # fiber-safe optimize
ccflagdebug="-Zi"
if test -z "$ar"; then
ar="lib"
fi
arflags=""
arflagout="-OUT:"
ccflagout="-Fo"
asmflagout="-Fo"
linkflagout="-Fe"
lib=".lib"
obj=".obj"
asm=".asm";;
gcc*)
ccflags="-Wall $ccflags"
ccflag99="-std=gnu99 -pedantic"
cxxflags="-std=c++11 $ccflags"
asmflags="-Wall $asmflags";;
clang*)
if test -z "$ar"; then
ar="${cc/clang/llvm-ar}"
fi
ccflags="-Wall $ccflags"
ccflag99="-std=c99"
cxxflags="-std=c++11 $ccflags"
asmflags="-Wall $asmflags";;
*)
echo "warning: unknown c-compiler '$ccname' -- command options might be wrong";;
esac
if test -z "$ar"; then
ar="ar"
fi
case "$ccname,$target_os" in
clang*,windows)
ccversion=`$cc -v 2>&1 | grep -o '^clang version [0-9]*'`
echo "$ccversion"
case "$ccversion" in
"clang version [0-3]")
echo "warning: this clang version does not work correctly on windows 32-bit."
echo " please upgrade to version 4.0.0 or higher!"
echo "";;
esac;;
esac
if sh ./searchpath "$ar"; then
echo "found archiver: $ar"
else
echo "warning: cannot find archiver: $ar"
if sh ./searchpath "ar"; then
echo " using default archiver 'ar' instead"
ar="ar"
else
echo "you can pass the archiver name using the --ar=<archiver> option."
fi
fi
# Configure compiler to use in further tests
ccomp=$cc
cclibs=""
ccout="$linkflagout"
export cc ccflags ccout cclibs verbose exe cxx cxxflags
# Check C compiler
sh ./runtest $ccflag99 c99.c
case $? in
0) echo "The C compiler is C99 compliant.";;
1) echo "The C compiler '$cc' is not C99 compliant."
echo "A C99 compliant compiler might be required to build (due to line-comments etc).";;
*) echo "Unable to compile the test program."
echo "Make sure the C compiler '$cc' is properly installed."
env verbose="yes" sh ./runtest $ccflag99 c99.c
exit 2;;
esac
# Check C++ compiler
sh ./runtest++ c++11.cpp
case $? in
0) echo "The C++ compiler is C++11 compliant.";;
1) echo "The C++ compiler '$cxx' is not C++11 compliant."
echo "A C++ 11 compliant compiler might be required to build.";;
*) echo "Unable to compile the test program."
echo "Make sure the C++ compiler '$cxx' is properly installed."
env verbose="yes" sh ./runtest++ c++11.cpp
exit 2;;
esac
# Set up cenv.h
echo "// Generated by 'configure': C environment constants" > cenv.h
echo "#define LH_TARGET \"$target\"" >> cenv.h
echo "#define LH_CCNAME \"$ccname\"" >> cenv.h
echo "#define LH_ABI_$target_abi" >> cenv.h
function has_function {
def="$1"
name="$2"
shift
shift
if sh ./hasgot $* $name; then
echo "Function $name: found"
echo "#define $def" >> cenv.h;
else
echo "Function $name: not found"
echo "// #define $def" >> cenv.h;
fi
};
has_function HAS_GMTIME_S gmtime_s -i time.h
has_function HAS__MKGMTIME _mkgmtime -i time.h
has_function HAS_TIMEGM timegm -i time.h
if sh ./hasgot -i stdio.h "sscanf_s"; then
echo "Function sscanf_s: found"
echo "#define HAS_SSCANF_S" >> cenv.h;
else
echo "Function sscanf_s: not found"
echo "// #define HAS_SSCANF_S" >> cenv.h;
fi
if sh ./hasgot -i alloca.h "alloca(10)"; then
echo "Function alloca: found"
echo "#define HAS_ALLOCA_H" >> cenv.h;
elif sh ./hasgot -i malloc.h "_alloca(10)"; then
echo "Function _alloca: found"
echo "#define HAS__ALLOCA" >> cenv.h;
else
echo "Cannot find stack allocation function 'alloca'!"
echo "// #define HAS_ALLOCA_H" >> cenv.h;
fi
function has_header {
def="$1"
header="$2"
shift
shift
if sh ./hasgot $* -i $header; then
echo "Header $header: found"
echo "#define $def" >> cenv.h;
else
echo "Header $header: not found"
echo "// #define $def" >> cenv.h;
fi
};
has_header HAS_STDBOOL_H stdbool.h
# Generate makefile
echo "# Generated by 'configure': Makefile variables" > makefile.inc
echo "CONFIG=$config" >> makefile.inc
echo "ABI=$target_abi" >> makefile.inc
echo "OSTYPE=$ostype" >> makefile.inc
echo >> makefile.inc
echo "CC=$cc" >> makefile.inc
echo "CCNAME=$ccname" >> makefile.inc
echo "CCFLAGSOPT=$ccflags $ccflag99 $ccflagopt" >> makefile.inc
echo "CCFLAGSDEBUG=$ccflags $ccflag99 $ccflagdebug" >> makefile.inc
echo "CCFLAGOUT=$ccflagout" >> makefile.inc
echo "CCFLAG99=$ccflag99" >> makefile.inc
echo "CCDEPEND=$ccdepend" >> makefile.inc
echo "ASMFILES=$asmfiles" >> makefile.inc
echo "ASMFLAGS=$asmflags" >> makefile.inc
echo "ASMFLAGOUT=$asmflagout" >> makefile.inc
echo "AR=$ar" >> makefile.inc
echo "ARFLAGS=$arflags" >> makefile.inc
echo "ARFLAGOUT=$arflagout" >> makefile.inc
echo "LINK=$link" >> makefile.inc
echo "LINKFLAGS=$linkflags" >> makefile.inc
echo "LINKFLAGOUT=$linkflagout" >> makefile.inc
echo "CXX=$cxx" >> makefile.inc
echo "CXXFLAGS=$cxxflags" >> makefile.inc
echo "CXXFLAGSOPT=$cxxflags $ccflagopt" >> makefile.inc
echo "CXXFLAGSDEBUG=$cxxflags $ccflagdebug" >> makefile.inc
echo >> makefile.inc
echo "EXE=$exe" >> makefile.inc
echo "DLL=$dll" >> makefile.inc
echo "OBJ=$obj" >> makefile.inc
echo "LIB=$lib" >> makefile.inc
echo "ASM=$asm" >> makefile.inc
echo "CP=cp" >> makefile.inc
echo "CD=cd" >> makefile.inc
echo "RM=rm -f" >> makefile.inc
echo "MKDIR=mkdir -p" >> makefile.inc
# clean up and go to root dir again
# rm -f tst$exe hasgot.c *$obj
cd ..
# initialize out directory
rm -rf "out/$config"
mkdir -p "out/$config"
echo "# run 'make depend' to generate dependencies" > out/$config/makefile.depend
mv config/cenv.h out/$config/cenv.h
mv config/makefile.inc out/$config/makefile.inc
echo "include out/$config/makefile.inc" > out/makefile.config
# Print a summary
echo
echo "--- Configuration summary ---"
echo "System:"
echo " target : $target_abi-$target_os"
echo "Build:"
echo " c compiler : $cc $ccflag99 $ccflags"
echo " c++ compiler: $cxx $cxxflags"
echo " assembler : $cc $asmflags"
echo " linker : $link $cclinkflags"
echo " archiver : $ar $arflags"
echo
echo "Use the following commands to build:"
echo "> make depend"
echo "> make"
echo
echo "To run examples:"
echo "> make examples"
echo
echo "Test release version:"
echo "> make examples VARIANT=release"
echo