-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfigure
executable file
·335 lines (304 loc) · 7.28 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
#!/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] [-D<define> ...]"
echo " -s Silence output"
echo " -D<define>"
echo " Add define to CFLAGS"
exit $1
}
SFLAG=
MAKE=
DEFS=
LIB_LEX=
LIB_CURSES=
cat /dev/null > compat.h
while [ $# -gt 0 ]; do
case $1 in
-s)
SFLAG=1
;;
-D*)
DEFS="$DEFS $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
cat $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_major_minor_sysmacros () {
check_for "major(3), minor(3) using <sys/sysmacros.h>"
cat <<EOT >$TMPC
#include <sys/sysmacros.h>
int
main() {
(void)major(0);
(void)minor(0);
return 0;
}
EOT
gen_mk
compile
test_result
}
check_major_minor_types () {
check_for "major(3), minor(3)"
cat <<EOT >$TMPC
#include <sys/types.h>
int
main() {
(void)major(0);
(void)minor(0);
return 0;
}
EOT
gen_mk
compile
test_result
}
check_major_minor_mkdev () {
check_for "major(3), minor(3) using <sys/mkdev.h>"
cat <<EOT >$TMPC
#include <sys/types.h>
#include <sys/mkdev.h>
int
main() {
(void)major(0);
(void)minor(0);
return 0;
}
EOT
gen_mk
compile
test_result
}
check_major_minor () {
check_major_minor_sysmacros && {
DEFS="$DEFS -DUSE_SYS_SYSMACROS_H"
return
}
check_major_minor_types && return
check_major_minor_mkdev && {
DEFS="$DEFS -DUSE_SYS_MKDEV_H"
}
}
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 -Wbad-function-cast"
__CCXXDBG="$__CCXXDBG -Wcast-align"
__CCXXDBG="$__CCXXDBG -Wcast-qual"
#__CCXXDBG="$__CCXXDBG -Wconversion"
__CCXXDBG="$__CCXXDBG -Wfloat-equal"
__CCXXDBG="$__CCXXDBG -Wlogical-not-parentheses"
__CCXXDBG="$__CCXXDBG -Wshadow"
__CCXXDBG="$__CCXXDBG -Wsign-compare"
__CCXXDBG="$__CCXXDBG -Wundef"
__CCXXDBG="$__CCXXDBG -Wuninitialized"
__CCXXDBG="$__CCXXDBG -Wunused-parameter"
__CCXXDBG="$__CCXXDBG -Wunused-function"
__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) "
__CCXXDBG="$__CCXXDBG -Wduplicated-branches"
__CCXXDBG="$__CCXXDBG -Wduplicated-cond"
__CCXXDBG="$__CCXXDBG -Wjump-misses-init"
__CCXXDBG="$__CCXXDBG -Wlogical-op"
#__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=
}
}
[ ! -s compat.h ] && rm compat.h
OUTMK=Makefile
INMK=${OUTMK}.in
CFG=config
TMPNAM=.$CFG
TMPMK=${TMPNAM}.mk
TMPC=${TMPNAM}.c
TMPL=${TMPNAM}.l # For lex tests only ...
OUT=${TMPNAM}.out
ERR=${TMPNAM}.err
LOG=${CFG}.log
rm -f $LOG
gen_mk
check_make
check_major_minor
#check_Sanitizer
TermTest () {
check_for "$1"
Term="$1"
echo "TERMLIB=$1" > $OUTMK
gen_mk 1
cat <<EOT >>$OUTMK
$TMPNAM: ${TMPNAM}.o
\$(CC) \$(_LDFLAGS) -o \$@ ${TMPNAM}.o \$(TERMLIB)
EOT
cat <<EOT >>$TMPC
int tgetent(char *, const char *);
int main() {
char tcbuf[1024];
char *terms[] = { "xterm", "screen" };
unsigned i;
for (i = 0; i < sizeof(terms)/sizeof(*terms); i++)
if (tgetent(tcbuf, terms[i]) != 1) {
return i + 1;
}
return 0;
}
EOT
compile
test_result 2 && ./$TMPNAM 2>> $LOG && {
echo yes
return
}
echo no
false
}
TestLocalTermlib () {
TermTest "-ltinfo" && return
TermTest "-lncurses" && return
ODEFS=$DEFS
D="-I/usr/pkg/include -L/usr/pkg/lib -Wl,-rpath,/usr/pkg/lib"
DEFS="$DEFS $D"
TermTest "-lncurses $D" && return
DEFS=$ODEFS
TermTest "-lcurses" && return
}
TestLocalTermlib
echo "TERMLIB=$Term" > $OUTMK
gen_mk 1
rm -f $TMPNAM*