fix wrong prototype of freeaddrinfo_t
[rofl0r-proxychains-ng.git] / configure
blob7ceb122e928810e92da6913ec6c1a805f9841138
1 #!/bin/sh
3 prefix=/usr/local
4 OUR_CPPFLAGS=
6 # Get a temporary filename
7 fail() { printf "%s\n" "$1" >&2 ; exit 1 ; }
8 i=0
9 set -C
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"
14 done
15 set +C
16 trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
18 check_compile() {
19 printf "checking %s ... " "$1"
20 printf "$3" > "$tmpc"
21 local res=0
22 $CC $OUR_CPPFLAGS $CPPFLAGS $2 $CFLAGS "$tmpc" -o "$tmpc".out >/dev/null 2>&1 \
23 || res=1
24 test x$res = x0 && \
25 { printf "yes\n" ; test x"$2" = x || OUR_CPPFLAGS="$OUR_CPPFLAGS $2" ; } \
26 || printf "no\n"
27 rm -f "$tmpc".out
28 return $res
31 get_define() {
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/^.* .* //'
41 check_define() {
42 printf "checking whether \$CC defines %s ... " "$1"
43 local res=1
44 get_define "$1" >/dev/null && res=0
45 test x$res = x0 && printf "yes\n" || printf "no\n"
46 return $res
49 check_compile_run() {
50 printf "checking %s ... " "$1"
51 printf "$2" > "$tmpc"
52 local res=0
53 $CC $OUR_CPPFLAGS $CPPFLAGS $CFLAGS "$tmpc" -o "$tmpc".out >/dev/null 2>&1 \
54 || res=1
55 test x$res = x0 && { "$tmpc".out || res=1 ; }
56 rm -f "$tmpc".out
57 test x$res = x0 && printf "yes\n" || printf "no\n"
58 return $res
61 check_link_silent() {
62 printf "$2" > "$tmpc"
63 local res=0
64 $CC $OUR_CPPFLAGS $CPPFLAGS $1 $CFLAGS "$tmpc" -o "$tmpc".out >/dev/null 2>&1 || res=1
65 rm -f "$tmpc".out
66 return $res
69 check_link() {
70 printf "checking %s ... " "$1"
71 local res=0
72 check_link_silent "$2" "$3" || res=1
73 test x$res = x0 && printf "yes\n" || printf "no\n"
74 return $res
77 usage() {
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 "--fat-binary-m1 : build for both arm64e and x86_64 architectures on M1 Macs"
90 echo "--hookmethod=dlsym|dyld hook method for osx. default: auto"
91 echo " if OSX >= 12 is detected, dyld method will be used if auto."
92 echo "--help : show this text"
93 exit 1
96 spliteq() {
97 arg=$1
98 echo "${arg#*=}"
99 #alternatives echo "$arg" | cut -d= -f2-
100 # or echo "$arg" | sed 's/[^=]*=//'
103 fat_binary=
104 fat_binary_m1=
105 ignore_cve=no
106 hookmethod=auto
108 parsearg() {
109 case "$1" in
110 --prefix=*) prefix=`spliteq $1`;;
111 --exec_prefix=*) exec_prefix=`spliteq $1`;;
112 --bindir=*) bindir=`spliteq $1`;;
113 --libdir=*) libdir=`spliteq $1`;;
114 --includedir=*) includedir=`spliteq $1`;;
115 --sysconfdir=*) sysconfdir=`spliteq $1`;;
116 --ignore-cve) ignore_cve=1;;
117 --ignore-cve=*) ignore_cve=`spliteq $1`;;
118 --hookmethod=*) hookmethod=`spliteq $1`;;
119 --fat-binary) fat_binary=1;;
120 --fat-binary-m1) fat_binary_m1=1;;
121 --help) usage;;
122 esac
125 while true ; do
126 case $1 in
127 -*) parsearg "$1"; shift;;
128 *) break ;;
129 esac
130 done
132 if [ -z "$exec_prefix" ] ; then
133 exec_prefix=$prefix
136 if [ -z "$libdir" ] ; then
137 libdir=$prefix/lib
140 if [ -z "$includedir" ] ; then
141 includedir=$prefix/include
144 if [ -z "$sysconfdir" ] ; then
145 sysconfdir=$prefix/etc
148 if [ -z "$bindir" ] ; then
149 bindir=$exec_prefix/bin
152 if [ -z "$CC" ] ; then
153 CC=cc
156 echo > config.mak
158 bsd_detected=false
159 isbsd() {
160 $bsd_detected
162 mac_detected=false
163 ismac() {
164 $mac_detected
166 mac_64=false
167 ismac64() {
168 $mac_64
170 solaris_detected=false
171 issolaris() {
172 $solaris_detected
174 haiku_detected=false
175 ishaiku() {
176 $haiku_detected
179 check_compile 'whether C compiler works' '' 'int main() {return 0;}' || fail 'error: install a C compiler and library'
180 check_compile 'whether libc headers are complete' '' '#include <netdb.h>\nint main() {return 0;}' || fail 'error: necessary libc headers are not installed'
181 check_compile 'whether C compiler understands -Wno-unknown-pragmas' '-Wno-unknown-pragmas' 'int main() {return 0;}'
183 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" \
184 '#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
185 # GLIBC < 2.14
186 if ! check_compile 'whether getnameinfo() flags argument is unsigned' "-DGN_NODELEN_T=socklen_t -DGN_SERVLEN_T=socklen_t -DGN_FLAGS_T=unsigned" \
187 '#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
188 if ! check_compile 'whether getnameinfo() servlen argument is size_t' "-DGN_NODELEN_T=socklen_t -DGN_SERVLEN_T=size_t -DGN_FLAGS_T=int" \
189 '#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
190 # OpenBSD & FreeBSD
191 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" \
192 '#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
193 fail "failed to detect getnameinfo signature"
199 check_compile 'whether we have GNU-style getservbyname_r()' "-DHAVE_GNU_GETSERVBYNAME_R" \
200 '#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;}'
202 check_compile 'whether we have pipe2() and O_CLOEXEC' "-DHAVE_PIPE2" \
203 '#define _GNU_SOURCE\n#include <fcntl.h>\n#include <unistd.h>\nint main() {\nint pipefd[2];\npipe2(pipefd, O_CLOEXEC);\nreturn 0;}'
205 check_compile 'whether we have SOCK_CLOEXEC' "-DHAVE_SOCK_CLOEXEC" \
206 '#define _GNU_SOURCE\n#include <sys/socket.h>\nint main() {\nreturn socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, 0);}'
208 check_compile 'whether we have clock_gettime' "-DHAVE_CLOCK_GETTIME" \
209 '#define _GNU_SOURCE\n#include <time.h>\nint main() {\nstruct timespec now;clock_gettime(CLOCK_REALTIME, &now);\nreturn now.tv_sec ^ now.tv_nsec;}'
211 check_define __APPLE__ && {
212 mac_detected=true
213 check_define __x86_64__ && mac_64=true
214 if test "$hookmethod" = auto ; then
215 osver=$(get_define_stripped __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 2>/dev/null)
216 test "$osver" -gt $((120000 - 1)) && hookmethod=dyld
219 check_define __FreeBSD__ && bsd_detected=true
220 check_define __OpenBSD__ && {
221 bsd_detected=true
222 echo "CFLAGS+=-DIS_OPENBSD">>config.mak
223 check_compile_run 'whether OpenBSDs fclose() (illegally) calls close()' \
224 '#include <stdio.h>\n#include<stdlib.h>\nint close(int x){exit(0);}int main(){fclose(stdin);return 1;}' && \
225 OUR_CPPFLAGS="$OUR_CPPFLAGS -DBROKEN_FCLOSE"
227 check_define __sun && check_define __SVR4 && solaris_detected=true
228 check_define __HAIKU__ && haiku_detected=true
230 echo "CC=$CC">>config.mak
231 [ -z "$CPPFLAGS" ] || echo "CPPFLAGS=$CPPFLAGS">>config.mak
232 [ -z "$CFLAGS" ] || echo "USER_CFLAGS=$CFLAGS">>config.mak
233 [ -z "$LDFLAGS" ] || echo "USER_LDFLAGS=$LDFLAGS">>config.mak
234 echo prefix=$prefix>>config.mak
235 echo exec_prefix=$exec_prefix>>config.mak
236 echo bindir=$bindir>>config.mak
237 echo libdir=$libdir>>config.mak
238 echo includedir=$includedir>>config.mak
239 echo sysconfdir=$sysconfdir>>config.mak
240 [ "$ignore_cve" = "no" ] && echo "CPPFLAGS+= -DSUPER_SECURE">>config.mak
241 [ -z "$OUR_CPPFLAGS" ] || echo "CPPFLAGS+= $OUR_CPPFLAGS" >>config.mak
243 check_link "whether we can use -Wl,--no-as-needed" "-Wl,--no-as-needed" \
244 "int main() { return 0; }" || echo NO_AS_NEEDED= >> config.mak
246 LD_SONAME_FLAG=
247 printf "checking what's the option to use in linker to set library name ... "
248 for o in --soname -h -soname -install_name; do
249 check_link_silent "-shared -Wl,$o,libconftest.so" "void test_func(int a) {}" && LD_SONAME_FLAG=$o && break
250 done
251 if [ -z "$LD_SONAME_FLAG" ]; then
252 printf '\ncannot find an option to set library name\n'
253 exit 1
255 echo "$LD_SONAME_FLAG"
256 echo "LD_SET_SONAME = -Wl,$LD_SONAME_FLAG," >> config.mak
258 if check_link "checking whether we can use -ldl" "-ldl" \
259 "int main(){return 0;}" ; then
260 echo "LIBDL = -ldl" >> config.mak
263 if check_link "checking whether we can use -lpthread" "-lpthread" \
264 "int main(){return 0;}" ; then
265 echo "PTHREAD = -lpthread" >> config.mak
266 else
267 check_link "checking whether we can use -pthread" "-pthread" \
268 "int main(){return 0;}" || fail "no pthread support detected"
269 echo "PTHREAD = -pthread" >> config.mak
272 make_cmd=make
273 if ismac ; then
274 echo LDSO_SUFFIX=dylib>>config.mak
275 echo MAC_CFLAGS+=-DIS_MAC=1>>config.mak
276 if test "$hookmethod" = dyld ; then
277 echo "using Monterey style DYLD hooking"
278 echo "CFLAGS+=-DMONTEREY_HOOKING">>config.mak
280 if ismac64 && [ "$fat_binary" = 1 ] ; then
281 echo "Configuring a fat binary for i386 and x86_64"
282 echo "MAC_CFLAGS+=-arch i386 -arch x86_64">>config.mak
283 echo "FAT_LDFLAGS=-arch i386 -arch x86_64">>config.mak
284 echo "FAT_BIN_LDFLAGS=-arch i386 -arch x86_64">>config.mak
286 if [ "$fat_binary_m1" = 1 ] ; then
287 echo "Configuring a fat binary for arm64[e] and x86_64"
288 echo "MAC_CFLAGS+=-arch arm64 -arch arm64e -arch x86_64">>config.mak
289 echo "FAT_LDFLAGS=-arch arm64 -arch arm64e -arch x86_64">>config.mak
290 echo "FAT_BIN_LDFLAGS=-arch arm64 -arch x86_64">>config.mak
292 elif isbsd ; then
293 echo LIBDL=>>config.mak
294 echo "CFLAGS+=-DIS_BSD">>config.mak
295 make_cmd=gmake
296 elif issolaris; then
297 echo "CFLAGS+=-DIS_SOLARIS -D__EXTENSIONS__" >> config.mak
298 echo "SOCKET_LIBS=-lsocket -lnsl" >> config.mak
299 elif ishaiku ; then
300 echo LIBDL=>>config.mak
301 echo "CFLAGS+=-DIS_HAIKU" >> config.mak
304 echo "Done, now run $make_cmd && $make_cmd install"