examples/portscanner: quick hack to make it work on single host/portrange
[rofl0r-rocksock.git] / configure
blob15bc27a0d265140d5b0cc30e7e07f014dc5819fc
1 #!/bin/sh
2 #set -x
3 prefix=/usr/local
5 libs=`cat << EOF
6 EOF
8 clear_config() {
9 rm -f config.mak 2>/dev/null
12 add_config() {
13 printf "%s\n" "$1" >> config.mak
16 add_cflags() {
17 add_config "CFLAGS += $1"
20 add_ldflags() {
21 add_config "LDFLAGS += $1"
24 get_pkgconf_cflags() {
25 pkg-config --cflags "$1" 2>/dev/null
28 get_pkgconf_ldflags() {
29 pkg-config --libs "$1" 2>/dev/null
32 add_pkgconf_cflags() {
33 fallback="$2"
34 flags=$(get_pkgconf_cflags "$1")
35 [ -z "$flags" ] && flags="$fallback"
36 add_cflags "$flags"
39 add_pkgconf_ldflags() {
40 fallback="$2"
41 flags=$(get_pkgconf_ldflags "$1")
42 [ -z "$flags" ] && flags="$fallback"
43 add_ldflags "$flags"
46 add_lib() {
47 add_pkgconf_cflags "$1" "$2"
48 add_pkgconf_ldflags "$1" "$3"
49 return 0
52 usage() {
53 echo "supported arguments"
54 echo "--prefix=/path default: $prefix"
55 echo "--exec_prefix=/path default: $prefix/bin"
56 echo "--bindir=/path default: $prefix/bin"
57 echo "--libdir=/path default: $prefix/lib"
58 echo "--includedir=/path default: $prefix/include"
59 echo "--sysconfdir=/path default: $prefix/etc"
60 echo "--with-ssl=[auto,wolfssl,openssl,no] default: auto"
61 echo "--disable-static default: no"
62 echo "--enable-shared default: no"
63 echo "--help : show this text"
64 exit 1
67 spliteq() {
68 arg=$1
69 echo "${arg#*=}"
70 #alternatives echo "$arg" | cut -d= -f2-
71 # or echo "$arg" | sed 's/[^=]*=//'
74 trylink () {
75 printf "checking whether linking against %s works... " "$2"
76 echo "int main(){};" > "$tmpc"
77 if $CC "$2" -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
78 printf "yes\n"
79 eval "$1=\"\${$1} \$2\""
80 eval "$1=\${$1# }"
81 return 0
82 else
83 printf "no\n"
84 return 1
88 ssl_lib=auto
89 parsearg() {
90 case "$1" in
91 --prefix=*) prefix=`spliteq $1`;;
92 --exec_prefix=*) exec_prefix=`spliteq $1`;;
93 --bindir=*) bindir=`spliteq $1`;;
94 --libdir=*) libdir=`spliteq $1`;;
95 --includedir=*) includedir=`spliteq $1`;;
96 --sysconfdir=*) sysconfdir=`spliteq $1`;;
97 --help) usage;;
98 --disable-static) disable_static=1 ;;
99 --disable-static=yes) disable_static=1 ;;
100 --enable-shared) enable_shared=1 ;;
101 --enable-shared=yes) enable_shared=1 ;;
102 --with-ssl=*) ssl_lib=`spliteq $1`;;
103 esac
106 while true ; do
107 case $1 in
108 -*) parsearg "$1"; shift;;
109 *) break ;;
110 esac
111 done
113 [ -z "$exec_prefix" ] && exec_prefix=$prefix
114 [ -z "$libdir" ] && libdir=$prefix/lib
115 [ -z "$includedir" ] && includedir=$prefix/include
116 [ -z "$sysconfdir" ] && sysconfdir=$prefix/etc
117 [ -z "$bindir" ] && bindir=$exec_prefix/bin
118 [ -z "$CC" ] && CC=cc
120 clear_config
122 add_config "prefix = $prefix"
123 add_config "exec_prefix = $exec_prefix"
124 add_config "bindir = $bindir"
125 add_config "libdir = $libdir"
126 add_config "includedir = $includedir"
127 add_config "sysconfdir = $sysconfdir"
129 add_config "CC ?= $CC"
130 [ -z "$CPPFLAGS" ] || add_config "CPPFLAGS += $CPPFLAGS"
131 [ -z "$CFLAGS" ] || add_cflags "$CFLAGS"
133 for lib in $libs ; do add_lib "$lib" ; done
136 # Get a temp filename we can use
139 set -C
140 while : ; do i=$(($i+1))
141 tmpc="./conf$$-$PPID-$i.c"
142 2>|/dev/null > "$tmpc" && break
143 test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
144 done
145 set +C
146 trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
149 if [ "$ssl_lib" = auto ] ; then
150 foo=
151 if trylink foo "-lwolfssl" ; then ssl_lib=cyassl
152 elif trylink foo "-lssl" && trylink foo "-lcrypto" ; then ssl_lib=openssl
153 else ssl_lib=no
156 if [ ! "$ssl_lib" = no ] ; then
157 add_config "CFLAGS += -DUSE_SSL"
158 case "$ssl_lib" in
159 openssl) add_lib openssl "" "-lssl -lcrypto" && add_cflags "-DUSE_OPENSSL" ;;
160 cyassl|wolfssl) add_lib wolfssl "" "-lwolfssl" && add_cflags "-DUSE_CYASSL" ;;
161 *) echo "error: unsupported --with-ssl option $ssl_lib" ; exit 1 ;;
162 esac
164 [ "$disable_static" = 1 ] && add_config "ALL_LIBS =" && enable_shared=1
165 [ "$enable_shared" = 1 ] && add_config "ALL_LIBS += librocksock.so"
168 echo "hint: if you intend to build a static binary with minimal size, try NO_DNS_SUPPORT in CFLAGS"
169 echo "config.mak successfully created. now run make && make install"