8 SYSCONFDIR
="$PREFIX/etc/$APP_DIRNAME"
10 DATADIR
="$PREFIX/var/lib/$APP_DIRNAME"
14 LUA_INCDIR
="/usr/include"
17 ICU_FLAGS
="-licui18n -licudata -licuuc"
26 CFLAGS
="-fPIC -Wall -pedantic -std=c99"
34 Configure $APP_NAME prior to building.
37 --ostype=OS Use one of the OS presets. May be one of:
38 debian, macosx, linux, freebsd, openbsd, netbsd
39 --prefix=DIR Prefix where $APP_NAME should be installed.
41 --sysconfdir=DIR Location where the config file should be installed.
42 Default is \$PREFIX/etc/$APP_DIRNAME
43 --libdir=DIR Location where the server files should be stored.
44 Default is \$PREFIX/lib
45 --datadir=DIR Location where the server data should be stored.
46 Default is \$PREFIX/var/lib/$APP_DIRNAME
47 --lua-version=VERSION Use specific Lua version: 5.1, 5.2, or 5.3
48 Default is auto-detected.
49 --lua-suffix=SUFFIX Versioning suffix to use in Lua filenames.
50 Default is "$LUA_SUFFIX" (lua$LUA_SUFFIX...)
51 --with-lua=PREFIX Use Lua from given prefix.
52 Default is auto-detected (the parent directory of \$LUA_BINDIR).
53 --with-lua-bin=DIR You can also specify Lua's bin dir.
54 Default is the directory of the auto-detected Lua interpreter,
55 or \$LUA_DIR/bin if --with-lua is used.
56 --runwith=BINARY What Lua binary to set as runtime environment.
58 --with-lua-include=DIR You can also specify Lua's includes dir.
59 Default is \$LUA_DIR/include
60 --with-lua-lib=DIR You can also specify Lua's libraries dir.
61 Default is \$LUA_DIR/lib
62 --with-idn=LIB The name of the IDN library to link with.
64 --idn-library=(idn|icu) Select library to use for IDNA functionality.
65 idn: use GNU libidn (default)
67 --with-ssl=LIB The name of the SSL to link with.
68 Default is $OPENSSL_LIB
69 --with-random=METHOD CSPRNG backend to use. One of
70 getrandom: Linux kernel
71 arc4random: OpenBSD kernel
72 openssl: OpenSSL RAND method
73 Default is to use /dev/urandom
74 --cflags=FLAGS Flags to pass to the compiler
76 --add-cflags=FLAGS Adds additional CFLAGS, preserving defaults.
78 --ldflags=FLAGS Flags to pass to the linker
80 --add-ldflags=FLAGS Adds additional linker flags, preserving defaults.
82 --c-compiler=CC The C compiler to use when building modules.
84 --compiler-wrapper=WRAPPER Adds a prefix to compiler and linker calls,
85 usable for eg distcc or ccache.
86 --linker=CC The linker to use when building modules.
88 --no-example-certs Disables generation of example certificates.
95 prog
=$
(command -v "$1" 2>/dev
/null
)
105 echo "configure failed."
110 # shellcheck disable=SC2039
112 -n*) echo_n_flag
='';;
113 *) echo_n_flag
='-n';;
117 echo $echo_n_flag "$*"
120 # ----------------------------------------------------------------------------
122 # ----------------------------------------------------------------------------
128 value
=$
(echo "$1" |
sed 's/[^=]*.\(.*\)/\1/')
129 key
=$
(echo "$1" |
sed 's/=.*//')
130 # shellcheck disable=SC2088
131 if echo "$value" |
grep "~" >/dev
/null
2>/dev
/null
134 echo '*WARNING*: the "~" sign is not expanded in flags.'
135 # shellcheck disable=SC2016
136 echo 'If you mean the home directory, use $HOME instead.'
145 [ -n "$value" ] || die
"Missing value in flag $key."
150 [ -n "$value" ] || die
"Missing value in flag $key."
155 # TODO make this a switch?
157 if [ "$OSPRESET" = "debian" ]; then
158 if [ "$LUA_SUFFIX_SET" != "yes" ]; then
162 if [ "$RUNWITH_SET" != "yes" ]; then
163 RUNWITH
="lua$LUA_SUFFIX";
166 LUA_INCDIR
="/usr/include/lua$LUA_SUFFIX"
168 CFLAGS
="$CFLAGS -ggdb"
170 if [ "$OSPRESET" = "macosx" ]; then
171 LUA_INCDIR
=/usr
/local
/include
;
173 LUA_LIBDIR
=/usr
/local
/lib
175 CFLAGS
="$CFLAGS -mmacosx-version-min=10.3"
176 LDFLAGS
="-bundle -undefined dynamic_lookup"
178 if [ "$OSPRESET" = "linux" ]; then
179 LUA_INCDIR
=/usr
/local
/include
;
181 LUA_LIBDIR
=/usr
/local
/lib
183 CFLAGS
="$CFLAGS -ggdb"
185 if [ "$OSPRESET" = "freebsd" ] ||
[ "$OSPRESET" = "openbsd" ]; then
186 LUA_INCDIR
="/usr/local/include/lua51"
188 CFLAGS
="-Wall -fPIC -I/usr/local/include"
189 LDFLAGS
="-I/usr/local/include -L/usr/local/lib -shared"
197 if [ "$OSPRESET" = "openbsd" ]; then
198 LUA_INCDIR
="/usr/local/include";
201 if [ "$OSPRESET" = "netbsd" ]; then
202 LUA_INCDIR
="/usr/pkg/include/lua-5.1"
204 LUA_LIBDIR
="/usr/pkg/lib/lua/5.1"
206 CFLAGS
="-Wall -fPIC -I/usr/pkg/include"
207 LDFLAGS
="-L/usr/pkg/lib -Wl,-rpath,/usr/pkg/lib -shared"
209 if [ "$OSPRESET" = "pkg-config" ]; then
210 if [ "$LUA_SUFFIX_SET" != "yes" ]; then
214 LUA_CF
="$(pkg-config --cflags-only-I lua$LUA_SUFFIX)"
215 LUA_CF
="${LUA_CF#*-I}"
216 LUA_CF
="${LUA_CF%% *}"
217 if [ "$LUA_CF" != "" ]; then
233 [ -n "$value" ] || die
"Missing value in flag $key."
237 --lua-version|
--with-lua-version)
238 [ -n "$value" ] || die
"Missing value in flag $key."
240 [ "$LUA_VERSION" = "5.1" ] ||
[ "$LUA_VERSION" = "5.2" ] ||
[ "$LUA_VERSION" = "5.3" ] || die
"Invalid Lua version in flag $key."
244 [ -n "$value" ] || die
"Missing value in flag $key."
249 [ -n "$value" ] || die
"Missing value in flag $key."
254 [ -n "$value" ] || die
"Missing value in flag $key."
259 [ -n "$value" ] || die
"Missing value in flag $key."
289 CFLAGS
="$CFLAGS $value"
295 LDFLAGS
="$LDFLAGS $value"
315 die
"Error: Unknown flag: $1"
321 if [ "$PREFIX_SET" = "yes" ] && [ ! "$SYSCONFDIR_SET" = "yes" ]
323 if [ "$PREFIX" = "/usr" ]
324 then SYSCONFDIR
=/etc
/$APP_DIRNAME
325 else SYSCONFDIR
=$PREFIX/etc
/$APP_DIRNAME
329 if [ "$PREFIX_SET" = "yes" ] && [ ! "$DATADIR_SET" = "yes" ]
331 if [ "$PREFIX" = "/usr" ]
332 then DATADIR
=/var
/lib
/$APP_DIRNAME
333 else DATADIR
=$PREFIX/var
/lib
/$APP_DIRNAME
337 if [ "$PREFIX_SET" = "yes" ] && [ ! "$LIBDIR_SET" = "yes" ]
342 detect_lua_version
() {
343 detected_lua
=$
("$1" -e 'print(_VERSION:match(" (5%.[123])$"))' 2> /dev
/null
)
344 if [ "$detected_lua" != "nil" ]
346 if [ "$LUA_VERSION_SET" != "yes" ]
348 echo "Lua version detected: $detected_lua"
349 LUA_VERSION
=$detected_lua
351 elif [ "$LUA_VERSION" = "$detected_lua" ]
359 search_interpreter
() {
361 if [ "$LUA_BINDIR_SET" = "yes" ]
363 find_lua
="$LUA_BINDIR"
364 elif [ "$LUA_DIR_SET" = "yes" ]
366 LUA_BINDIR
="$LUA_DIR/bin"
367 if [ -f "$LUA_BINDIR/lua$suffix" ]
369 find_lua
="$LUA_BINDIR"
372 find_lua
=$
(find_program lua
"$suffix")
374 if [ -n "$find_lua" ] && [ -x "$find_lua/lua$suffix" ]
376 if detect_lua_version
"$find_lua/lua$suffix"
378 echo "Lua interpreter found: $find_lua/lua$suffix..."
379 if [ "$LUA_BINDIR_SET" != "yes" ]
381 LUA_BINDIR
="$find_lua"
383 if [ "$LUA_DIR_SET" != "yes" ]
385 LUA_DIR
=$
(dirname "$find_lua")
395 if [ "$LUA_SUFFIX_SET" != "yes" ]
397 if [ "$LUA_VERSION_SET" = "yes" ] && [ "$LUA_VERSION" = "5.1" ]
399 suffixes
="5.1 51 -5.1 -51"
400 elif [ "$LUA_VERSION_SET" = "yes" ] && [ "$LUA_VERSION" = "5.2" ]
402 suffixes
="5.2 52 -5.2 -52"
403 elif [ "$LUA_VERSION_SET" = "yes" ] && [ "$LUA_VERSION" = "5.3" ]
405 suffixes
="5.3 53 -5.3 -53"
407 suffixes
="5.1 51 -5.1 -51 5.2 52 -5.2 -52 5.3 53 -5.3 -53"
409 for suffix
in "" $suffixes
411 search_interpreter
"$suffix" && {
417 search_interpreter
"$LUA_SUFFIX" && {
423 if [ "$LUA_DIR_SET" != "yes" ] && [ "$LUA_DIR" = "/" ]
429 if [ "$lua_interp_found" != "yes" ] && [ "$RUNWITH_SET" != "yes" ]
431 if [ "$LUA_VERSION_SET" ]; then
432 interp
="Lua $LUA_VERSION";
436 if [ "$LUA_DIR_SET" ] ||
[ "$LUA_BINDIR_SET" ]; then
441 echo "$interp interpreter not found in $where"
442 die
"You may want to use the flags --with-lua, --with-lua-bin and/or --lua-suffix. See --help."
445 if [ "$LUA_VERSION_SET" = "yes" ] && [ "$RUNWITH_SET" != "yes" ]
447 echo_n
"Checking if $LUA_BINDIR/lua$LUA_SUFFIX is Lua version $LUA_VERSION... "
448 if detect_lua_version
"$LUA_BINDIR/lua$LUA_SUFFIX"
453 die
"You may want to use the flags --with-lua, --with-lua-bin and/or --lua-suffix. See --help."
457 if [ "$LUA_INCDIR_SET" != "yes" ]
459 LUA_INCDIR
="$LUA_DIR/include"
462 if [ "$LUA_LIBDIR_SET" != "yes" ]
464 LUA_LIBDIR
="$LUA_DIR/lib"
467 echo_n
"Checking Lua includes... "
468 lua_h
="$LUA_INCDIR/lua.h"
471 echo "lua.h found in $lua_h"
473 v_dir
="$LUA_INCDIR/lua/$LUA_VERSION"
477 echo "lua.h found in $lua_h"
480 d_dir
="$LUA_INCDIR/lua$LUA_VERSION"
484 echo "lua.h found in $lua_h (Debian/Ubuntu)"
487 echo "lua.h not found (looked in $LUA_INCDIR, $v_dir, $d_dir)"
488 die
"You may want to use the flag --with-lua or --with-lua-include. See --help."
493 if [ "$lua_interp_found" = "yes" ]
495 echo_n
"Checking if Lua header version matches that of the interpreter... "
496 header_version
=$
(sed -n 's/.*LUA_VERSION_NUM.*5.\(.\).*/5.\1/p' "$lua_h")
497 if [ "$header_version" = "$LUA_VERSION" ]
502 echo "lua.h version mismatch (interpreter: $LUA_VERSION; lua.h: $header_version)."
503 die
"You may want to use the flag --with-lua or --with-lua-include. See --help."
507 if [ "$IDN_LIBRARY" = "icu" ]
509 IDNA_LIBS
="$ICU_FLAGS"
510 CFLAGS
="$CFLAGS -DUSE_STRINGPREP_ICU"
512 if [ "$IDN_LIBRARY" = "idn" ]
514 IDNA_LIBS
="-l$IDN_LIB"
517 if [ -f config.unix
]; then
521 if [ "$RUNWITH_SET" != yes ]; then
522 RUNWITH
="lua$LUA_SUFFIX"
525 OPENSSL_LIBS
="-l$OPENSSL_LIB"
527 if [ "$PRNG" = "OPENSSL" ]; then
528 PRNGLIBS
=$OPENSSL_LIBS
529 elif [ "$PRNG" = "ARC4RANDOM" ] && [ "$(uname)" = "Linux" ]; then
535 echo "Writing configuration..."
539 cat <<EOF > config.unix
540 # This file was automatically generated by the configure script.
541 # Run "./configure --help" for details.
543 LUA_VERSION=$LUA_VERSION
545 SYSCONFDIR=$SYSCONFDIR
548 LUA_SUFFIX=$LUA_SUFFIX
550 LUA_DIR_SET=$LUA_DIR_SET
551 LUA_INCDIR=$LUA_INCDIR
552 LUA_LIBDIR=$LUA_LIBDIR
553 LUA_BINDIR=$LUA_BINDIR
556 OPENSSL_LIBS=$OPENSSL_LIBS
564 RANDOM_LIBS=$PRNGLIBS
569 echo "Installation prefix: $PREFIX"
570 echo "$APP_NAME configuration directory: $SYSCONFDIR"
571 echo "Using Lua from: $LUA_DIR"
573 make clean
> /dev
/null
2> /dev
/null
576 echo "Done. You can now run 'make' to build."