-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfigure
executable file
·382 lines (328 loc) · 8.24 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#!/bin/sh
# Based on the configure script from musl libc, MIT licensed
usage() {
cat <<EOF
Usage: $0 [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
--srcdir=DIR source directory [detected]
Installation directories:
--prefix=PREFIX main installation prefix [/usr/local]
--exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sharedir=DIR share directories [PREFIX/share]
--docdir=DIR misc. documentation [PREFIX/share/doc]
--mandir=DIR man pages [PREFIX/share/man]
Some influential environment variables:
CC C compiler command [detected]
CFLAGS C compiler flags [-Os -pipe ...]
LDFLAGS Linker flags
Use these variables to override the choices made by configure.
EOF
exit 0
}
# helper functions
quote() {
tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && {
$1
EOF
echo "$1"
return 0
}
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; }
trycc() { 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;" >"$tmpc"
if $CC $CFLAGS_TRY $2 -c -o "$tmpo" "$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
}
tryldflag() {
printf "checking whether linker accepts %s... " "$2"
echo "typedef int x;" >"$tmpc"
if $CC $LDFLAGS_TRY -nostdlib -shared "$2" -o "$tmpo" "$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
}
check_lpeg() {
printf " checking for lpeg... "
ccflags=$1
shift
llflags=$@
cat >"$tmpc" <<EOF
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <assert.h>
int main() {
lua_State *L = luaL_newstate();
luaL_openlibs(L);
int reqRes = luaL_dostring(L, "local t=require('lpeg') return (t~=nil)");
assert(reqRes == 0);
return 0;
}
EOF
if $CC $CFLAGS $ccflags "$tmpc" \
$LDFLAGS $llflags -o "$tmpo" >/dev/null 2>&1; then
eval $tmpo >/dev/null 2>&1
if test $? -eq 0; then
return 1
fi
fi
return 0
}
check_luautf8() {
printf " checking for luautf8... "
ccflags=$1
shift
llflags=$@
cat >"$tmpc" <<EOF
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <assert.h>
int main() {
lua_State *L = luaL_newstate();
luaL_openlibs(L);
int reqRes = luaL_dostring(L, "local t=require('lua-utf8') return (t~=nil)");
assert(reqRes == 0);
return 0;
}
EOF
if $CC $CFLAGS $ccflags "$tmpc" \
$LDFLAGS $llflags -o "$tmpo" >/dev/null 2>&1; then
eval $tmpo >/dev/null 2>&1
if test $? -eq 0; then
return 1
fi
fi
return 0
}
# start of script
CFLAGS_AUTO=
CFLAGS_TRY=
LDFLAGS_AUTO=
LDFLAGS_TRY=
SRCDIR=
PREFIX=/usr/local
EXEC_PREFIX='$(PREFIX)'
BINDIR='$(EXEC_PREFIX)/bin'
SHAREDIR='$(PREFIX)/share'
DOCDIR='$(PREFIX)/share/doc'
MANDIR='$(PREFIX)/share/man'
for arg; do
case "$arg" in
--srcdir=*) SRCDIR=${arg#*=} ;;
--prefix=*) PREFIX=${arg#*=} ;;
--exec-prefix=*) EXEC_PREFIX=${arg#*=} ;;
--bindir=*) BINDIR=${arg#*=} ;;
--sharedir=*) SHAREDIR=${arg#*=} ;;
--docdir=*) DOCDIR=${arg#*=} ;;
--mandir=*) MANDIR=${arg#*=} ;;
--environment-only) environmentonly=yes ;;
--enable-* | --disable-* | --with-* | --without-* | --*dir=* | --build=*) ;;
-*) echo "$0: unknown option $arg" ;;
CC=*) CC=${arg#*=} ;;
CFLAGS=*) CFLAGS=${arg#*=} ;;
CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
LDFLAGS=*) LDFLAGS=${arg#*=} ;;
*=*) ;;
*) ;;
esac
done
for i in SRCDIR PREFIX EXEC_PREFIX BINDIR SHAREDIR DOCDIR MANDIR; do
stripdir $i
done
have_pkgconfig=no
printf "checking for pkg-config... "
cmdexists pkg-config && have_pkgconfig=yes
printf "%s\n" "$have_pkgconfig"
#
# Get the source dir for out-of-tree builds
#
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"
#
# Get a temp filename we can use
#
i=0
set -C
while :; do
i=$(($i + 1))
tmpc="./conf$$-$PPID-$i.c"
tmpo="./conf$$-$PPID-$i.o"
2>|/dev/null >"$tmpc" && break
test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
done
set +C
trap 'rm -f "$tmpc" "$tmpo"' EXIT QUIT TERM HUP
trap 'rm -f "$tmpc" "$tmpo" && echo && fail "$0: interrupted"' INT
#
# Find a C compiler to use
#
printf "checking for C compiler... "
trycc cc
trycc gcc
trycc clang
printf "after checking %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;" >"$tmpc"
if output=$($CC $CPPFLAGS $CFLAGS -c -o "$tmpo" "$tmpc" 2>&1); then
printf "yes\n"
else
printf "no; compiler output follows:\n%s\n" "$output"
exit 1
fi
tryflag CFLAGS -pipe
tryflag CFLAGS -Wall
tryflag CFLAGS -O2
#dead code elimination
tryflag CFLAGS -ffunction-sections
tryflag CFLAGS -fdata-sections
tryldflag LDFLAGS -Wl,--gc-sections
printf "creating config.mk... "
cmdline=$(quote "$0")
for i; do cmdline="$cmdline $(quote "$i")"; done
exec 3>&1 1>config.mk
cat <<EOF
# This version of config.mk was generated by:
# $cmdline
# Any changes made here will be lost if configure is re-run
ABS_SRCDIR = $abs_srcdir
SRCDIR = $SRCDIR
PREFIX = $PREFIX
EXEC_PREFIX = $EXEC_PREFIX
BINDIR = $BINDIR
DOCPREFIX = $DOCDIR
MANPREFIX = $MANDIR
SHAREPREFIX = $SHAREDIR
CC = $CC
CFLAGS = $CFLAGS
LDFLAGS = $LDFLAGS
CFLAGS_DEBUG = -U_FORTIFY_SOURCE -UNDEBUG -O0 -g3 -ggdb -Wall -Wextra -pedantic -Wno-missing-field-initializers -Wno-unused-parameter
EOF
exec 1>&3 3>&-
printf "done\n"
printf "checking for liblua >= 5.1 ...\n"
cat >"$tmpc" <<EOF
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#if LUA_VERSION_NUM < 501
#error "Need at least Lua 5.1"
#endif
int main(int argc, char *argv[]) {
lua_State *L = luaL_newstate();
luaL_openlibs(L);
lua_close(L);
return 0;
}
EOF
have_lua="no"
have_lpeg="no"
have_luautf8="no"
for liblua in luajit lua lua5.4 lua5.3 lua5.2 lua-5.4 lua-5.3 lua-5.2 lua54 lua53 lua52; do
printf " checking for %s... " "$liblua"
if test "$have_pkgconfig" = "yes"; then
CFLAGS_LUA=$(pkg-config --cflags $liblua 2>/dev/null)
LDFLAGS_LUA=$(pkg-config --libs $liblua 2>/dev/null)
else
CFLAGS_LUA=""
LDFLAGS_LUA="-l$liblua -lm -ldl"
fi
if test $? -eq 0 && $CC $CFLAGS $CFLAGS_LUA "$tmpc" \
$LDFLAGS $LDFLAGS_LUA -o "$tmpo" >/dev/null 2>&1; then
have_lua="yes"
printf "yes\n"
check_lpeg $CFLAGS_LUA $LDFLAGS_LUA
has_lpeg=$?
if (test $has_lpeg -gt 0); then
have_lpeg="yes"
printf "yes\n"
else
printf "no\n"
fi
check_luautf8 $CFLAGS_LUA $LDFLAGS_LUA
has_luautf8=$?
if (test $has_luautf8 -gt 0); then
have_luautf8="yes"
printf "yes\n"
else
printf "no"
fi
if (test $has_luautf8 -gt 0) && (test $has_lpeg -gt 0); then
break
fi
else
printf "no"
fi
printf "\n"
done
if test $have_lua = "no"; then
fail "Error: Lua was not found."
fi
if test $have_lpeg = "no"; then
fail "Error: Lua dependency LPEG was not found in any Lua installation."
fi
have_pcre2="no"
CFLAGS_PCRE2=""
LDFLAGS_PCRE2=""
printf "checking for pcre2..."
if pkg-config --exists check >/dev/null 2>&1; then
have_pcre2="yes"
CFLAGS_PCRE2=$(pkg-config --cflags libpcre2-8)
LDFLAGS_PCRE2=$(pkg-config --libs libpcre2-8)
echo "yes"
else
echo "no"
fi
printf "completing config.mk... "
exec 3>&1 1>>config.mk
cat <<EOF
CONFIG_HELP = $CONFIG_HELP
CONFIG_LUA = $CONFIG_LUA
CFLAGS_LUA = $CFLAGS_LUA
LDFLAGS_LUA = $LDFLAGS_LUA
CFLAGS_PCRE2 = $CFLAGS_PCRE2
LDFLAGS_PCRE2 = $LDFLAGS_PCRE2
EOF
exec 1>&3 3>&-
test "$SRCDIR" = "." || ln -sf $SRCDIR/Makefile .
printf "done\n"