-
Notifications
You must be signed in to change notification settings - Fork 5
/
configure
executable file
·638 lines (591 loc) · 14.7 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
#!/bin/sh
# Try and be like autotools configure, but without autotools
echo "configure args: $*"
exec 3>config.log
# Ensure that we do not inherit these from env
OS=
BUILD=
HOST=
HOSTCC=
TARGET=
: ${PREFIX=/usr}
INCLUDEDIR=
DEBUG=
POLL=
for x do
opt=${x%%=*}
var=${x#*=}
case "$opt" in
--os|OS) OS=$var;;
--debug) DEBUG=$var;;
--disable-debug) DEBUG=no;;
--enable-debug) DEBUG=yes;;
--prefix) PREFIX=$var;;
--sysconfdir) SYSCONFDIR=$var;;
--bindir|--sbindir) SBINDIR=$var;;
--libexecdir) LIBEXECDIR=$var;;
--statedir|--localstatedir) STATEDIR=$var;;
--dbdir) DBDIR=$var;;
--rundir|--runstatedir) RUNDIR=$var;;
--mandir) MANDIR=$var;;
--datadir) DATADIR=$var;;
--with-ccopts|CFLAGS) CFLAGS=$var;;
-I|--includedir) INCLUDEDIR="$INCLUDEDIR${INCLUDEDIR:+ }-I$var";;
CC) CC=$var;;
CPPFLAGS) CPPFLAGS=$var;;
PKG_CONFIG) PKG_CONFIG=$var;;
--with-hook) HOOKSCRIPTS="$HOOKSCRIPTS${HOOKSCRIPTS:+ }$var";;
--with-hooks|HOOKSCRIPTS) HOOKSCRIPTS=$var; HOOKSET=true;;
--build) BUILD=$var;;
--host) HOST=$var; HOSTCC=$var-;;
--target) TARGET=$var;;
--libdir) LIBDIR=$var;;
--with-poll) POLL="$var";;
--infodir) ;; # ignore autotools
--disable-maintainer-mode|--disable-dependency-tracking) ;;
--disable-silent-rules) ;;
-V|--version)
v=$(sed -ne 's/.*VERSION[[:space:]]*"\([^"]*\).*/\1/p' src/parpd.h);
c=$(sed -ne 's/^.*copyright\[\] = "\([^"]*\).*/\1/p' src/parpd.c);
echo "parpd-$v $c";
exit 0;;
-h|--help) cat <<EOF
\`configure' configures this package to adapt to many kinds of systems.
Usage: configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
-V, --version display version information and exit
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX [/]
By default, \`make install' will install all the files in \'/sbin',
\`/libexec', etc. You can specify
an installation prefix other than \`/' using \`--prefix',
for instance \`--prefix=$HOME'.
For better control, use the options below.
Fine tuning of the installation directories:
--bindir=DIR user executables [PREFIX/bin]
--sbindir=DIR system admin executables [PREFIX/sbin]
--libexecdir=DIR program executables [PREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--localstatedir=DIR modifiable single-machine data [/var]
--libdir=DIR object code libraries [PREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--mandir=DIR man documentation [PREFIX/man]
System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST build programs to run on HOST [BUILD]
--target=TARGET configure for building compilers for TARGET [HOST]
Optional Features:
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
CPPFLAGS C/C++ preprocessor flags, e.g. -I<include dir> if you have
headers in a nonstandard directory <include dir>
CPP C preprocessor
PKG_CONFIG pkg-config executable
Use these variables to override the choices made by \`configure' or to help
it to find libraries and programs with nonstandard names/locations.
EOF
exit 0
;;
*) echo "$0: WARNING: unknown option $opt" >&2;;
esac
done
: ${SED:=sed}
: ${GREP:=grep}
: ${PKG_CONFIG:=pkg-config}
: ${WC:=wc}
_which()
{
x="$(which "$1" 2>/dev/null)"
if [ $? = 0 -a -n "$x" ]; then
echo "$x"
return 0
fi
for x in /sbin/"$1" /usr/sbin/"$1" \
/usr/pkg/sbin/"$1" /usr/local/sbin/"$1"
do
if [ -e "$x" ]; then
echo "$x"
return 0
fi
done
return 1
}
CONFIG_H=config.h
CONFIG_MK=config.mk
if [ -z "$BUILD" ]; then
# autoconf target triplet: cpu-vendor-os
BUILD=$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')
fi
: ${HOST:=$BUILD}
if [ -z "$OS" ]; then
echo "Deriving operating system from ... $HOST"
# Derive OS from cpu-vendor-[kernel-]os
CPU=${HOST%%-*}
REST=${HOST#*-}
if [ "$CPU" != "$REST" ]; then
VENDOR=${REST%%-*}
REST=${REST#*-}
if [ "$VENDOR" != "$REST" ]; then
# Use kernel if given, otherwise os
OS=${REST%%-*}
else
# 2 tupple
OS=$VENDOR
VENDOR=
fi
fi
# Work with cpu-kernel-os, ie Debian
case "$VENDOR" in
linux*|kfreebsd*) OS=$VENDOR; VENDOR= ;;
esac
case "$REST" in
gnu/kfreebsd*) OS="kfreebsd"; VENDOR= ;;
esac
# Special case
case "$OS" in
dragonfly*)
# This means /usr HAS to be mounted not via dhcpcd
: ${LIBEXECDIR:=${PREFIX:-/usr}/libexec}
;;
gnu*) OS=hurd;; # No HURD support as yet
esac
fi
echo "Configuring parpd for ... $OS"
rm -f $CONFIG_H $CONFIG_MK
echo "# $OS" >$CONFIG_MK
echo "/* $OS */" >$CONFIG_H
if [ "$PREFIX" = /usr ]; then
: ${SYSCONFDIR:=/etc}
else
: ${SYSCONFDIR:=$PREFIX/etc}
fi
: ${SBINDIR:=$PREFIX/sbin}
: ${STATEDIR:=/var}
: ${RUNDIR:=$STATEDIR/run}
: ${MANDIR:=${PREFIX:-/usr}/share/man}
eval SYSCONFDIR="$SYSCONFDIR"
eval SBINDIR="$SBINDIR"
eval RUNDIR="$RUNDIR"
eval MANDIR="$MANDIR"
echo "#ifndef SYSCONFDIR" >>$CONFIG_H
for x in SYSCONFDIR SBINDIR RUNDIR; do
eval v=\$$x
# Make files look nice for import
l=$((10 - ${#x}))
unset t
[ $l -gt 3 ] && t=" "
echo "$x=$t $v" >>$CONFIG_MK
unset t
[ $l -gt 2 ] && t=" "
echo "#define $x$t \"$v\"" >>$CONFIG_H
done
echo "#endif" >>$CONFIG_H
echo "MANDIR= $MANDIR" >>$CONFIG_MK
# Always obey CC.
if [ -n "$CC" ]; then
HOSTCC=
else
CC=cc
_COMPILERS="cc clang gcc pcc icc"
fi
# Only look for a cross compiler if --host and --build are not the same
if [ -n "$HOSTCC" -a "$BUILD" != "$HOST" ]; then
for _CC in $_COMPILERS; do
_CC=$(_which "$HOSTCC$_CC")
if [ -x "$_CC" ]; then
CC=$_CC
break
fi
done
fi
if ! type "$CC" >/dev/null 2>&1; then
for _CC in $_COMPILERS; do
_CC=$(_which "$_CC")
if [ -x "$_CC" ]; then
CC=$_CC
break
fi
done
fi
# Set to blank, then append user config
# We do this so our SED call to append to XCC remains portable
if [ -n "$CFLAGS" ]; then
echo "CFLAGS=" >>$CONFIG_MK
echo "CFLAGS+= $CFLAGS" >>$CONFIG_MK
fi
if [ -n "$CPPFLAGS" ]; then
echo "CPPFLAGS=" >>$CONFIG_MK
echo "CPPFLAGS+= $CPPFLAGS" >>$CONFIG_MK
fi
if [ -n "$INCLUDEDIR" ]; then
echo "CPPFLAGS+= $INCLUDEDIR" >>$CONFIG_MK
fi
if [ -n "$LDFLAGS" ]; then
echo "LDFLAGS=" >>$CONFIG_MK
echo "LDFLAGS+= $LDFLAGS" >>$CONFIG_MK
fi
echo "CPPFLAGS+= -DHAVE_CONFIG_H" >>$CONFIG_MK
if [ "$STATIC" = yes ]; then
echo "LDFLAGS+= -static" >>$CONFIG_MK
fi
if [ -z "$DEBUG" -a -d .git ]; then
printf "Found git checkout ... "
DEBUG=yes
fi
if [ -n "$DEBUG" -a "$DEBUG" != no -a "$DEBUG" != false ]; then
echo "Adding debugging CFLAGS"
cat <<EOF >>$CONFIG_MK
CPPFLAGS+= -DSANITIZE_MEMORY
CFLAGS+= -g -Wall -Wextra
CFLAGS+= -Wmissing-prototypes -Wmissing-declarations
CFLAGS+= -Wmissing-format-attribute -Wnested-externs
CFLAGS+= -Winline -Wcast-align -Wcast-qual -Wpointer-arith
CFLAGS+= -Wreturn-type -Wswitch -Wshadow
CFLAGS+= -Wcast-qual -Wwrite-strings
CFLAGS+= -Wformat=2
CFLAGS+= -Wpointer-sign -Wmissing-noreturn
EOF
case "$OS" in
mirbsd*|openbsd*);; # OpenBSD has many redundant decs in system headers
bitrig*|solaris*|sunos*)
echo "CFLAGS+= -Wredundant-decls" >>$CONFIG_MK
;; # Bitrig spouts many conversion errors with htons
# sunos has many as well
*) echo "CFLAGS+= -Wredundant-decls" >>$CONFIG_MK
echo "CFLAGS+= -Wconversion" >>$CONFIG_MK
;;
esac
case "$OS" in
solaris*|sunos*);;
*) echo "CFLAGS+= -Wstrict-overflow" >>$CONFIG_MK;;
esac
# Turn on extra per compiler debugging
case "$CC" in
*gcc*) echo "CFLAGS+= -Wlogical-op" >>$CONFIG_MK;;
esac
else
echo "CPPFLAGS+= -DNDEBUG" >>$CONFIG_MK
fi
case "$OS" in
linux*)
echo "SRC_PF= lpf.c" >>$CONFIG_MK
;;
*)
echo "SRC_PF= bpf.c" >>$CONFIG_MK
;;
esac
echo "Using compiler .. $CC"
# Add CPPFLAGS and CFLAGS to CC for testing features
XCC="$CC `$SED -n -e 's/CPPFLAGS+=*\(.*\)/\1/p' $CONFIG_MK`"
XCC="$XCC `$SED -n -e 's/CFLAGS+=*\(.*\)/\1/p' $CONFIG_MK`"
# When running tests, treat all warnings as errors.
# This avoids the situation where we link to a libc symbol
# without the correct header because it might be hidden behind
# a _*_SOURCE #define guard.
XCC="$XCC -Wall -Werror"
# Now test we can use the compiler with our CFLAGS
cat <<EOF >_test.c
int main(void) {
return 0;
}
EOF
_CC=false
if $XCC _test.c -o _test >/dev/null 2>&3; then
[ -x _test ] && _CC=true
fi
rm -f _test.c _test
if ! $_CC; then
echo "$CC does not create executables" >&2
exit 1
fi
[ "$CC" != cc ] && echo "CC= $CC" >>$CONFIG_MK
$CC --version | $SED -e '1!d'
abort=false
# We require the libc to support non standard functions, like getifaddrs
printf "Testing for getifaddrs ... "
cat <<EOF >_getifaddrs.c
#include <sys/types.h>
#include <ifaddrs.h>
int main(void) {
struct ifaddrs *ifap;
return getifaddrs(&ifap);
}
EOF
LIBSOCKET=
if $XCC _getifaddrs.c -o _getifaddrs 2>&3; then
echo "yes"
elif $XCC _getifaddrs.c -o _getifaddrs -lsocket 2>&3; then
LIBSOCKET=-lsocket
echo "yes (-lsocket)"
echo "LDADD+= -lsocket" >>$CONFIG_MK
else
echo "no"
echo "libc support for getifaddrs is required - aborting" >&2
abort=true
fi
rm -f _getifaddrs.c _getifaddrs
$abort && exit 1
printf "Testing for clock_gettime ... "
cat <<EOF >_clock_gettime.c
#include <time.h>
int main(void) {
struct timespec ts;
return clock_gettime(CLOCK_MONOTONIC, &ts);
}
EOF
if $XCC _clock_gettime.c -o _clock_gettime 2>&3; then
echo "yes"
elif $XCC _clock_gettime.c -lrt -o _clock_gettime 2>&3; then
echo "yes (-lrt)"
echo "LDADD+= -lrt" >>$CONFIG_MK
else
echo "no"
echo "libc support for clock_getttime is required - aborting" >&2
abort=true
fi
rm -f _clock_gettime.c _clock_gettime
$abort && exit 1
printf "Testing for inet_ntoa ... "
cat <<EOF >_inet_ntoa.c
#include <netinet/in.h>
#include <arpa/inet.h>
int main(void) {
struct in_addr in = { .s_addr = 0 };
inet_ntoa(in);
return 0;
}
EOF
if $XCC _inet_ntoa.c -o _inet_ntoa 2>&3; then
echo "yes"
elif $XCC _inet_ntoa.c -lnsl -o _inet_ntoa 2>&3; then
echo "yes (-lnsl)"
echo "LDADD+= -lnsl" >>$CONFIG_MK
elif $XCC _inet_ntoa.c -lsocket -o _inet_ntoa 2>&3; then
echo "yes (-lsocket)"
echo "LDADD+= -lsocket" >>$CONFIG_MK
else
echo "no"
echo "libc support for inet_ntoa is required - aborting" >&2
abort=true
fi
rm -f _inet_ntoa.c _inet_ntoa
$abort && exit 1
if [ -z "$STRLCPY" ]; then
printf "Testing for strlcpy ... "
cat <<EOF >_strlcpy.c
#include <string.h>
int main(void) {
const char s1[] = "foo";
char s2[10];
strlcpy(s2, s1, sizeof(s2));
return 0;
}
EOF
if $XCC _strlcpy.c -o _strlcpy 2>&3; then
STRLCPY=yes
else
STRLCPY=no
fi
echo "$STRLCPY"
rm -f _strlcpy.c _strlcpy
fi
if [ "$STRLCPY" = no ]; then
echo "COMPAT_SRCS+= compat/strlcpy.c" >>$CONFIG_MK
echo "#include \"compat/strlcpy.h\"" >>$CONFIG_H
fi
if [ -z "$TAILQ_FOREACH_SAFE" ]; then
printf "Testing for TAILQ_FOREACH_SAFE ... "
cat <<EOF >_queue.c
#include <sys/queue.h>
int main(void) {
#ifndef TAILQ_FOREACH_SAFE
#error TAILQ_FOREACH_SAFE
#endif
return 0;
}
EOF
if $XCC _queue.c -o _queue 2>&3; then
TAILQ_FOREACH_SAFE=yes
TAILQ_FOREACH=yes
else
TAILQ_FOREACH_SAFE=no
fi
echo "$TAILQ_FOREACH_SAFE"
rm -f _queue.c _queue
fi
if [ "$TAILQ_FOREACH_SAFE" = no ] && [ -z "$TAILQ_FOREACH_MUTABLE" ]; then
printf "Testing for TAILQ_FOREACH_MUTABLE ... "
cat <<EOF >_queue.c
#include <sys/queue.h>
int main(void) {
#ifndef TAILQ_FOREACH_MUTABLE
#error TAILQ_FOREACH_MUTABLE
#endif
return 0;
}
EOF
if $XCC _queue.c -o _queue 2>&3; then
TAILQ_FOREACH_MUTABLE=yes
TAILQ_FOREACH_SAFE=yes
TAILQ_FOREACH=yes
echo "#define TAILQ_FOREACH_SAFE TAILQ_FOREACH_MUTABLE" \
>> $CONFIG_H
else
TAILQ_FOREACH_MUTABLE=no
fi
echo "$TAILQ_FOREACH_MUTABLE"
rm -f _queue.c _queue
fi
if [ -z "$TAILQ_FOREACH" ]; then
printf "Testing for TAILQ_FOREACH ... "
cat <<EOF >_queue.c
#include <sys/queue.h>
int main(void) {
#ifndef TAILQ_FOREACH
#error TAILQ_FOREACH
#endif
return 0;
}
EOF
if $XCC _queue.c -o _queue 2>&3; then
TAILQ_FOREACH=yes
else
TAILQ_FOREACH=no
fi
echo "$TAILQ_FOREACH"
rm -f _queue.c _queue
fi
if [ "$TAILQ_FOREACH_SAFE" = no ]; then
# If we don't include sys/queue.h then clang analyser finds
# too many false positives.
# See http://llvm.org/bugs/show_bug.cgi?id=18222
# Strictly speaking this isn't needed, but I like it to help
# catch any nasties.
if [ "$TAILQ_FOREACH" = yes ]; then
echo "#include <sys/queue.h>">>$CONFIG_H
fi
echo "#include \"compat/queue.h\"">>$CONFIG_H
else
echo "#define HAVE_SYS_QUEUE_H" >>$CONFIG_H
fi
if [ -z "$POLL" ]; then
printf "Testing for kqueue1 ... "
cat <<EOF >_kqueue.c
#include <sys/types.h>
#include <sys/event.h>
int main(void) {
return kqueue1(0);
}
EOF
if $XCC _kqueue.c -o _kqueue 2>&3; then
POLL=kqueue1
echo "yes"
else
echo "no"
fi
rm -f _kqueue.c _kqueue
fi
if [ -z "$POLL" ]; then
printf "Testing for kqueue ... "
cat <<EOF >_kqueue.c
#include <sys/types.h>
#include <sys/event.h>
int main(void) {
return kqueue();
}
EOF
if $XCC _kqueue.c -o _kqueue 2>&3; then
POLL=kqueue
echo "yes"
else
echo "no"
fi
rm -f _kqueue.c _kqueue
fi
if [ -z "$POLL" ]; then
printf "Testing for epoll ... "
cat <<EOF >_epoll.c
#ifdef __linux__
#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37)
#error kernel has buggy epoll_wait timeout
#endif
#endif
#include <sys/epoll.h>
#include <unistd.h>
int main(void) {
struct epoll_event e;
epoll_create1(EPOLL_CLOEXEC);
epoll_pwait(-1, &e, 0, 0, NULL);
return 0;
}
EOF
if $XCC _epoll.c -o _epoll 2>&3; then
POLL=epoll
echo "#define HAVE_EPOLL" >>$CONFIG_MK
echo "yes"
else
echo "no"
fi
rm -f _epoll.c _epoll
fi
if [ -z "$POLL" ]; then
printf "Testing for pselect ... "
cat <<EOF >_pselect.c
#include <sys/select.h>
#include <stdlib.h>
int main(void) {
pselect(0, NULL, NULL, NULL, NULL, NULL);
return 0;
}
EOF
if $XCC _pselect.c -o _pselect 2>&3; then
POLL=pselect
echo "yes"
else
echo "no"
fi
rm -f _pselect.c _pselect
fi
case "$POLL" in
kqueue1)
echo "#define HAVE_KQUEUE" >>$CONFIG_H
echo "#define HAVE_KQUEUE1" >>$CONFIG_H
;;
kqueue)
echo "#define HAVE_KQUEUE" >>$CONFIG_H
;;
epoll)
echo "#define HAVE_EPOLL" >>$CONFIG_H
;;
pollts)
echo "#define HAVE_POLLTS" >>$CONFIG_H
;;
ppoll)
echo "#define HAVE_PPOLL" >>$CONFIG_H
;;
pselect)
echo "#define HAVE_PSELECT" >>$CONFIG_H
;;
*)
echo "No suitable polling function is available, not even pselect" >&2
exit 1
;;
esac
echo
echo " SYSCONFDIR = $SYSCONFDIR"
echo " SBINDIR = $SBINDIR"
echo " RUNDIR = $RUNDIR"
echo " MANDIR = $MANDIR"
echo
rm -f parpd