-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·279 lines (231 loc) · 7.52 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#! /bin/sh
usage () {
cat <<EOF
Usage: $0 [option]... [var=value]... [target]
In order to set environment variables (like CC), you have to specify them as
var=value. See below for descriptions of some of them.
Default values are specified in brackets.
Configuration settings:
--srcdir=dir source directory [auto detected]
Installation directories:
--prefix=prefix main installation prefix [/usr/local]
--libdir=dir library files [prefix/lib]
--includedir=dir include files [prefix/include]
System types:
--target=target configure to run on target [auto detected]
--host=host same as target
--build=build build system, used to detect cross compiling
Optional features:
--enable-debug build with debug symbols [no]
--enable-warnings build with extensive warnings [yes]
--enable-shared build shared library [yes]
--enable-static build static library [no]
--max-deltas=N maximum number of temporary deltas
--max-operations=N maximum number of operations before flushing
Environment variables you may set:
CC C compiler [auto detected]
CFLAGS C compiler flags [-O2 -pipe ...]
CROSS_COMPILE prefix for cross compiler and tools [not set]
These variables may be set to override detections made by configure.
EOF
exit 0
}
quote () {
tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
$1
EOF
printf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#"
}
echo () { printf "%s\n" "$*" ; }
fail () { echo "$*" ; exit 1 ; }
fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
cmdexists () { type "$1" >/dev/null 2>&1 ; }
tryc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; }
stripdir () {
while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
}
tryflag () {
printf "checking whether compiler accepts %s... " "$2"
echo "typedef int x;" > "$tsrc"
if $CC $CFLAGS_TRY $2 -c -o /dev/null "$tsrc" >/dev/null 2>&1 ; then
printf "yes\n"
eval "$1=\"\${$1} \$2\""
eval "$1=\${$1# }"
return 0
else
printf "no\n"
return 1
fi
}
CFLAGS_EXTRA=
CFLAGS_AUTO=
CFLAGS_TRY=
srcdir=
prefix=/usr/local
libdir='$(prefix)/lib'
includedir='$(prefix)/include'
debug=no
warnings=yes
shared=yes
static=no
maxdeltas=256
maxops=1024
for arg ; do
case "$arg" in
--help|-h) usage ;;
--srcdir=*) srcdir=${arg#*=} ;;
--prefix=*) prefix=${arg#*=} ;;
--libdir=*) libdir=${arg#*=} ;;
--includedir=*) includedir=${arg#*=} ;;
--syslibdir=*) syslibdir=${arg#*=} ;;
--enable-shared|--enable-shared=yes) shared=yes ;;
--disable-shared|--enable-shared=no) shared=no ;;
--enable-static|--enable-static=yes) static=yes ;;
--disable-static|--enable-static=no) static=no ;;
--enable-debug|--enable-debug=yes) debug=yes ;;
--disable-debug|--enable-debug=no) debug=no ;;
--enable-warnings|--enable-warnings=yes) warnings=yes ;;
--disable-warnings|--enable-warnings=no) warnings=no ;;
--enable-*|--disable-*|--with-*|--without-*|--*dir=*) ;;
--host=*|--target=*) target=${arg#*=} ;;
--build=*) build=${arg#*=} ;;
--max-deltas=*) maxdeltas=${arg#*=} ;;
--max-operations=*) maxops=${arg#*=} ;;
-* ) fail "$0: unknown option '$arg'" ;;
CC=*) CC=${arg#*=} ;;
CFLAGS=*) CFLAGS=${arg#*=} ;;
LDFLAGS=*) LDFLAGS=${arg#*=} ;;
CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;;
*=*) ;;
*) build=$arg ; target=$arg ;;
esac
done
for i in srcdir prefix libdir includedir ; do
stripdir $i
done
# See if we're building out of tree.
if test -z "$srcdir" ; then
srcdir="${0%/configure}"
stripdir srcdir
fi
abs_builddir="$(pwd)" || fail "$0: cannot determine working directory"
abs_srcdir="$(cd $srcdir && pwd)" || fail "$0: invalid source directory $srcdir"
test "$abs_srcdir" = "$abs_builddir" && srcdir=.
test "$srcdir" != "." -a -f Makefile -a ! -h Makefile && fail "$0: Makefile already exists in the working directory"
# Generate a temporary directory.
set -C
tdir=$(mktemp -d "$(basename $0).XXXXXXX")
set +C
trap 'rm -rf "$tdir"' EXIT INT QUIT TERM HUP
tsrc="$tdir/tx.c"
texe="$tdir/texe"
# For cross-compiling, set a default CROSS_COMPILE if it wasn't provided.
test "$target" && \
test "$target" != "$build" && \
test -z "$CROSS_COMPILE" && \
CROSS_COMPILE="$target-"
# Set C compiler.
printf "checking for C compiler..."
tryc ${CROSS_COMPILE}gcc
tryc ${CROSS_COMPILE}clang
tryc ${CROSS_COMPILE}icc
tryc ${CROSS_COMPILE}cc
printf "%s\n" "$CC"
test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
printf "checking whether C compiler works... "
echo "typedef int x;" > "$tsrc"
if output=$($CC $CFLAGS -c -o /dev/null "$tsrc" 2>&1) ; then
printf "yes\n"
else
printf "no; compiler output follows:\n%s\n" "$output"
exit 1
fi
printf "checking whether C11 threads are available..."
cat > "$tsrc" <<- EOM
#include <threads.h>
#include <stdatomic.h>
int main (void) { return (0); }
EOM
if output=$($CC $CFLAGS -c -o /dev/null "$tsrc" 2>&1) ; then
printf "yes\n"
CFLAGS_AUTO="$CFLAGS_AUTO -DSREF_USE_C11"
else
printf "no\n"
fi
printf "checking whether pthreads are available..."
cat > "$tsrc" <<- EOM
#include <pthread.h>
int main (void) { return (0); }
EOM
if output=$($CC $CFLAGS -c -o /dev/null "$tsrc" 2>&1) ; then
printf "yes\n"
CFLAGS_AUTO="$CFLAGS_AUTO -DSREF_USE_PTHREADS"
else
printf "no\n"
fi
# Find out options to force errors on unknown compiler/linker flags.
tryflag CFLAGS_TRY -Werror=unknown-warning-option
tryflag CFLAGS_TRY -Werror=unused-command-line-argument
tryflag CFLAGS_TRY -Werror=ignored-optimization-argument
# Try to avoid executable stacks in GNU compilers.
tryflag CFLAGS_EXTRA -Wa,--noexecstack
# See if the compiler accepts explicit standard versioning
tryflag CFLAGS -std=c11
if [ $? -ne 0 ]; then
tryflag CFLAGS -std=c99
fi
# Enable optimizations
tryflag CFLAGS -O2
# Enable debugging if needed.
test "x$debug" = xyes && tryflag CFLAGS_AUTO -g
# Always try to use -pipe.
tryflag CFLAGS_AUTO -pipe
# See if we can link against pthreads with a compiler switch.
tryflag CFLAGS_AUTO -pthread
if test "x$warnings" = xyes ; then
tryflag CFLAGS_AUTO -Wall
tryflag CFLAGS_AUTO -Wno-parentheses
tryflag CFLAGS_AUTO -Wno-uninitialized
tryflag CFLAGS_AUTO -Wno-missing-braces
tryflag CFLAGS_AUTO -Wno-unused-value
tryflag CFLAGS_AUTO -Wno-unused-but-set-variable
tryflag CFLAGS_AUTO -Wno-unknown-pragmas
fi
case $maxdeltas in
''|*[!0-9]*) fail "--max-deltas must be an integer" ;;
*) ;;
esac
case $maxops in
''|*[!0-9]*) fail "--max-operations must be an integer" ;;
*) ;;
esac
# generate version file
version=$(cat $srcdir/VERSION)
major=$(echo $version | cut -d. -f1)
minor=$(echo $version | cut -d. -f2)
echo "const int MAJOR = $major; const int MINOR = $minor;" > $srcdir/version.h
printf "creating config.mak... "
cmdline=$(quote "$0")
for i ; do cmdline="$cmdline $(quote "$i")" ; done
exec 3>&1 1>config.mak
cat << EOF
# This version of config.mak was generated by:
# $cmdline
# Any changes made here will be lost if configure is re-run
srcdir = $srcdir
prefix = $prefix
libdir = $libdir
includedir = $includedir
CC = $CC
CFLAGS = $CFLAGS -DSREF_NDELTAS=$maxdeltas -DSREF_NMAXOPS=$maxops
CFLAGS_AUTO = $CFLAGS_AUTO
CFLAGS_EXTRA = $CFLAGS_EXTRA
LDFLAGS = $LDFLAGS
CROSS_COMPILE = $CROSS_COMPILE
EOF
test "x$static" = xno && echo "STATIC_LIBS ="
test "x$shared" = xno && echo "SHARED_LIBS ="
test "x$shared" = xno && echo 'TEST_OBJS = $(OBJS)'
exec 1>&3 3>&-
test "$srcdir" = "." || ln -sf $srcdir/Makefile .
printf "done\n"