-
Notifications
You must be signed in to change notification settings - Fork 20
/
configure
executable file
·668 lines (609 loc) · 13 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
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
#!/bin/sh
# Copyright (c) 2016-2018, Carsten Kunze <[email protected]>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
usage () {
echo "Usage: $0 [-s]"
echo " -s Silence output"
exit $1
}
SRCDIR=$(dirname $0)
SFLAG=
MAKE=
DEFS=
LIB_LEX=
LIB_CURSES=
cat /dev/null > compat.h
while [ $# -gt 0 ]; do
case $1 in
-s) SFLAG=1;;
*)
echo "$0: $1: Unknown option" >&2
usage 1;;
esac
shift
done
check_for () {
[ -e $LOG ] && cat <<EOT >>$LOG
================================================================================
EOT
A="Checking for $1 ... "
printf "$A\n\n" >>$LOG
[ -z "$SFLAG" ] && printf "$A"
}
compile () {
rm -f ${TMPNAM}.o $TMPNAM $OUT $ERR
$MAKE -f $OUTMK $TMPNAM > $OUT 2> $ERR
RESULT=$?
cat $OUT $ERR >> $LOG
if [ $RESULT -eq 0 ]; then true; else false; fi
}
test_result () {
RESULT=$?
RESULT_TEXT=${1:-0} # 1: omit "no", 2: say nothing
if [ $RESULT -eq 0 ]; then
echo success >>$LOG
[ -z "$SFLAG" -a $RESULT_TEXT -lt 2 ] && \
echo "yes$PASS_TEXT"
PASS_TEXT=
[ -e $TMPC ] && rm -f $TMPC
true
else
[ -z "$SFLAG" -a $RESULT_TEXT -lt 1 ] && echo no
if [ -e $TMPC ]; then
echo "Failed program:" >>$LOG
pr -n -t $TMPC >>$LOG
rm -f $TMPC
fi
false
fi
}
gen_mk () {
[ $# -eq 0 ] && rm -f $OUTMK
[ -n "$LEX" ] && echo "LEX=$LEX" >> $OUTMK
[ -n "$FLOAT_STORE" ] && echo "FLOAT_STORE=$FLOAT_STORE" >> $OUTMK
[ -n "$DEFS" ] && echo "DEFINES=$DEFS" >> $OUTMK
[ -n "$INCDIR_CURSES" ] && echo "INCDIR_CURSES=$INCDIR_CURSES" >> $OUTMK
[ -n "$RPATH_CURSES" ] && echo "RPATH_CURSES=$RPATH_CURSES" >> $OUTMK
[ -n "$LIBDIR_CURSES" ] && echo "LIBDIR_CURSES=$LIBDIR_CURSES" \
>> $OUTMK
[ -n "$LIB_CURSES" ] && echo "LIB_CURSES=$LIB_CURSES" >> $OUTMK
[ -n "$LIB_AVLBST" ] && echo "LIB_AVLBST=$LIB_AVLBST" >> $OUTMK
[ -n "$LIB_LEX" ] && echo "LIB_LEX=$LIB_LEX" >> $OUTMK
[ -n "$__CDBG" ] && echo "__CDBG=$__CDBG" >> $OUTMK
[ -n "$__CXXDBG" ] && echo "__CXXDBG=$__CXXDBG" >> $OUTMK
[ -n "$__CLDBG" ] && echo "__CLDBG=$__CLDBG" >> $OUTMK
[ -n "$__CLXXDBG" ] && echo "__CLXXDBG=$__CLXXDBG" >> $OUTMK
sed -e /SRCDIR=\$/s:\$:$SRCDIR: $INMK >> $OUTMK || exit 1
}
check_make () {
check_for "make(1)"
cat <<EOT >$TMPMK
all:
true
EOT
make -f $TMPMK >> $LOG 2>&1
test_result && {
MAKE=make
return
}
echo "Failed makefile:" >>$LOG
pr -n -t $TMPMK >>$LOG
check_for "bmake(1)"
cat <<EOT >$TMPMK
all:
true
EOT
bmake -f $TMPMK >> $LOG 2>&1
test_result && MAKE=bmake
}
check_make_vpath () {
check_for "make supports VPATH"
mkdir subdir
> subdir/subfile.c
cat <<EOT > $TMPMK
VPATH=subdir
all: subfile.c
@echo $<;test "$<" = subdir/subfile.c
EOT
$MAKE -f $TMPMK >> $LOG 2>&1
test_result && SUPPORTS_VPATH=1
rm -rf subdir
}
check_Sanitizer () {
check_for "CC Sanitizer"
# C only
__CDBG=
__CLDBG=
__CCXXDBG=
# C++ only
__CXXDBG=
__CLXXDBG=
__CDBG="$__CDBG -Wmissing-prototypes"
__CDBG="$__CDBG -Wstrict-prototypes"
__CCXXDBG="$__CCXXDBG -g -O0 -fno-omit-frame-pointer -fno-optimize-sibling-calls"
__CCXXDBG="$__CCXXDBG -Wall"
__CCXXDBG="$__CCXXDBG -Wextra"
__CCXXDBG="$__CCXXDBG -Wsign-compare"
__CCXXDBG="$__CCXXDBG -Wcast-align"
__CCXXDBG="$__CCXXDBG -Wcast-qual"
__CCXXDBG="$__CCXXDBG -Wunused-parameter"
__CCXXDBG="$__CCXXDBG -Wunused-function"
__CCXXDBG="$__CCXXDBG -Wshadow"
__CCXXDBG="$__CCXXDBG -Wwrite-strings"
__CLXXDBG="$__CLXXDBG -fno-common -fsanitize=address -fsanitize=undefined"
#__CLXXDBG="$__CLXXDBG -fsanitize-recover=all"
[ -n "$CC" ] || CC=cc
VER=`$CC --version`
if echo $VER | grep -iq gcc || echo $VER | \
grep -iq 'Free Software Foundation'; then
[ -z "$SFLAG" ] && printf "(gcc) "
#__CLXXDBG="$__CLXXDBG -fprofile-arcs -ftest-coverage"
__CLXXDBG="$__CLXXDBG -fsanitize=float-divide-by-zero"
__CLXXDBG="$__CLXXDBG -fsanitize=float-cast-overflow"
elif echo $VER | grep -q clang; then
[ -z "$SFLAG" ] && printf "(clang) "
__CCXXDBG="$__CCXXDBG -Wincompatible-pointer-types-discards-qualifiers"
__CCXXDBG="$__CCXXDBG -Wmissing-variable-declarations"
__CXXDBG="$__CXXDBG -Wunused-private-field"
__CLXXDBG="$__CLXXDBG -fsanitize=unsigned-integer-overflow"
else
[ -z "$SFLAG" ] && echo "Unknown compiler"
return
fi
# Most C++ options can be used for C too
__CDBG="$__CDBG $__CCXXDBG"
__CLDBG="$__CLDBG $__CLXXDBG"
__CXXDBG="$__CXXDBG $__CCXXDBG"
cat <<EOT >$TMPC
int
main() {
return 0;
}
EOT
gen_mk
cat <<EOT >>$OUTMK
$TMPNAM: ${TMPNAM}.o
\$(CC) \$(__CDBG) \$(__CLDBG) -o \$@ ${TMPNAM}.o
EOT
compile
test_result || {
__CLDBG=
__CLXXDBG=
}
}
check_float_store () {
FLOAT_STORE=-ffloat-store
check_for "$FLOAT_STORE"
cat <<EOT >$TMPC
int
main() {
return 0;
}
EOT
gen_mk
cat <<EOT >>$OUTMK
${TMPNAM}.o:
\$(CC) $FLOAT_STORE -c $TMPC
EOT
rm -f ${TMPNAM}.o
$MAKE -f $OUTMK ${TMPNAM}.o >> $LOG 2> $TMPNAM
cat $TMPNAM >> $LOG
if [ -s $TMPNAM ]; then
if grep -e $FLOAT_STORE $TMPNAM | grep -q 'not supported'
then
false
elif grep -e $FLOAT_STORE $TMPNAM | grep -q 'argument unused'
then
false
else
true
fi
else
true
fi
test_result || FLOAT_STORE=
}
check_strlcpy () {
check_for "strlcpy(3)"
cat <<EOT >$TMPC
#include <string.h>
int
main(int argc, char **argv) {
char a[10];
(void)argc;
strlcpy(a, *argv, sizeof a);
return 0;
}
EOT
compile
if test_result; then
DEFS="$DEFS -DHAVE_STRLCPY"
else
H=compat.h
grep -q '<sys/types\.h>' $H 2>/dev/null || cat <<EOT >>$H
#include <sys/types.h>
EOT
cat <<EOT >>$H
size_t strlcpy(char *, const char *, size_t);
EOT
fi
}
check_strlcat () {
check_for "strlcat(3)"
cat <<EOT >$TMPC
#include <string.h>
int
main(int argc, char **argv) {
char a[10];
(void)argc;
*a = 0;
strlcat(a, *argv, sizeof a);
return 0;
}
EOT
compile
if test_result; then
DEFS="$DEFS -DHAVE_STRLCAT"
else
H=compat.h
grep -q '<sys/types\.h>' $H 2>/dev/null || cat <<EOT >>$H
#include <sys/types.h>
EOT
cat <<EOT >>$H
size_t strlcat(char *, const char *, size_t);
EOT
fi
}
check_fixterm () {
check_for 'fixterm(3)'
cat <<EOT >$TMPC
#include "compat.h"
int
main() {
fixterm();
return 0;
}
EOT
gen_mk
cat <<EOT >>$OUTMK
$TMPNAM: ${TMPNAM}.o
\$(CC) \$(_CFLAGS) \$(_LDFLAGS) \$(RPATH_CURSES) -o \$@ ${TMPNAM}.o \$(LDADD)
EOT
compile
test_result && DEFS="$DEFS -DHAVE_FIXTERM"
}
check_resetterm () {
check_for 'resetterm(3)'
cat <<EOT >$TMPC
#include "compat.h"
int
main() {
resetterm();
return 0;
}
EOT
gen_mk
cat <<EOT >>$OUTMK
$TMPNAM: ${TMPNAM}.o
\$(CC) \$(_CFLAGS) \$(_LDFLAGS) \$(RPATH_CURSES) -o \$@ ${TMPNAM}.o \$(LDADD)
EOT
compile
test_result && DEFS="$DEFS -DHAVE_RESETTERM"
}
compile_curses () {
cat <<EOT >$TMPC
#include "compat.h"
int
main() {
return 0;
}
EOT
gen_mk
cat <<EOT >>$OUTMK
$TMPNAM: ${TMPNAM}.o
\$(CC) \$(_CFLAGS) \$(_LDFLAGS) \$(RPATH_CURSES) -o \$@ ${TMPNAM}.o \$(LDADD)
EOT
compile
test_result 1
}
test_curses () {
compile_curses && return
[ $# -gt 0 ] && for i in $*; do
compile_curses $i && return
done
}
check_ncursesw () {
LIB_CURSES="-lncursesw"
check_for $LIB_CURSES
ODEFS=$DEFS
# At first test for specific ncursesw.h to not used -lncursesw with
# traditional curses.h if both curses systems are installed.
DEFS="$DEFS -DHAVE_NCURSESW_CURSES_H"
INCDIR_CURSES="-I/usr/include/ncurses6"
RPATH_CURSES="-Wl,-rpath,/usr/lib64/ncurses6"
LIBDIR_CURSES="-L/usr/lib64/ncurses6"
PASS_TEXT=" (#include <ncursesw/curses.h>, -I/usr/include/ncurses6, \
-L/usr/lib64/ncurses6)"
test_curses && return # Linux NC6
INCDIR_CURSES=
RPATH_CURSES=
LIBDIR_CURSES=
PASS_TEXT=" (#include <ncursesw/curses.h>)"
test_curses && return # Linux
INCDIR_CURSES="-I/usr/pkg/include"
RPATH_CURSES="-Wl,-rpath,/usr/pkg/lib"
LIBDIR_CURSES="-L/usr/pkg/lib"
PASS_TEXT=" (#include <ncursesw/curses.h>, -I/usr/pkg/include, \
-L/usr/pkg/lib)"
test_curses && return # NetBSD
DEFS=$ODEFS
INCDIR_CURSES=
RPATH_CURSES=
LIBDIR_CURSES=
PASS_TEXT=
test_curses && return # OpenBSD, FreeBSD
[ -z "$SFLAG" ] && echo no
false
}
check_ncurses () {
LIB_CURSES="-lncurses"
check_for $LIB_CURSES
ODEFS=$DEFS
DEFS="$DEFS -DHAVE_NCURSES_CURSES_H"
PASS_TEXT=" (#include <ncurses/curses.h>)"
test_curses && return # OpenIndiana
DEFS="$DEFS -DHAVE_NCURSES_CURSES_H"
INCDIR_CURSES="-I/usr/pkg/include"
RPATH_CURSES="-Wl,-rpath,/usr/pkg/lib"
LIBDIR_CURSES="-L/usr/pkg/lib"
PASS_TEXT=" (#include <ncurses/curses.h>, -I/usr/pkg/include, \
-L/usr/pkg/lib)"
test_curses && return # NetBSD
DEFS=$ODEFS
INCDIR_CURSES=
RPATH_CURSES=
LIBDIR_CURSES=
PASS_TEXT=
test_curses && return
[ -z "$SFLAG" ] && echo no
false
}
check_curses () {
LIB_CURSES="-lcurses"
check_for $LIB_CURSES
test_curses || {
[ -z "$SFLAG" ] && echo no
false
return
}
check_for attr_t
cat <<EOT >$TMPC
#include "compat.h"
int
main(int argc, char **argv) {
(void)argv;
attr_t c = argc + '0';
return (int)c;
}
EOT
compile
test_result && DEFS="$DEFS -DHAVE_ATTR_T"
check_for 'attr_get(3)'
cat <<EOT >$TMPC
#include "compat.h"
int
main() {
return attr_get(NULL, NULL, NULL);
}
EOT
gen_mk
cat <<EOT >>$OUTMK
$TMPNAM: ${TMPNAM}.o
\$(CC) \$(_CFLAGS) -o \$@ ${TMPNAM}.o \$(LDADD)
EOT
compile
test_result && DEFS="$DEFS -DHAVE_ATTR_GET"
check_fixterm
check_resetterm
true
}
curses_mk_compat_h () {
cat <<EOT >>compat.h
#ifndef _XOPEN_SOURCE_EXTENDED
# define _XOPEN_SOURCE_EXTENDED
#endif
#if defined(HAVE_NCURSESW_CURSES_H)
# include <ncursesw/curses.h>
#elif defined(HAVE_NCURSES_CURSES_H)
# include <ncurses/curses.h>
#else
# include <curses.h>
# ifndef false
# define false 0
# endif
# ifndef true
# define true 1
# endif
#endif
EOT
}
check_lib_curses () {
curses_mk_compat_h
DEFS0=$DEFS
DEFS="$DEFS -DHAVE_ATTR_T -DHAVE_ATTR_GET -DHAVE_FIXTERM \
-DHAVE_RESETTERM"
check_ncursesw && return
check_ncurses && return
DEFS=$DEFS0
check_curses && return
}
check_netbsd_curses () {
curses_mk_compat_h
[ `uname` = "NetBSD" ] && check_curses && return
DEFS0=$DEFS
DEFS="$DEFS -DHAVE_ATTR_T -DHAVE_ATTR_GET -DHAVE_FIXTERM \
-DHAVE_RESETTERM"
check_ncursesw && return
check_ncurses && return
DEFS=$DEFS0
check_curses && return
}
check_curses_wch () {
check_for "wins_wch(3)"
cat <<EOT >$TMPC
#include "compat.h"
int
main() {
cchar_t c;
wins_wch(stdscr, &c);
return 0;
}
EOT
gen_mk
cat <<EOT >>$OUTMK
$TMPNAM: ${TMPNAM}.o
\$(CC) \$(_CFLAGS) \$(_LDFLAGS) \$(RPATH_CURSES) -o \$@ ${TMPNAM}.o \$(LDADD)
EOT
compile
test_result || return;
DEFS="$DEFS -DHAVE_CURSES_WCH"
}
check_curses_keyname () {
check_for "keyname(3)"
cat <<EOT >$TMPC
#include "compat.h"
int
main(int argc, char **argv) {
(void)argv;
puts(keyname(argc));
return 0;
}
EOT
gen_mk
cat <<EOT >>$OUTMK
$TMPNAM: ${TMPNAM}.o
\$(CC) \$(_CFLAGS) \$(_LDFLAGS) \$(RPATH_CURSES) -o \$@ ${TMPNAM}.o \$(LDADD)
EOT
compile
test_result || return;
DEFS="$DEFS -DHAVE_CURSES_KEYNAME"
}
check_isfinite () {
check_for "isfinite(3)"
cat <<EOT >$TMPC
#include <math.h>
int
main(int argc, char **argv) {
(void)argv;
return isfinite((double)argc);
}
EOT
compile
test_result && {
DEFS="$DEFS -DHAVE_ISFINITE"
return
}
check_for "finite(3)"
cat <<EOT >$TMPC
#include <math.h>
int
main(int argc, char **argv) {
(void)argv;
return finite((double)argc);
}
EOT
compile
test_result 2 && {
[ -s $ERR ] ||
grep -iq implicite $ERR ||
grep -iq warning $ERR || {
[ -z "$SFLAG" ] && echo yes
return
}
}
cat <<EOT >$TMPC
#include <math.h>
#include <ieeefp.h>
int
main(int argc, char **argv) {
(void)argv;
return finite(argc);
}
EOT
PASS_TEXT=" (#include <ieeefp.h>)"
compile
test_result && DEFS="$DEFS -DUSE_IEEEFP_H"
PASS_TEXT=
}
check_sc_attr_get () {
check_for "sc(1) attr_get(3)"
cat <<EOT >$TMPC
#include <limits.h>
#include "compat.h"
#include "sc.h"
int
main() {
attr_get(NULL, NULL, NULL);
return 0;
}
EOT
gen_mk
cat <<EOT >>$OUTMK
$TMPNAM: ${TMPNAM}.o
\$(CC) \$(_CFLAGS) -o \$@ ${TMPNAM}.o \$(LDADD)
EOT
compile
test_result || DEFS="$DEFS -DNO_ATTR_GET"
}
check_stdbool_h () {
check_for "<stdbool.h>"
cat <<EOT >$TMPC
#include <stdbool.h>
int
main() {
return 0;
}
EOT
compile
test_result && DEFS="$DEFS -DHAVE_STDBOOL_H"
}
[ ! -s compat.h ] && rm compat.h
OUTMK=Makefile
INMK=${SRCDIR}/${OUTMK}.in
CFG=config
TMPNAM=.$CFG
TMPMK=${TMPNAM}.mk
TMPC=${TMPNAM}.c
OUT=${TMPNAM}.out
ERR=${TMPNAM}.err
LOG=${CFG}.log
SUPPORTS_VPATH=0
rm -f $LOG
gen_mk
check_make
check_make_vpath
test $SUPPORTS_VPATH = 1 && INMK=${SRCDIR}/${OUTMK}.in.vpath
#check_Sanitizer
check_float_store
check_strlcpy
check_strlcat
check_lib_curses
check_curses_wch
check_curses_keyname
check_isfinite
check_sc_attr_get
check_stdbool_h
gen_mk
rm -f $TMPNAM*
echo "#define _COMPAT_H" >>compat.h