-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.sh
executable file
·1821 lines (1571 loc) · 40.3 KB
/
config.sh
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
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /bin/sh
#
# Copyright (c) 2005 Christian Biere <christianbiere@gmx.de>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# Note: This script is supposed to work with cross-compilers. Thus, no
# custom programs are run, only compiling and linking is used.
#
# Set DEBUG_CONFIG_SH to 1 to see all source code
# unset DEBUG_CONFIG_SH
debug_config_sh=1
# assert_fail is used to force the a compiler error
assert_fail='switch (0) { case 0: case (sizeof(char[-23]) == 333): break; }'
assert_work='switch (0) { case 0: case (sizeof(char[333]) == 333): break; }'
die () {
# print the first parameter to stdout and exit with an error
echo 'config.sh:' $1
echo '***'
echo '*** See config_test.log for details.'
echo '***'
exit 1
}
msg () {
# echo all parameters to stderr and stdout
echo ${1+"$@"} >&2
}
msg_printf() {
# printf all parameters to stderr and stdout
printf ${1+"$@"} >&2
}
msg_yes () {
# print 'yes' to stderr and stdout
msg 'yes'
return 0
}
msg_no () {
# print 'no' to stderr and stdout
msg 'no'
return 1
}
msg_yes_no () {
# print 'yes' on previous success or no on previous failure
# to stderr and stdout. The exit code is preserved.
if [ $1 -eq 0 ]; then
msg_yes
return 0
else
msg_no
return 1
fi
}
config_debug_log_source () {
test "x${debug_config_sh}" != x || return
{ echo; cat config_test.c; echo; } >> config_test.log
}
clear_var() {
eval $1=1
eval unset $1
}
config_test_c_compile () {
config_debug_log_source
${CC} ${CPPFLAGS} ${CFLAGS} -c config_test.c >> config_test.log 2>&1
if [ $? -eq 0 ]; then
test $# -gt 0 && eval $1=1
return 0
fi
test $# -gt 0 && clear_var $1
return 1
}
# config_test_c_create (line_1 ... line_n)
#
# This function creates config_test.c from line_1 (and optionally more lines)
# as part of the main() funtion.
#
config_test_c_create () {
test $# -gt 0 || die 'Too few arguments to "config_test_c_create"!'
{
echo '#include "config_test.h"'
printf 'int main(void)\n{\n'
while [ $# -gt 0 ]; do
printf "%s\n" "$1"
shift
done
printf ' return 0;\n}\n'
} > config_test.c
}
config_test_compile_lines () {
test $# -gt 0 || die 'Too few arguments to "config_test_compile_lines"!'
config_test_c_create ${1+"$@"}
config_test_c_compile
}
config_var() {
if [ $2 -ne 0 ]; then
clear_var $1
return 1
fi
eval $1=1
return 0
}
config_test_compile () {
test $# -gt 1 || die 'Too few arguments to "config_test_compile"!'
clear_var $1
eval ret=$1
shift
config_test_compile_lines ${1+"$@"}
config_var $ret $?
return $?
}
config_test_compile_and_link () {
test $# -gt 0 || die 'Too few arguments to "config_test_compile_and_link"!'
clear_var $1
eval ret=$1
shift
test $# -gt 0 && config_test_c_create ${1+"$@"}
config_test_c_compile || return 1
for lib in '' ${try_libs}; do
if [ "x${lib}" != x ]; then
lib="-l`echo "$lib"| sed 's/:/ -l/g'`"
fi
${CC} ${CPPFLAGS} ${CFLAGS} \
-o config_test config_test.o ${LDFLAGS} ${lib} \
>> config_test.log 2>&1
if [ $? -eq 0 ]; then
if [ "x${lib}" != x ]; then
LDFLAGS="${LDFLAGS:+$LDFLAGS }${lib}"
fi
config_var $ret 0
return 0
fi
done
config_var $ret 1
return 1
}
invert_result() {
test $1 -eq 0 && return 1
return 0
}
check_compile_time_assert () {
msg_printf 'Looking whether compile-time assertions work... '
config_test_compile_lines "${assert_work}" || { msg_no; return 1; }
config_test_compile_lines "${assert_fail}"
invert_result $?
msg_yes_no $?
return $?
}
check_std_header () {
test $# -gt 1 || die 'Too few arguments to "check_std_header"!'
msg_printf 'Looking for <'"$2"'>... '
cat > config_test.c <<EOF
#include "config_test.h"
#include <$2>
int main(void)
{
return 0;
}
EOF
config_test_c_compile
msg_yes_no $?
config_var $1 $?
return $?
}
#
# check_type_size (result, type, hint)
#
# hint is optional. It'll be checked first to speed up the detection.
#
check_type_size () {
printf 'Looking for sizeof('"$2"')... ' >&2
test $# -gt 1 || die 'Too few arguments to "check_type_size"!'
clear_var $1
# some shells can't calculate with $((expr)), so check common sizes only
for i in $3 1 2 4 8 16 32 64 128 256; do
config_test_compile_lines \
'static char x[sizeof('"$2"') == ('"$i"') ? 1 : -23];' \
'switch (0) { case 0: case (sizeof(x) == 1): break; }'
if [ $? -eq 0 ]; then
msg "$i"
eval $1="$i"
return 0
fi
done
msg 'failure'
return 1
}
#
# check_have_type (result, type)
#
check_have_type() {
msg_printf 'Looking for type '"$2"'... '
test $# -gt 1 || die 'Too few arguments to "check_have_type"!'
config_test_compile_lines "$2"' x; (void) x;'
msg_yes_no $?
if [ $? -eq 0 ]; then
eval $1=1
return 0
else
clear_var $1
return 1
fi
}
config_h_prolog() {
{
echo '#ifndef CONFIG_HEADER_FILE'
echo '#define CONFIG_HEADER_FILE'
echo
compiler_specifics
} >> config.h
}
config_h_epilog() {
{
echo
echo '#endif /* CONFIG_HEADER_FILE */'
} >> config.h
}
config_h_def() {
eval val=\$$1
{
if [ "x$val" != x ]; then
echo '#define '"$1" "$val"
else
echo '#undef '"$1"
fi
} >> config.h
}
config_test_h_def() {
eval val=\$$1
{
if [ "x$val" != x ]; then
echo '#define '"$1" "$val"
else
echo '#undef '"$1"
fi
} >> config_test.h
}
config_make_def() {
eval val=\$$1
echo "${1}=${val}"
}
compiler_specifics() {
echo '#ifdef __TenDRA__'
echo '#pragma TenDRA longlong type allow'
echo '#endif /* __TenDRA__ */'
}
compiler_flags() {
msg_printf 'Looking whether this is TenDRA CC... '
config_test_compile_lines \
'#if defined(__TenDRA__)' \
'/* Looks like TenDRA CC */' \
'#else' \
"${assert_fail}" \
'#endif'
msg_yes_no $?
if [ $? -eq 0 ]; then
CFLAGS='-Xa -O2'
export CFLAGS
return
fi
msg_printf 'Looking whether this is Tiny CC... '
config_test_compile_lines \
'#if defined(__TINYC__)' \
'/* Looks like Tiny CC */' \
'#else' \
"${assert_fail}" \
'#endif'
msg_yes_no $?
if [ $? -eq 0 ]; then
CFLAGS='-Wall -O2'
export CFLAGS
return
fi
msg_printf 'Looking whether this is GNU CC... '
config_test_compile_lines \
'#if defined(__GNUC__) && defined(__GNUC_MINOR__)' \
'#if ((__GNUC__ > 0) && (__GNUC_MINOR__ >= 0))' \
'/* Looks like GCC */' \
'#else' \
"${assert_fail}" \
'#endif' \
'#else' \
"${assert_fail}" \
'#endif'
msg_yes_no $?
if [ $? -eq 0 ]; then
msg_printf 'Looking for stack smashing protection... '
CFLAGS='-fstack-protector'
config_test_compile_and_link 'no_such_variable' ''
msg_yes_no $?
if [ $? -ne 0 ]; then
unset CFLAGS
msg '***'
msg '*** You might want to have a look at this:'
msg '***'
msg '*** http://www.trl.ibm.com/projects/security/ssp/'
msg '***'
fi
CFLAGS="${CFLAGS}"' -W -Wall -Wformat=2 -Wshadow -g -O2'
export CFLAGS
fi
}
create_makefile() {
test $# -eq 1 || die 'Wrong number of arguments for "create_makefile()"!'
dir="$1"
depfile="${dir}/Makefile.dep"
if [ -f "${depfile}" ]; then
touch "${depfile}"
cp config.h "${dir}" || exit
else
msg 'Creating "'"${depfile}"'" ...'
touch "${depfile}" || exit
(
cp config.h "${dir}" || exit
cd "${dir}" || exit
${CC} -MM *.c || exit
) > "${depfile}"
fi
(
if [ "x${prefix}" = x ]; then
prefix='/usr/local'
fi
if [ "x${bin_dir}" = x ]; then
bin_dir="${prefix}/bin"
fi
if [ "x${library_dir}" = x ]; then
library_dir="${prefix}/lib"
fi
if [ "x${header_dir}" = x ]; then
header_dir="${prefix}/include"
fi
echo '# Environment variables'
config_make_def 'CC'
config_make_def 'CPP'
config_make_def 'CFLAGS'
config_make_def 'CPPFLAGS'
config_make_def 'LDFLAGS'
config_make_def 'prefix'
config_make_def 'bin_dir'
config_make_def 'library_dir'
config_make_def 'header_dir'
config_make_def 'link_libdl'
config_make_def 'link_rpath'
echo
cat "${dir}/Makefile.template" "${dir}/Makefile.dep" || exit
) | cat > "${dir}/Makefile"
}
show_help() {
msg 'The following environment variables are honored:'
msg 'CC, CPP, CFLAGS, CPPFLAGS, LDFLAGS, PREFIX'
msg
msg 'The following switches are available:'
if [ "x${prefix}" != x ]; then
msg ' --prefix=PATH Path prefix used for installing files.'
fi
if [ "x${bin_dir}" != x ]; then
msg ' --bin-dir=PATH Directory used for installing executables.'
fi
if [ "x${library_dir}" != x ]; then
msg ' --library-dir=PATH Directory used for installing libraries.'
fi
if [ "x${header_dir}" != x ]; then
msg ' --header-dir=PATH Directory used for installing header files.'
fi
if [ "x${use_ipv6}" != x ]; then
msg ' --disable-ipv6 Do not use IPv6 even if supported.'
fi
if [ "x${use_zlib}" != x ]; then
msg ' --disable-zlib Do not use zlib even if available.'
fi
if [ "x${use_socker}" != x ]; then
msg ' --disable-socker Do not use socker even if available.'
fi
if [ "x${use_large_files}" != x ]; then
msg ' --disable-large-files Disable explicit large file support.'
fi
if [ "x${use_poll}" != x ]; then
msg ' --use-poll Use poll() instead of kqueue() or epoll().'
fi
if [ "x${use_threads}" != x ]; then
msg ' --use-threads Use POSIX threads (if available).'
fi
if [ "x${use_gethostbyname}" != x ]; then
msg ' --use-gethostbyname Use gethostbyname() instead of getaddrinfo().'
fi
if [ "x${use_sha1}" != x ]; then
msg ' --use-sha1 Use SHA-1 calculation routines.'
fi
if [ "x${use_sqlite3}" != x ]; then
msg ' --use-sqlite3 Use SQLite3.'
fi
msg
}
handle_vars() {
var_list="\
bin_dir \
header_dir \
library_dir \
prefix \
use_gethostbyname \
use_ipv6 \
use_poll \
use_sha1 \
use_socker \
use_sqlite3 \
use_threads \
use_zlib \
"
for var in $var_list; do
eval val=\$$var
if [ "x${val}" = xauto ]; then
unset ${var}
fi
done
}
set_var_from_arg() {
test $# -eq 2 || die 'Wrong number of arguments for "set_var_from_arg()"!'
eval $1=`echo "x$2" | sed 's,^x[^=]*=,,'`
}
handle_args() {
while [ $# -gt 0 ]; do
case $1 in
--help|-h)
show_help
exit
;;
--prefix=*)
set_var_from_arg 'prefix' "$1"
;;
--bin-dir=*)
set_var_from_arg 'bin_dir' "$1"
;;
--library-dir=*)
set_var_from_arg 'library_dir' "$1"
;;
--header-dir=*)
set_var_from_arg 'header_dir' "$1"
;;
--disable-ipv6)
unset use_ipv6
;;
--disable-zlib)
unset use_zlib
;;
--disable-large-files)
unset use_large_files
;;
--use-gethostbyname)
use_gethostbyname=1
;;
--use-poll)
use_poll=1
;;
--use-threads)
use_threads=1
;;
--disable-socker)
unset use_socker
;;
--use-socker)
use_socker=1
;;
--disable-sha1)
unset use_sha1
;;
--use-sha1)
use_sha1=1
;;
--disable-sqlite3)
unset use_sqlite3
;;
--use-sqlite3)
use_sqlite3=1
;;
*)
die 'Unsupported argument: "'"$1"'"'
;;
esac
shift
done
handle_vars
}
#
# Here starts the config.sh main routine
#
# Load settings and defaults
. ./config.conf
# Handle arguments
handle_args ${1+"$@"}
uid=`id -u || unknown`
if [ "x$uid" = x0 ]; then
msg 'There is no reason to run this as root.'
echo '***'
echo '*** JUU KYUU HACHI NANA ROKU GO YON SAN NI ICHI ZERO!'
echo '***'
fi
rm -f config_test.h || die 'Could not remove config_test.h'
touch config_test.h || die 'Could not create config_test.h'
rm -f config_test.log || die 'Could not remove config_test.log'
compiler_specifics >> config_test.h
msg_printf 'Looking for whether $(CC) is set... '
if [ "x$CC" = x ]; then
msg_yes_no $?
msg_printf 'Looking for C compiler (cc)... '
CC=`command -v cc || command -v gcc || echo cc`
fi
msg "$CC"
msg_printf 'Looking whether the compiler works... '
config_test_compile_and_link 'no_such_variable' ''
if [ $? -ne 0 ]; then
msg_no
die 'Cannot continue without a working compiler'
else
msg_yes $?
fi
check_compile_time_assert || die 'Cannot continue'
if [ "x${CFLAGS}" = x ]; then
compiler_flags
fi
check_std_header 'HAVE_SYS_TYPES_H' 'sys/types.h' && \
echo '#include <sys/types.h>' >> config_test.h
config_test_h_def 'HAVE_SYS_TYPES_H'
check_std_header 'HAVE_INTTYPES_H' 'inttypes.h' && \
echo '#include <inttypes.h>' >> config_test.h
config_test_h_def 'HAVE_INTTYPES_H'
check_std_header 'HAVE_STDBOOL_H' 'stdbool.h' && \
echo '#include <stdbool.h>' >> config_test.h
config_test_h_def 'HAVE_STDBOOL_H'
check_std_header 'HAVE_STDLIB_H' 'stdlib.h' && \
echo '#include <stdlib.h>' >> config_test.h
config_test_h_def 'HAVE_STDLIB_H'
check_std_header 'HAVE_SYS_PARAM_H' 'sys/param.h' && \
echo '#include <sys/param.h>' >> config_test.h
config_test_h_def 'HAVE_SYS_PARAM_H'
check_std_header 'HAVE_SYS_ENDIAN_H' 'sys/endian.h' && \
echo '#include <sys/endian.h>' >> config_test.h
config_test_h_def 'HAVE_SYS_ENDIAN_H'
check_std_header 'HAVE_SYS_SOCKET_H' 'sys/socket.h' && \
echo '#include <sys/socket.h>' >> config_test.h
config_test_h_def 'HAVE_SYS_SOCKET_H'
check_std_header 'HAVE_SYS_EVENT_H' 'sys/event.h' && \
echo '#include <sys/event.h>' >> config_test.h
config_test_h_def 'HAVE_SYS_EVENT_H'
check_std_header 'HAVE_SYS_TIME_H' 'sys/time.h' && \
echo '#include <sys/time.h>' >> config_test.h
config_test_h_def 'HAVE_SYS_TIME_H'
check_std_header 'HAVE_SYS_UN_H' 'sys/un.h' && \
echo '#include <sys/un.h>' >> config_test.h
config_test_h_def 'HAVE_SYS_UN_H'
check_std_header 'HAVE_NETINET_IN_H' 'netinet/in.h' && \
echo '#include <netinet/in.h>' >> config_test.h
config_test_h_def 'HAVE_NETINET_IN_H'
check_std_header 'HAVE_ARPA_INET_H' 'arpa/inet.h' && \
echo '#include <arpa/inet.h>' >> config_test.h
config_test_h_def 'HAVE_ARPA_INET_H'
if [ "x${use_threads}" != x ]; then
check_std_header 'HAVE_PTHREAD_H' 'pthread.h' && \
echo '#include <pthread.h>' >> config_test.h
config_test_h_def 'HAVE_PTHREAD_H'
else
clear_var HAVE_PTHREAD_H
fi
msg_printf 'Looking for SHUT_RD... '
config_test_compile 'HAVE_SHUT_RD' 'shutdown(1, SHUT_RD);'
msg_yes_no $?
msg_printf 'Looking for SHUT_WR... '
config_test_compile 'HAVE_SHUT_WR' 'shutdown(1, SHUT_WR);'
msg_yes_no $?
msg_printf 'Looking for SHUT_RDWR... '
config_test_compile 'HAVE_SHUT_RDWR' 'shutdown(1, SHUT_RDWR);'
msg_yes_no $?
check_std_header 'HAVE_NETDB_H' 'netdb.h' && \
echo '#include <netdb.h>' >> config_test.h
config_test_h_def 'HAVE_NETDB_H'
check_std_header 'HAVE_FEATURES_H' 'features.h'
config_test_h_def 'HAVE_FEATURES_H'
check_have_type 'HAVE_INT8_T' 'int8_t'
config_test_h_def 'HAVE_INT8_T'
check_have_type 'HAVE_UINT8_T' 'uint8_t'
config_test_h_def 'HAVE_UINT8_T'
check_have_type 'HAVE_INT16_T' 'int16_t'
config_test_h_def 'HAVE_INT16_T'
check_have_type 'HAVE_UINT16_T' 'uint16_t'
config_test_h_def 'HAVE_UINT16_T'
check_have_type 'HAVE_INT32_T' 'int32_t'
config_test_h_def 'HAVE_INT32_T'
check_have_type 'HAVE_UINT32_T' 'uint32_t'
config_test_h_def 'HAVE_UINT32_T'
check_have_type 'HAVE_INT64_T' 'int64_t'
config_test_h_def 'HAVE_INT64_T'
check_have_type 'HAVE_UINT64_T' 'uint64_t'
config_test_h_def 'HAVE_UINT64_T'
check_have_type 'HAVE_INTMAX_T' 'intmax_t'
config_test_h_def 'HAVE_INTMAX_T'
check_have_type 'HAVE_UINTMAX_T' 'uintmax_t'
config_test_h_def 'HAVE_UINTMAX_T'
check_have_type 'HAVE_INTPTR_T' 'intptr_t'
config_test_h_def 'HAVE_INTPTR_T'
check_have_type 'HAVE_UINTPTR_T' 'uintptr_t'
config_test_h_def 'HAVE_UINTPTR_T'
check_have_type 'HAVE_SOCKLEN_T' 'socklen_t'
config_test_h_def 'HAVE_SOCKLEN_T'
check_have_type 'HAVE_IN_ADDR_T' 'in_addr_t'
config_test_h_def 'HAVE_IN_ADDR_T'
check_have_type 'HAVE_IN_PORT_T' 'in_port_t'
config_test_h_def 'HAVE_PORT_T'
check_type_size 'SIZEOF_CHAR' 'char'
config_test_h_def 'SIZEOF_CHAR'
check_type_size 'SIZEOF_SHORT' 'short' 2
config_test_h_def 'SIZEOF_SHORT'
check_type_size 'SIZEOF_INT' 'int' 4
config_test_h_def 'SIZEOF_INT'
check_type_size 'SIZEOF_LONG' 'long' 4
config_test_h_def 'SIZEOF_LONG'
check_type_size 'SIZEOF_LONG_LONG' 'long long' 8
config_test_h_def 'SIZEOF_LONG_LONG'
check_type_size 'SIZEOF_UINTMAX_T' 'uintmax_t' 8
config_test_h_def 'SIZEOF_UINTMAX_T'
check_type_size 'SIZEOF_UINTPTR_T' 'uintptr_t' 4
config_test_h_def 'SIZEOF_UINTPTR_T'
check_type_size 'SIZEOF_VOID_PTR' 'void *' 4
config_test_h_def 'SIZEOF_VOID_PTR'
check_type_size 'SIZEOF_BOOL' 'bool' 4
config_test_h_def 'SIZEOF_BOOL'
check_type_size 'SIZEOF_SIZE_T' 'size_t' 4
config_test_h_def 'SIZEOF_SIZE_T'
check_type_size 'SIZEOF_OFF_T' 'off_t' 4
config_test_h_def 'SIZEOF_OFF_T'
msg_printf 'Looking for C99 __func__ ... '
config_test_compile_and_link 'HAVE_C99_func' \
'const char *s = __func__; (void) s;'
msg_yes_no $?
config_test_h_def 'HAVE_C99_func'
msg_printf 'Looking for C99 inline support... '
cat > config_test.c <<EOF
#include "config_test.h"
static inline int
my_function(int i)
{
return i;
}
int main(int argc, char *argv[])
{
(void) argv;
return 0 != my_function(argc);
}
EOF
config_test_c_compile 'HAVE_C99_inline'
msg_yes_no $?
msg_printf 'Looking for __inline support... '
cat > config_test.c <<EOF
#include "config_test.h"
static __inline int
my_function(int i)
{
return i;
}
int main(int argc, char *argv[])
{
(void) argv;
return 0 != my_function(argc);
}
EOF
config_test_c_compile 'HAVE___inline'
msg_yes_no $?
msg_printf 'Looking for C99 variadic macro support... '
cat > config_test.c <<EOF
#include "config_test.h"
int
my_function(int i, ...)
{
return i;
}
#define MY_MACRO(...) my_function(1, ## __VA_ARGS__)
int main(void)
{
MY_MACRO(1, 2);
return 0;
}
EOF
config_test_c_compile 'HAVE_C99_VARIADIC_MACROS'
msg_yes_no $?
if [ "x${use_large_files}" != x ]; then
msg_printf 'Looking for large file support... '
cat > config_test.c <<EOF
#include "config_test.h"
#define STATIC_ASSERT(x) \
do { switch (0) { case 0: case ((x) ? 1 : 0): break; } } while(0)
#define MAX_INT_VAL(t) \
(((t) 1 << (CHAR_BIT * sizeof(t) - 1 - ((t) -1 < 0))) \
- 1 + ((t) 1 << (CHAR_BIT * sizeof(t) - 1 - ((t) -1 < 0))))
int
main(void)
{
STATIC_ASSERT(MAX_INT_VAL(off_t) > 0x7fffffffL);
return 0;
}
EOF
config_test_compile_and_link 'HAVE_LARGE_FILE_SUPPORT'
if [ "x${HAVE_LARGE_FILE_SUPPORT}" != x ]; then
msg_yes
else
saved_cflags=${CFLAGS}
CFLAGS="${CFLAGS} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE"
config_test_compile_and_link 'HAVE_LARGE_FILE_SUPPORT'
if [ "x${HAVE_LARGE_FILE_SUPPORT}" != x ]; then
msg_yes
else
CFLAGS=${saved_cflags}
fi
fi
fi
msg_printf 'Looking for gethostbyname()... '
# Solaris needs libnsl for gethostbyname()
try_libs='nsl'
config_test_compile_and_link 'HAVE_GETHOSTBYNAME' \
'struct hostent *he = gethostbyname("localhost"); if (!he) return 1;'
msg_yes_no $?
unset try_libs
msg_printf 'Looking for herror()... '
# Solaris needs libresolv, libnsl and libsocket for herror()
try_libs='socket nsl resolv socket:nsl socket:nsl:resolv'
config_test_compile_and_link 'HAVE_HERROR' 'char *s = "blah"; herror(s);'
msg_yes_no $?
unset try_libs
msg_printf 'Looking for hstrerror()... '
# Solaris needs libresolv, libnsl and libsocket for hstrerror()
try_libs='socket nsl resolv socket:nsl socket:nsl:resolv'
config_test_compile_and_link 'HAVE_HSTRERROR' \
'int i = 1; const char *s = hstrerror(i); if (!s) return 1;'
msg_yes_no $?
unset try_libs
if [ "x${use_gethostbyname}" != x ]; then
clear_var HAVE_GETADDRINFO
clear_var HAVE_FREEADDRINFO
clear_var HAVE_GAI_STRERROR
else
msg_printf 'Looking for getaddrinfo()... '
# Solaris needs libsocket and libnsl for getaddrinfo()
try_libs='socket nsl socket:nsl'
cat > config_test.c <<EOF
#include "config_test.h"
int
main(void) {
static int ret;
struct addrinfo hints;
struct addrinfo *res;
hints.ai_flags = 1;
hints.ai_family = 1;
hints.ai_socktype = 1;
hints.ai_protocol = 1;
hints.ai_addrlen = (socklen_t) 1;
hints.ai_canonname = "canonname";
hints.ai_addr = (struct sockaddr *) 0;
hints.ai_next = (struct addrinfo *) 0;
ret |= getaddrinfo("localhost", "www", &hints, &res);
return 0 != ret;
}
EOF
config_test_compile_and_link 'HAVE_GETADDRINFO'
msg_yes_no $?
unset try_libs
msg_printf 'Looking for freeaddrinfo()... '
# Solaris needs libsocket and libnsl for freeaddrinfo()
try_libs='socket nsl socket:nsl'
config_test_compile_and_link 'HAVE_FREEADDRINFO' \
'struct addrinfo *ai = (struct addrinfo *) 0; freeaddrinfo(ai);'
msg_yes_no $?
unset try_libs
msg_printf 'Looking for gai_strerror()... '
# Solaris needs libsocket and libnsl for gai_strerror()
try_libs='socket nsl socket:nsl'
config_test_compile_and_link 'HAVE_GAI_STRERROR' \
'int i = 1; const char *s = gai_strerror(i); if (!s) return 1;'
msg_yes_no $?
unset try_libs
fi
if [ "x${use_ipv6}" != x ]; then
msg_printf 'Looking for IPv6 support... '
cat > config_test.c <<EOF
#include "config_test.h"
/*
* <sys/socket.h>,
* <netinet/in.h>,
* <arpa/inet.h>,
* <netdb.h> are included by config_test.h
*/
#define STATIC_ASSERT(x) \
do { switch (0) { case 0: case ((x) ? 1 : 0): break; } } while(0)
int
main(void) {
static struct sockaddr_storage ss;
static struct sockaddr_in6 sin6;
static struct in6_addr in6;
ss.ss_family |= PF_INET6;
sin6.sin6_family |= AF_INET6;
sin6.sin6_port |= 6346;
sin6.sin6_flowinfo |= 23UL;
sin6.sin6_scope_id |= 42UL;
sin6.sin6_addr = in6;
sin6.sin6_addr.s6_addr[0] = in6.s6_addr[0];
STATIC_ASSERT(AF_INET6 == PF_INET6);
STATIC_ASSERT(sizeof in6 == sizeof sin6.sin6_addr);
STATIC_ASSERT(16 == sizeof sin6.sin6_addr.s6_addr);
STATIC_ASSERT(2 == sizeof sin6.sin6_port);
STATIC_ASSERT(4 == sizeof sin6.sin6_flowinfo);
STATIC_ASSERT(4 == sizeof sin6.sin6_scope_id);
(void) sin6;
(void) in6;
return 0;
}
EOF
config_test_compile_and_link 'HAVE_IPV6_SUPPORT'
msg_yes_no $?
else
clear_var HAVE_IPV6_SUPPORT
fi
msg_printf 'Looking for setproctitle()... '
config_test_compile_and_link 'HAVE_SETPROCTITLE' 'setproctitle("blah");'
msg_yes_no $?
msg_printf 'Looking for fchroot()... '
echo '#include <unistd.h>' >> config_test.h
config_test_compile_and_link \
'HAVE_FCHROOT' 'int fd = 1; int ret; ret = fchroot(fd);'
msg_yes_no $?
msg_printf 'Looking for SA_INTERRUPT... '
echo '#include <signal.h>' >> config_test.h
config_test_compile_and_link 'HAVE_SA_INTERRUPT' 'int x; x = SA_INTERRUPT;'
msg_yes_no $?