Fix zsh completion file to proxychains4
[rofl0r-proxychains-ng.git] / configure
blob0102eb29d6e47a44965815804cdc65a2f5ae6546
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 "--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"
92 exit 1
95 spliteq() {
96 arg=$1
97 echo "${arg#*=}"
98 #alternatives echo "$arg" | cut -d= -f2-
99 # or echo "$arg" | sed 's/[^=]*=//'
102 fat_binary=
103 ignore_cve=no
104 hookmethod=auto
106 parsearg() {
107 case "$1" in
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;;
118 --help) usage;;
119 esac
122 while true ; do
123 case $1 in
124 -*) parsearg "$1"; shift;;
125 *) break ;;
126 esac
127 done
129 if [ -z "$exec_prefix" ] ; then
130 exec_prefix=$prefix
133 if [ -z "$libdir" ] ; then
134 libdir=$prefix/lib
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
150 CC=cc
153 echo > config.mak
155 bsd_detected=false
156 isbsd() {
157 $bsd_detected
159 mac_detected=false
160 ismac() {
161 $mac_detected
163 mac_64=false
164 ismac64() {
165 $mac_64
167 solaris_detected=false
168 issolaris() {
169 $solaris_detected
171 haiku_detected=false
172 ishaiku() {
173 $haiku_detected
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
180 # GLIBC < 2.14
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
185 # OpenBSD & FreeBSD
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__ && {
207 mac_detected=true
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__ && {
216 bsd_detected=true
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
241 LD_SONAME_FLAG=
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
245 done
246 if [ -z "$LD_SONAME_FLAG" ]; then
247 printf '\ncannot find an option to set library name\n'
248 exit 1
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
261 else
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
267 make_cmd=make
268 if ismac ; then
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
280 elif isbsd ; then
281 echo LIBDL=>>config.mak
282 echo "CFLAGS+=-DIS_BSD">>config.mak
283 make_cmd=gmake
284 elif issolaris; then
285 echo "CFLAGS+=-DIS_SOLARIS -D__EXTENSIONS__" >> config.mak
286 echo "SOCKET_LIBS=-lsocket -lnsl" >> config.mak
287 elif ishaiku ; then
288 echo LIBDL=>>config.mak
289 echo "CFLAGS+=-DIS_HAIKU" >> config.mak
292 echo "Done, now run $make_cmd && $make_cmd install"