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