3 die
() { >&2 printf '%s: fatal: %s\n' "${0##*/}" "$*"; exit 1; }
4 warn
() { >&2 printf '%s: %s\n' "${0##*/}" "$*"; }
9 [ "${V#*[!0-9]}" = "$V" ] || V
=1
10 V
="$(( 0 + ${V:-0} ))"
12 [ $V -le 1 ] || NOERR
=
16 [ $V -le 1 ] ||
[ -z "$TMPD" ] || warn
"retaining temp dir $TMPD"
17 [ $V -ge 2 ] ||
[ -z "$TMPD" ] ||
rm -rf "$TMPD"
28 # safe printf-based version of echo
29 echol
() { printf '%s\n' "$*"; }
31 # set variable with name $1 to name of new writable temp file with .$2 extension
32 # if $2 omitted default is "c"
34 if [ -z "$TMPD" ]; then
35 TMPD
="$(mktemp -d /tmp/make-config-h.XXXXXX)" && [ -n "$TMPD" ] && [ -w "$TMPD" ] ||
36 die
"could not make temp file directory"
38 _tmpf
="$(mktemp "$TMPD/source-XXXXXX
")" && [ -n "$_tmpf" ] && [ -w "$_tmpf" ] ||
39 die
"could not make temp file"
40 mv "$_tmpf" "$_tmpf.${2:-c}" || die
"could not rename temp file to have .${2:-c} extension"
41 eval "$1"'="$_tmpf.${2:-c}"'
44 # attempt to compile "C" source file
45 # on standard input with status as only result
46 # $1 contains eval'd extra compile args
51 eval '"$CC" -c -o "$_obj" $1 "$_src" >/dev/null '"$NOERR"
54 # attempt to compile and link "C" source file
55 # on standard input with status as only result
56 # $1 contains eval'd extra compile args
57 # $2 contains eval'd extra link args
61 v_get_temp_ext _bin bin
63 eval '"$CC" -c -o "$_obj" $1 "$_src" >/dev/null '"$NOERR" &&
64 eval '"$CC" -o "$_bin" $2 "$_obj" >/dev/null '"$NOERR"
67 # $1 is base name of macro to use (i.e. HAVE_$1)
68 # $2 is routine to call (either testcomp or testlink)
69 # $3... are optional options to $2
70 # standard input is source to compile or compile+link
74 [ $V -eq 0 ] || warn
"checking for $_macro..."
76 [ $V -eq 0 ] || warn
" ...HAVE_$_macro => yes"
77 echol
"#define HAVE_$_macro 1"
79 [ $V -eq 0 ] || warn
" ...HAVE_$_macro => no"
80 echol
"#undef HAVE_$_macro"
85 emitresult STDINT_H testcomp
<<-IPV6
87 extern uint32_t itworks(uint32_t);
90 # Check for IPV6 (see RFC 3493)
91 emitresult IPV6 testcomp
<<-IPV6
92 #include <sys/types.h>
93 #include <sys/socket.h>
94 #include <netinet/in.h>
95 #if defined(IN6ADDR_ANY_INIT) && defined(AF_INET6)
96 extern void itworks(void);
102 # Check for inet_ntop (see RFC 3493)
103 # this is separate in case IPV6 is present but inet_ntop is not
104 emitresult INET_NTOP testlink
<<-INET_NTOP
105 #include <sys/types.h>
106 #include <sys/socket.h>
107 #include <netinet/in.h>
108 #include <arpa/inet.h>
110 static void check(void)
113 struct in6_addr addr;
115 s = inet_ntop(AF_INET6, &addr, str, (socklen_t)sizeof(str));
125 emitresult SNPRINTF testlink
<<-SNPRINTF
127 static void check(void)
130 int n = snprintf(str, sizeof(str), "%d", (int)42);
131 printf("%n %s", n, str);
139 emitresult RLIMIT testlink
<<-RLIMIT
141 #include <sys/types.h>
142 #include <sys/time.h>
143 #include <sys/resource.h>
144 static void check(void)
148 rc = getrlimit(RLIMIT_FSIZE, &rl);
149 rl.rlim_cur = (rlim_t)LONG_MAX;
150 rl.rlim_max = RLIM_INFINITY;
151 rc = setrlimit(RLIMIT_FSIZE, &rl);