-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathconfigure
executable file
·594 lines (501 loc) · 16.2 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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
#!/bin/sh -e
#
# Parse command-line options
#
usage () {
cat <<'USAGE'
Target options:
KXARCH=l32 q operating system name
KXVER=3 q major version
QHOME=$HOME/q installation directory
Compiler options:
CC=gcc C compiler
FC=gfortran Fortran compiler
CFLAGS=-O3 C compiler flags
FFLAGS= Fortran compiler flags
FLAGS=-march=native common flags for both compilers
TOOLPREFIX= prefix for ld, ar, ranlib, dlltool, nm binaries
e.g. x86_64-w64-mingw32-
XCC=gcc C compiler for build-time programs
e.g. Cygwin gcc when main compiler is MinGW gcc
BLAS options (needed for LAPACK):
--build-blas build Netlib BLAS (fast build)
--build-openblas build OpenBLAS with dynamic architecture
--build-openblas=native build OpenBLAS for specified architecture
(native, generic, sandybridge, etc.)
--with-blas=/path/to/libblas.a use system BLAS library
LAPACK options:
--build-lapack build Netlib LAPACK
--with-lapack=/path/to/liblapack.a use system LAPACK library
USAGE
}
unset CONFTEST KXARCH KXVER QHOME_CONFIG CC FC CFLAGS CFLAGS_FLOAT
unset FFLAGS FFLAGS_FLOAT FFLAGS_THREAD
unset FLAGS FLAGS_BITS FLAGS_WINDOWS FLAGS_PIC FLAGS_PIPE
unset TOOLPREFIX XCC CONFIG
unset LDFLAGS LDFLAGS_LIBGCC LD_EXPORT LD_STATIC LD_SHARED STRIP_FLAGS
unset LIBS_FORTRAN LIBS_BLAS LIBS_LAPACK
unset FETCH SHA256
unset BUILD_BLAS BUILD_OPENBLAS WITH_BLAS BUILD_LAPACK WITH_LAPACK
for arg in "$@"; do
case "$arg" in
KXARCH=*) KXARCH="${arg#*=}" ;;
KXVER=*) KXVER="${arg#*=}" ;;
CC=*) CC="${arg#*=}" ;;
FC=*) FC="${arg#*=}" ;;
CFLAGS=*) CFLAGS="${arg#*=}" ;;
FFLAGS=*) FFLAGS="${arg#*=}" ;;
FLAGS=*) FLAGS="${arg#*=}" ;;
TOOLPREFIX=*) TOOLPREFIX="${arg#*=}" ;;
XCC=*) XCC="${arg#*=}" ;;
--build-blas) BUILD_BLAS=1 ;;
--build-openblas) BUILD_OPENBLAS=dynamic ;;
--build-openblas=*) BUILD_OPENBLAS="${arg#*=}" ;;
--with-blas=*) WITH_BLAS="${arg#*=}" ;;
--build-lapack) BUILD_LAPACK=1 ;;
--with-lapack=*) WITH_LAPACK="${arg#*=}" ;;
-h|--help) usage; exit 0 ;;
*) echo "unknown configure option $1, try --help" >&2
exit 1 ;;
esac
done
#
# Determine q platform
#
quiet () {
$* </dev/null 2>/dev/null || :
}
echo_n () {
# echo -n is not portable
printf '%s' "$*"
}
echo_n "q operating system... "
if [ -n "$KXARCH" ]; then
echo "$KXARCH (selected)"
else
# q doesn't run interactively in Cygwin
echo '-1 string .z.o;' >conftest.q
KXARCH=`quiet q conftest.q | tail -n 1 | tr -d '\r'`
if [ -n "$KXARCH" ]; then
echo "$KXARCH (detected from q)"
else
case "$(quiet uname -s):$(quiet uname -m)" in
MINGW*|MSYS*|CYGWIN*)
case $PROCESSOR_ARCHITECTURE:$PROCESSOR_ARCHITEW6432 in
AMD64:*|*:AMD64) KXARCH=w64 ;;
*) KXARCH=w32 ;;
esac ;;
Linux:x86_64) KXARCH=l64 ;;
Linux:*) KXARCH=l32 ;;
Darwin:x86_64) KXARCH=m64 ;;
Darwin:*) KXARCH=m32 ;;
SunOS:*)
case "$(quiet isainfo):$(quiet isainfo -b)" in
*i386*:64) KXARCH=v64 ;;
*i386*:32) KXARCH=v32 ;;
*:64) KXARCH=s64 ;;
*:32) KXARCH=s32 ;;
esac ;;
esac
if [ -n "$KXARCH" ]; then
echo "$KXARCH (detected from host)"
else
echo "unknown"
fi
fi
fi
case $KXARCH in
w32|w64|l32|l64|m32|m64|s32|s64|v32|v64) ;;
*) echo "unknown q operating system." >&2; exit 1 ;;
esac
echo_n "q version... "
if [ -n "$KXVER" ]; then
echo "$KXVER (selected)"
else
echo '-1 string floor .Q.k;' >conftest.q
KXVER=`quiet q conftest.q | tail -n 1 | tr -d '\r'`
if [ -n "$KXVER" ]; then
echo "$KXVER (detected from q)"
else
KXVER=3
echo "$KXVER (default)"
fi
fi
case $KXVER in
2|3) ;;
*) echo "unknown q version." >&2; exit 1 ;;
esac
echo_n "q home... "
if [ -n "${QHOME_CONFIG+n}" ]; then
echo "${QHOME_CONFIG:-none} (selected)"
else
# q may be a script that sets QHOME
echo '-1 getenv`QHOME;' >conftest.q
QHOME_CONFIG=`quiet q conftest.q | tail -n 1 | tr -d '\r'`
if [ -n "$QHOME_CONFIG" ]; then
echo "$QHOME_CONFIG (detected from q)"
else
if [ -z "${KXARCH##w*}" ]; then
QHOME_CONFIG=c:/q
else
QHOME_CONFIG=$HOME/q
fi
echo "$QHOME_CONFIG (default)"
fi
fi
#
# Find make
#
echo_n "looking for GNU make... "
while true; do
cat >conftest.mk <<'MAKEFILE'
ifeq "" ""
all:
endif
MAKEFILE
for MAKE in make gmake gnumake; do
$MAKE -f conftest.mk >conftest.out 2>conftest.err && break 2
done
echo "not found"
echo "GNU make is required." >&2
exit 1
done
echo $MAKE
#
# Test routines
#
makeenv () {
{ echo; echo "$1"; } >>conftest.out
{ echo; echo "$1"; } >>conftest.err
shift
$MAKE "$@" \
QML_CONFIGURE=1 \
CONFTEST="$CONFTEST" \
KXARCH="$KXARCH" \
KXVER="$KXVER" \
QHOME="$QHOME_CONFIG" \
CC="$CC" \
FC="$FC" \
CFLAGS="$CFLAGS $CFLAGS_FLOAT" \
FFLAGS="$FFLAGS $FFLAGS_FLOAT $FFLAGS_THREAD" \
FLAGS="$FLAGS $FLAGS_BITS $FLAGS_WINDOWS $FLAGS_PIC $FLAGS_PIPE" \
XAR="$XAR" \
TOOLPREFIX="$TOOLPREFIX" \
XCC="$XCC" \
CONFIG="$CONFIG" \
LDFLAGS="$LDFLAGS $LDFLAGS_LIBGCC" \
LD_EXPORT="$LD_EXPORT" \
LD_STATIC="$LD_STATIC" \
LD_SHARED="$LD_SHARED" \
STRIP_FLAGS="$STRIP_FLAGS" \
LIBS_FORTRAN="$LIBS_FORTRAN" \
LIBS_BLAS="$LIBS_BLAS" \
LIBS_LAPACK="$LIBS_LAPACK" \
FETCH="$FETCH" \
SHA256="$SHA256" \
>>conftest.out 2>>conftest.err
}
makeyesno () {
echo_n "$1 "
if makeenv "testing $3:" -f mk/test.mk test/$3; then
echo yes
else
echo no
echo "$2" >&2; exit 1
fi
}
makeselect () {
echo_n "$1${1:+ }"; fail=$2; var=$3; test=$4; shift 4
while [ $# != 0 ]; do
eval $var=\$1
if makeenv "testing $test with $var='$1':" -f mk/test.mk test/"$test"
then
if [ -n "$1" ]; then
echo $1
else
echo none
fi
break
fi
shift
done
if [ $# = 0 ]; then
echo "not found"
echo "$fail" >&2
exit 1
fi
}
#
# Configure compilers
#
echo_n "looking for C compiler... "
CC_selected=$CC
if [ -n "$CC" ]; then
echo "$CC (selected)"
elif [ -z "${KXARCH##w*}" ]; then
# Since gcc 4, a separate MinGW compiler is used to produce native binaries
# $CC_choices also used below
if [ -z "${KXARCH#?32}" ]; then
CC_choices='i686-pc-mingw32-gcc i686-w64-mingw32-gcc'
else
CC_choices=x86_64-w64-mingw32-gcc
fi
makeselect "" \
"a compiler is required" \
CC c_version \
$CC_choices gcc
CC_selected=$CC
else
CC=gcc
echo "$CC (default)"
fi
makeyesno "checking if C compiler compiles..." \
"a working compiler is required." \
c_compile
makeyesno "checking if C compiler links..." \
"a working compiler is required." \
c_link
if [ -z "${CFLAGS+n}" ]; then
makeselect "selecting C optimization options..." "" \
CFLAGS c_link \
"-O2 -fno-strict-aliasing" ""
fi
makeselect "selecting C floating-point options..." \
"-ffloat-store is assumed by some libraries." \
CFLAGS_FLOAT c_link \
-ffloat-store
echo_n "looking for C compiler for build-time programs... "
if [ -n "$XCC" ]; then
echo "$XCC (selected)"
elif [ -z "${KXARCH##w*}" ]; then
# Needs to be POSIX-compliant, so use Cygwin gcc by preference
makeselect "" \
"a compiler is required." \
XCC xc_version \
gcc $CC_choices "$CC"
else
XCC=$CC
echo "$XCC (default)"
fi
makeyesno "checking if build-time C compiler compiles..." \
"a working compiler is required." \
xc_compile
makeyesno "checking if build-time C compiler links..." \
"a working compiler is required." \
xc_link
makeyesno "checking if build-time C compiler output runs..." \
"a working compiler is required." \
xc_run
echo_n "looking for Fortran compiler... "
if [ -n "$FC" ]; then
echo "$FC (selected)"
elif [ -n "$CC_selected" ] && [ -z "${CC_selected%%*gcc*}" ]; then
makeselect "" \
"a compiler is required." \
FC f_version \
"${CC_selected%gcc*}gfortran${CC_selected##*gcc}" \
gfortran
else
FC=gfortran
echo "$FC (default)"
fi
makeyesno "checking if Fortran compiler compiles..." \
"a working compiler is required." \
f_compile
makeyesno "checking if Fortran compiler links..." \
"a working compiler is required." \
f_link
if [ -z "${FFLAGS+n}" ]; then
makeselect "selecting Fortran optimization options..." "" \
FFLAGS f_link \
-O2 ""
fi
makeselect "selecting Fortran floating-point options..." \
"-ffloat-store is assumed by some libraries." \
FFLAGS_FLOAT f_link \
-ffloat-store
makeselect "selecting Fortran thread safety options..." \
"-frecursive is necessary for thread-safety." \
FFLAGS_THREAD f_link \
-frecursive -fmax-stack-var-size=2000000000
# nm required below
echo_n "looking for binutils... "
if [ -n "${TOOLPREFIX+n}" ]; then
echo "${TOOLPREFIX}ar (selected)"
elif [ -n "$CC_selected" ] && [ -z "${CC_selected%%*-gcc*}" ]; then
# Cygwin installs x86_64-w64-mingw32-ar but plain MinGW-w64 doesn't,
# though it has an appropriate ar in the same directory.
makeselect "" \
"binutils are required." \
XAR xar_version \
"${CC_selected%gcc*}ar" \
"$(dirname "$(which "$CC_selected")")/ar" \
ar
TOOLPREFIX=${XAR%ar}
else
echo "${TOOLPREFIX}ar (default)"
fi
makeselect "selecting target options..." \
"-m${KXARCH#?} is necessary, try a different compiler." \
FLAGS_BITS c_and_f_link \
-m${KXARCH#?}
if [ -z "${KXARCH##w*}" ]; then
# Cygwin binaries (using cygwin1.dll) don't work; we need native binaries
makeselect "selecting Windows options..." \
"-mno-cygwin or MinGW compiler required." \
FLAGS_WINDOWS no_cygwin \
'' -mno-cygwin
fi
makeselect "selecting additional compiler options..." "" \
FLAGS_PIPE c_and_f_link \
-pipe ""
if [ -z "${KXARCH##w*}" ]; then
makeyesno "checking if dlltool works..." \
"a working dlltool is required" \
dlltool
fi
# May compile successfully without -fPIC but then hang when calling back into q,
# so use -fPIC by default. Sometimes -shared link is impossible without -fPIC.
CONFTEST=shared
makeselect "selecting shared library options..." \
"couldn't create shared library." \
FLAGS_PIC c_compile \
-fPIC ""
case $KXARCH in
m*) set -- "-bundle -undefined dynamic_lookup" ;;
*) set -- -shared ;;
esac
makeselect "selecting how to link a shared library..." \
"couldn't create a shared library." \
LD_SHARED shared_link \
"$@"
if [ -z "${KXARCH##w*}" ]; then
# Avoid editing PATH to point to MinGW DLLs by linking statically.
# Could detect whether this is really needed, but then the portability of
# the resulting binary would be less predictable.
makeselect "selecting Windows DLL options..." \
"couldn't create Windows DLL." \
LDFLAGS_LIBGCC shared_link \
-static-libgcc ""
fi
makeselect "selecting how to export specific symbols..." \
"couldn't export specific symbols." \
LD_EXPORT ld_export \
-Wl,--version-script -Wl,-M -exported_symbols_list
makeselect "selecting strip options..." \
"couldn't strip shared library." \
STRIP_FLAGS strip \
-s "" -S
# -fPIC required for this
# Don't want to depend on MinGW libgfortran.dll, so link statically
CONFTEST=libm
makeselect "selecting how to link a specific library statically..." "" \
LD_STATIC ld_static \
-Wl,-Bstatic ""
CONFTEST=builtin
# When linking gfortran object files with clang need to explicitly add default
# gfortran library directories.
dirs=
for lib in gfortran gfortranbegin; do
dir=`dirname "$(quiet "$FC" $FLAGS_BITS -print-file-name=lib${lib}.a)"`
if [ -n "${dir%.}" ]; then
dirs="$dirs -L$dir"
fi
done
set -- -lgfortran
for i; do set -- "$@" "-lgfortanbegin $i"; done
for i; do set -- "$@" "$i -lquadmath"; done
for i; do set -- "$@" "$dirs $i"; done
makeselect "selecting additional libraries for Fortran..." \
"couldn't link C and Fortran code together." \
LIBS_FORTRAN f_compile_c_link \
"" "$@"
CONFTEST=stack_local
makeyesno "checking if Fortran locals are placed on stack..." \
"would not be thread-safe." \
stack_local
# Libraries
CONFTEST=blas
if [ -n "$BUILD_BLAS" ] && [ -n "$BUILD_OPENBLAS" ]; then
echo "choose either --build-blas or --build-openblas" >&2
exit 1
elif [ -n "$BUILD_BLAS" ]; then
echo "will build BLAS"
BUILD_LAPACK=1
elif [ -n "$BUILD_OPENBLAS" ]; then
echo "will build OpenBLAS for $BUILD_OPENBLAS architecture"
BUILD_LAPACK=1
elif [ -n "${WITH_BLAS+n}" ]; then
LIBS_BLAS=$WITH_BLAS
makeyesno "checking if BLAS works..." \
"BLAS is required, use --build-blas or different --with-blas" \
c_link
else
makeselect "looking for BLAS..." \
"BLAS is required, use --build-blas or --with-blas" \
LIBS_BLAS c_link \
"" -lblas
fi
CONFTEST=lapack
if [ -n "$BUILD_LAPACK" ]; then
echo "will build LAPACK"
elif [ -n "${WITH_LAPACK+n}" ]; then
LIBS_LAPACK=$WITH_LAPACK
makeyesno "checking if LAPACK works..." \
"LAPACK is required, use --build-lapack or different --with-lapack" \
c_link
else
makeselect "looking for LAPACK..." \
"LAPACK is required, use --build-lapack or --with-lapack" \
LIBS_LAPACK c_link \
"" -llapack
fi
# Utilities
makeyesno "checking if patch program works..." \
"patch program is required." \
patch
makeselect "looking for http downloader..." \
"http downloader is required." \
FETCH fetch \
curl wget manual
echo_n "phoning home... "
echo "just kidding"
makeselect "looking for sha256 program..." \
"sha256 program is required." \
SHA256 sha256 \
sha256 sha256sum shasum openssl
#
# Done
#
echo 'writing configuration to config.mk'
sed 's/\$/$$/g' >config.mk <<MAKEFILE
KXARCH := $KXARCH
KXVER := $KXVER
QHOME := $QHOME_CONFIG
CC := $CC
FC := $FC
CFLAGS := $CFLAGS $CFLAGS_FLOAT
FFLAGS := $FFLAGS $FFLAGS_FLOAT $FFLAGS_THREAD
FFLAGS_NTHREAD := $FFLAGS $FFLAGS_FLOAT
FLAGS := $FLAGS $FLAGS_BITS $FLAGS_WINDOWS $FLAGS_PIC $FLAGS_PIPE
XAR := $XAR
TOOLPREFIX := $TOOLPREFIX
XCC := $XCC
CONFIG := $CONFIG
LDFLAGS := $LDFLAGS $LDFLAGS_LIBGCC
LD_EXPORT := $LD_EXPORT
LD_STATIC := $LD_STATIC
LD_SHARED := $LD_SHARED
STRIP_FLAGS := $STRIP_FLAGS
LIBS_FORTRAN := $LIBS_FORTRAN
LIBS_BLAS := $LIBS_BLAS
BUILD_BLAS := $BUILD_BLAS
BUILD_OPENBLAS := $BUILD_OPENBLAS
LIBS_LAPACK := $LIBS_LAPACK
BUILD_LAPACK := $BUILD_LAPACK
FETCH := $FETCH
SHA256 := $SHA256
PATCH := $PATCH
MAKEFILE
echo "now run $MAKE"
$MAKE -f mk/test.mk clean >/dev/null 2>/dev/null