6 # Get a temporary filename
7 fail
() { printf "%s\n" "$1" >&2 ; exit 1 ; }
10 while : ; do i
=$
(($i+1))
11 tmpc
="./conf$$-$PPID-$i.c"
12 2>|
/dev
/null
> "$tmpc" && break
13 test "$i" -gt 50 && fail
"$0: cannot create temporary file $tmpc"
16 trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
19 printf "checking %s ... " "$1"
22 $CC $OUR_CPPFLAGS $CPPFLAGS $2 $CFLAGS "$tmpc" -o "$tmpc".out
>/dev
/null
2>&1 \
25 { printf "yes\n" ; test x
"$2" = x || OUR_CPPFLAGS
="$OUR_CPPFLAGS $2" ; } \
32 $CC $OUR_CPPFLAGS $CPPFLAGS $CFLAGS -dM -E - </dev
/null |
grep "$1"
35 get_define_stripped
() {
36 local output
=$
(get_define
"$1")
37 test "$?" = 0 ||
return 1
38 printf "%s\n" "$output" |
sed 's/^.* .* //'
42 printf "checking whether \$CC defines %s ... " "$1"
44 get_define
"$1" >/dev
/null
&& res
=0
45 test x
$res = x0
&& printf "yes\n" ||
printf "no\n"
50 printf "checking %s ... " "$1"
53 $CC $OUR_CPPFLAGS $CPPFLAGS $CFLAGS "$tmpc" -o "$tmpc".out
>/dev
/null
2>&1 \
55 test x
$res = x0
&& { "$tmpc".out || res
=1 ; }
57 test x
$res = x0
&& printf "yes\n" ||
printf "no\n"
64 $CC $OUR_CPPFLAGS $CPPFLAGS $1 $CFLAGS "$tmpc" -o "$tmpc".out
>/dev
/null
2>&1 || res
=1
70 printf "checking %s ... " "$1"
72 check_link_silent
"$2" "$3" || res
=1
73 test x
$res = x0
&& printf "yes\n" ||
printf "no\n"
78 echo "supported arguments"
79 echo "--prefix=/path default: $prefix"
80 echo "--exec_prefix=/path default: $prefix/bin"
81 echo "--bindir=/path default: $prefix/bin"
82 echo "--libdir=/path default: $prefix/lib"
83 echo "--includedir=/path default: $prefix/include"
84 echo "--sysconfdir=/path default: $prefix/etc"
85 echo "--ignore-cve default: no"
86 echo " if set to yes ignores CVE-2015-3887 and makes it possible"
87 echo " to preload from current dir (possibly insecure, but handy)"
88 echo "--fat-binary : build for both i386 and x86_64 architectures on 64-bit Macs"
89 echo "--hookmethod=dlsym|dyld hook method for osx. default: auto"
90 echo " if OSX >= 12 is detected, dyld method will be used if auto."
91 echo "--help : show this text"
98 #alternatives echo "$arg" | cut -d= -f2-
99 # or echo "$arg" | sed 's/[^=]*=//'
108 --prefix=*) prefix
=`spliteq $1`;;
109 --exec_prefix=*) exec_prefix
=`spliteq $1`;;
110 --bindir=*) bindir
=`spliteq $1`;;
111 --libdir=*) libdir
=`spliteq $1`;;
112 --includedir=*) includedir
=`spliteq $1`;;
113 --sysconfdir=*) sysconfdir
=`spliteq $1`;;
114 --ignore-cve) ignore_cve
=1;;
115 --ignore-cve=*) ignore_cve
=`spliteq $1`;;
116 --hookmethod=*) hookmethod
=`spliteq $1`;;
117 --fat-binary) fat_binary
=1;;
124 -*) parsearg
"$1"; shift;;
129 if [ -z "$exec_prefix" ] ; then
133 if [ -z "$libdir" ] ; then
137 if [ -z "$includedir" ] ; then
138 includedir
=$prefix/include
141 if [ -z "$sysconfdir" ] ; then
142 sysconfdir
=$prefix/etc
145 if [ -z "$bindir" ] ; then
146 bindir
=$exec_prefix/bin
149 if [ -z "$CC" ] ; then
167 solaris_detected
=false
176 check_compile
'whether C compiler works' '' 'int main() {return 0;}' || fail
'error: install a C compiler and library'
178 if ! check_compile
'whether getnameinfo() servlen argument is POSIX compliant (socklen_t)' "-DGN_NODELEN_T=socklen_t -DGN_SERVLEN_T=socklen_t -DGN_FLAGS_T=int" \
179 '#define _GNU_SOURCE\n#include <netdb.h>\nint getnameinfo(const struct sockaddr *, socklen_t, char *, socklen_t, char *, socklen_t, int);int main() {\nreturn 0;}' ; then
181 if ! check_compile
'whether getnameinfo() flags argument is unsigned' "-DGN_NODELEN_T=socklen_t -DGN_SERVLEN_T=socklen_t -DGN_FLAGS_T=unsigned" \
182 '#define _GNU_SOURCE\n#include <netdb.h>\nint getnameinfo(const struct sockaddr *, socklen_t, char *, socklen_t, char *, socklen_t, unsigned);int main() {\nreturn 0;}' ; then
183 if ! check_compile
'whether getnameinfo() servlen argument is size_t' "-DGN_NODELEN_T=socklen_t -DGN_SERVLEN_T=size_t -DGN_FLAGS_T=int" \
184 '#define _GNU_SOURCE\n#include <netdb.h>\nint getnameinfo(const struct sockaddr *, socklen_t, char *, socklen_t, char *, size_t, int);int main() {\nreturn 0;}' ; then
186 if ! check_compile
'whether getnameinfo() servlen and nodelen argument is size_t' "-DGN_NODELEN_T=size_t -DGN_SERVLEN_T=size_t -DGN_FLAGS_T=int" \
187 '#define _GNU_SOURCE\n#include <netdb.h>\nint getnameinfo(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int);int main() {\nreturn 0;}' ; then
188 fail
"failed to detect getnameinfo signature"
194 check_compile
'whether we have GNU-style getservbyname_r()' "-DHAVE_GNU_GETSERVBYNAME_R" \
195 '#define _GNU_SOURCE\n#include <netdb.h>\nint main() {\nstruct servent *se = 0;struct servent se_buf;char buf[1024];\ngetservbyname_r("foo", (void*) 0, &se_buf, buf, sizeof(buf), &se);\nreturn 0;}'
197 check_compile
'whether we have pipe2() and O_CLOEXEC' "-DHAVE_PIPE2" \
198 '#define _GNU_SOURCE\n#include <fcntl.h>\n#include <unistd.h>\nint main() {\nint pipefd[2];\npipe2(pipefd, O_CLOEXEC);\nreturn 0;}'
200 check_compile
'whether we have SOCK_CLOEXEC' "-DHAVE_SOCK_CLOEXEC" \
201 '#define _GNU_SOURCE\n#include <sys/socket.h>\nint main() {\nreturn socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, 0);}'
203 check_compile
'whether we have clock_gettime' "-DHAVE_CLOCK_GETTIME" \
204 '#define _GNU_SOURCE\n#include <time.h>\nint main() {\nstruct timespec now;clock_gettime(CLOCK_REALTIME, &now);\nreturn now.tv_sec ^ now.tv_nsec;}'
206 check_define __APPLE__
&& {
208 check_define __x86_64__
&& mac_64
=true
209 if test "$hookmethod" = auto
; then
210 osver
=$
(get_define_stripped __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
2>/dev
/null
)
211 test "$osver" -gt $
((120000 - 1)) && hookmethod
=dyld
214 check_define __FreeBSD__
&& bsd_detected
=true
215 check_define __OpenBSD__
&& {
217 echo "CFLAGS+=-DIS_OPENBSD">>config.mak
218 check_compile_run
'whether OpenBSDs fclose() (illegally) calls close()' \
219 '#include <stdio.h>\n#include<stdlib.h>\nint close(int x){exit(0);}int main(){fclose(stdin);return 1;}' && \
220 OUR_CPPFLAGS
="$OUR_CPPFLAGS -DBROKEN_FCLOSE"
222 check_define __sun
&& check_define __SVR4
&& solaris_detected
=true
223 check_define __HAIKU__
&& haiku_detected
=true
225 echo "CC=$CC">>config.mak
226 [ -z "$CPPFLAGS" ] ||
echo "CPPFLAGS=$CPPFLAGS">>config.mak
227 [ -z "$CFLAGS" ] ||
echo "USER_CFLAGS=$CFLAGS">>config.mak
228 [ -z "$LDFLAGS" ] ||
echo "USER_LDFLAGS=$LDFLAGS">>config.mak
229 echo prefix
=$prefix>>config.mak
230 echo exec_prefix
=$exec_prefix>>config.mak
231 echo bindir
=$bindir>>config.mak
232 echo libdir
=$libdir>>config.mak
233 echo includedir
=$includedir>>config.mak
234 echo sysconfdir
=$sysconfdir>>config.mak
235 [ "$ignore_cve" = "no" ] && echo "CPPFLAGS+= -DSUPER_SECURE">>config.mak
236 [ -z "$OUR_CPPFLAGS" ] ||
echo "CPPFLAGS+= $OUR_CPPFLAGS" >>config.mak
238 check_link
"whether we can use -Wl,--no-as-needed" "-Wl,--no-as-needed" \
239 "int main() { return 0; }" ||
echo NO_AS_NEEDED
= >> config.mak
242 printf "checking what's the option to use in linker to set library name ... "
243 for o
in --soname -h -soname -install_name; do
244 check_link_silent
"-shared -Wl,$o,libconftest.so" "void test_func(int a) {}" && LD_SONAME_FLAG
=$o && break
246 if [ -z "$LD_SONAME_FLAG" ]; then
247 printf '\ncannot find an option to set library name\n'
250 echo "$LD_SONAME_FLAG"
251 echo "LD_SET_SONAME = -Wl,$LD_SONAME_FLAG," >> config.mak
253 if check_link
"checking whether we can use -ldl" "-ldl" \
254 "int main(){return 0;}" ; then
255 echo "LIBDL = -ldl" >> config.mak
258 if check_link
"checking whether we can use -lpthread" "-lpthread" \
259 "int main(){return 0;}" ; then
260 echo "PTHREAD = -lpthread" >> config.mak
262 check_link
"checking whether we can use -pthread" "-pthread" \
263 "int main(){return 0;}" || fail
"no pthread support detected"
264 echo "PTHREAD = -pthread" >> config.mak
269 echo LDSO_SUFFIX
=dylib
>>config.mak
270 echo MAC_CFLAGS
+=-DIS_MAC=1>>config.mak
271 if test "$hookmethod" = dyld
; then
272 echo "using Monterey style DYLD hooking"
273 echo "CFLAGS+=-DMONTEREY_HOOKING">>config.mak
275 if ismac64
&& [ "$fat_binary" = 1 ] ; then
276 echo "Configuring a fat binary for i386 and x86_64"
277 echo "MAC_CFLAGS+=-arch i386 -arch x86_64">>config.mak
278 echo "LDFLAGS+=-arch i386 -arch x86_64">>config.mak
281 echo LIBDL
=>>config.mak
282 echo "CFLAGS+=-DIS_BSD">>config.mak
285 echo "CFLAGS+=-DIS_SOLARIS -D__EXTENSIONS__" >> config.mak
286 echo "SOCKET_LIBS=-lsocket -lnsl" >> config.mak
288 echo LIBDL
=>>config.mak
289 echo "CFLAGS+=-DIS_HAIKU" >> config.mak
292 echo "Done, now run $make_cmd && $make_cmd install"