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 -std=c99"
27 CFLAGS
="$CFLAGS -Wall -pedantic -Wextra -Wshadow -Wformat=2"
35 Configure $APP_NAME prior to building.
38 --ostype=OS Use one of the OS presets. May be one of:
39 debian, macosx, linux, freebsd, openbsd, netbsd
40 --prefix=DIR Prefix where $APP_NAME should be installed.
42 --sysconfdir=DIR Location where the config file should be installed.
43 Default is \$PREFIX/etc/$APP_DIRNAME
44 --libdir=DIR Location where the server files should be stored.
45 Default is \$PREFIX/lib
46 --datadir=DIR Location where the server data should be stored.
47 Default is \$PREFIX/var/lib/$APP_DIRNAME
48 --lua-version=VERSION Use specific Lua version: 5.1, 5.2, or 5.3
49 Default is auto-detected.
50 --lua-suffix=SUFFIX Versioning suffix to use in Lua filenames.
51 Default is "$LUA_SUFFIX" (lua$LUA_SUFFIX...)
52 --with-lua=PREFIX Use Lua from given prefix.
53 Default is auto-detected (the parent directory of \$LUA_BINDIR).
54 --with-lua-bin=DIR You can also specify Lua's bin dir.
55 Default is the directory of the auto-detected Lua interpreter,
56 or \$LUA_DIR/bin if --with-lua is used.
57 --runwith=BINARY What Lua binary to set as runtime environment.
59 --with-lua-include=DIR You can also specify Lua's includes dir.
60 Default is \$LUA_DIR/include
61 --with-lua-lib=DIR You can also specify Lua's libraries dir.
62 Default is \$LUA_DIR/lib
63 --with-idn=LIB The name of the IDN library to link with.
65 --idn-library=(idn|icu) Select library to use for IDNA functionality.
66 idn: use GNU libidn (default)
68 --with-ssl=LIB The name of the SSL to link with.
69 Default is $OPENSSL_LIB
70 --with-random=METHOD CSPRNG backend to use. One of
71 getrandom: Linux kernel
72 arc4random: OpenBSD kernel
73 openssl: OpenSSL RAND method
74 Default is to use /dev/urandom
75 --cflags=FLAGS Flags to pass to the compiler
77 --add-cflags=FLAGS Adds additional CFLAGS, preserving defaults.
79 --ldflags=FLAGS Flags to pass to the linker
81 --add-ldflags=FLAGS Adds additional linker flags, preserving defaults.
83 --c-compiler=CC The C compiler to use when building modules.
85 --compiler-wrapper=WRAPPER Adds a prefix to compiler and linker calls,
86 usable for eg distcc or ccache.
87 --linker=CC The linker to use when building modules.
89 --no-example-certs Disables generation of example certificates.
96 prog
=$
(command -v "$1" 2>/dev
/null
)
106 echo "configure failed."
111 # shellcheck disable=SC2039
113 -n*) echo_n_flag
='';;
114 *) echo_n_flag
='-n';;
118 echo $echo_n_flag "$*"
121 # ----------------------------------------------------------------------------
123 # ----------------------------------------------------------------------------
129 value
=$
(echo "$1" |
sed 's/[^=]*.\(.*\)/\1/')
130 key
=$
(echo "$1" |
sed 's/=.*//')
131 # shellcheck disable=SC2088
132 if echo "$value" |
grep "~" >/dev
/null
2>/dev
/null
135 echo '*WARNING*: the "~" sign is not expanded in flags.'
136 # shellcheck disable=SC2016
137 echo 'If you mean the home directory, use $HOME instead.'
146 [ -n "$value" ] || die
"Missing value in flag $key."
151 [ -n "$value" ] || die
"Missing value in flag $key."
168 [ -n "$value" ] || die
"Missing value in flag $key."
172 --lua-version|
--with-lua-version)
173 [ -n "$value" ] || die
"Missing value in flag $key."
175 [ "$LUA_VERSION" = "5.1" ] ||
[ "$LUA_VERSION" = "5.2" ] ||
[ "$LUA_VERSION" = "5.3" ] ||
[ "$LUA_VERSION" = "5.4" ] || die
"Invalid Lua version in flag $key."
179 [ -n "$value" ] || die
"Missing value in flag $key."
184 [ -n "$value" ] || die
"Missing value in flag $key."
189 [ -n "$value" ] || die
"Missing value in flag $key."
194 [ -n "$value" ] || die
"Missing value in flag $key."
224 CFLAGS
="$CFLAGS $value"
230 LDFLAGS
="$LDFLAGS $value"
250 die
"Error: Unknown flag: $1"
256 if [ "$OSPRESET_SET" = "yes" ]; then
257 # TODO make this a switch?
258 if [ "$OSPRESET" = "debian" ]; then
259 CFLAGS
="$CFLAGS -ggdb"
261 if [ "$OSPRESET" = "macosx" ]; then
262 if [ "$LUA_INCDIR_SET" != "yes" ]; then
263 LUA_INCDIR
=/usr
/local
/include
;
266 if [ "$LUA_LIBDIR_SET" != "yes" ]; then
267 LUA_LIBDIR
=/usr
/local
/lib
270 CFLAGS
="$CFLAGS -mmacosx-version-min=10.3"
271 LDFLAGS
="-bundle -undefined dynamic_lookup"
273 if [ "$OSPRESET" = "linux" ]; then
274 CFLAGS
="$CFLAGS -ggdb"
276 if [ "$OSPRESET" = "freebsd" ] ||
[ "$OSPRESET" = "openbsd" ]; then
277 LUA_INCDIR
="/usr/local/include/lua51"
279 CFLAGS
="-Wall -fPIC -I/usr/local/include"
280 LDFLAGS
="-I/usr/local/include -L/usr/local/lib -shared"
288 if [ "$OSPRESET" = "openbsd" ]; then
289 LUA_INCDIR
="/usr/local/include";
292 if [ "$OSPRESET" = "netbsd" ]; then
293 LUA_INCDIR
="/usr/pkg/include/lua-5.1"
295 LUA_LIBDIR
="/usr/pkg/lib/lua/5.1"
297 CFLAGS
="-Wall -fPIC -I/usr/pkg/include"
298 LDFLAGS
="-L/usr/pkg/lib -Wl,-rpath,/usr/pkg/lib -shared"
300 if [ "$OSPRESET" = "pkg-config" ]; then
301 if [ "$LUA_SUFFIX_SET" != "yes" ]; then
305 LUA_CF
="$(pkg-config --cflags-only-I lua$LUA_SUFFIX)"
306 LUA_CF
="${LUA_CF#*-I}"
307 LUA_CF
="${LUA_CF%% *}"
308 if [ "$LUA_CF" != "" ]; then
316 if [ "$PREFIX_SET" = "yes" ] && [ ! "$SYSCONFDIR_SET" = "yes" ]
318 if [ "$PREFIX" = "/usr" ]
319 then SYSCONFDIR
=/etc
/$APP_DIRNAME
320 else SYSCONFDIR
=$PREFIX/etc
/$APP_DIRNAME
324 if [ "$PREFIX_SET" = "yes" ] && [ ! "$DATADIR_SET" = "yes" ]
326 if [ "$PREFIX" = "/usr" ]
327 then DATADIR
=/var
/lib
/$APP_DIRNAME
328 else DATADIR
=$PREFIX/var
/lib
/$APP_DIRNAME
332 if [ "$PREFIX_SET" = "yes" ] && [ ! "$LIBDIR_SET" = "yes" ]
337 detect_lua_version
() {
338 detected_lua
=$
("$1" -e 'print(_VERSION:match(" (5%.[1234])$"))' 2> /dev
/null
)
339 if [ "$detected_lua" != "nil" ]
341 if [ "$LUA_VERSION_SET" != "yes" ]
343 echo "Lua version detected: $detected_lua"
344 LUA_VERSION
=$detected_lua
346 elif [ "$LUA_VERSION" = "$detected_lua" ]
354 search_interpreter
() {
356 if [ "$LUA_BINDIR_SET" = "yes" ]
358 find_lua
="$LUA_BINDIR"
359 elif [ "$LUA_DIR_SET" = "yes" ]
361 LUA_BINDIR
="$LUA_DIR/bin"
362 if [ -f "$LUA_BINDIR/lua$suffix" ]
364 find_lua
="$LUA_BINDIR"
367 find_lua
=$
(find_program lua
"$suffix")
369 if [ -n "$find_lua" ] && [ -x "$find_lua/lua$suffix" ]
371 if detect_lua_version
"$find_lua/lua$suffix"
373 echo "Lua interpreter found: $find_lua/lua$suffix..."
374 if [ "$LUA_BINDIR_SET" != "yes" ]
376 LUA_BINDIR
="$find_lua"
378 if [ "$LUA_DIR_SET" != "yes" ]
380 LUA_DIR
=$
(dirname "$find_lua")
390 if [ "$LUA_SUFFIX_SET" != "yes" ]
392 if [ "$LUA_VERSION_SET" = "yes" ] && [ "$LUA_VERSION" = "5.1" ]
394 suffixes
="5.1 51 -5.1 -51"
395 elif [ "$LUA_VERSION_SET" = "yes" ] && [ "$LUA_VERSION" = "5.2" ]
397 suffixes
="5.2 52 -5.2 -52"
398 elif [ "$LUA_VERSION_SET" = "yes" ] && [ "$LUA_VERSION" = "5.3" ]
400 suffixes
="5.3 53 -5.3 -53"
401 elif [ "$LUA_VERSION_SET" = "yes" ] && [ "$LUA_VERSION" = "5.4" ]
403 suffixes
="5.4 54 -5.4 -54"
405 suffixes
="5.1 51 -5.1 -51"
406 suffixes
="$suffixes 5.2 52 -5.2 -52"
407 suffixes
="$suffixes 5.3 53 -5.3 -53"
408 suffixes
="$suffixes 5.4 54 -5.4 -54"
410 for suffix
in "" $suffixes
412 search_interpreter
"$suffix" && {
418 search_interpreter
"$LUA_SUFFIX" && {
424 if [ "$LUA_DIR_SET" != "yes" ] && [ "$LUA_DIR" = "/" ]
430 if [ "$lua_interp_found" != "yes" ] && [ "$RUNWITH_SET" != "yes" ]
432 if [ "$LUA_VERSION_SET" ]; then
433 interp
="Lua $LUA_VERSION";
437 if [ "$LUA_DIR_SET" ] ||
[ "$LUA_BINDIR_SET" ]; then
442 echo "$interp interpreter not found in $where"
443 die
"You may want to use the flags --with-lua, --with-lua-bin and/or --lua-suffix. See --help."
446 if [ "$LUA_VERSION_SET" = "yes" ] && [ "$RUNWITH_SET" != "yes" ]
448 echo_n
"Checking if $LUA_BINDIR/lua$LUA_SUFFIX is Lua version $LUA_VERSION... "
449 if detect_lua_version
"$LUA_BINDIR/lua$LUA_SUFFIX"
454 die
"You may want to use the flags --with-lua, --with-lua-bin and/or --lua-suffix. See --help."
458 if [ "$LUA_INCDIR_SET" != "yes" ]
460 LUA_INCDIR
="$LUA_DIR/include"
463 if [ "$LUA_LIBDIR_SET" != "yes" ]
465 LUA_LIBDIR
="$LUA_DIR/lib"
468 lua_h
="$LUA_INCDIR/lua.h"
469 echo_n
"Looking for lua.h at $lua_h..."
475 for postfix
in "$LUA_VERSION" "$LUA_SUFFIX"; do
476 if ! [ "$postfix" = "" ]; then
477 v_dir
="$LUA_INCDIR/lua/$postfix";
479 v_dir
="$LUA_INCDIR/lua";
482 echo_n
"Looking for lua.h at $lua_h..."
490 d_dir
="$LUA_INCDIR/lua$postfix"
492 echo_n
"Looking for lua.h at $lua_h..."
503 if [ ! -f "$lua_h" ]; then
504 echo "lua.h not found."
506 die
"You may want to use the flag --with-lua or --with-lua-include. See --help."
510 if [ "$lua_interp_found" = "yes" ]
512 echo_n
"Checking if Lua header version matches that of the interpreter... "
513 header_version
=$
(sed -n 's/.*LUA_VERSION_NUM.*5.\(.\).*/5.\1/p' "$lua_h")
514 if [ "$header_version" = "$LUA_VERSION" ]
519 echo "lua.h version mismatch (interpreter: $LUA_VERSION; lua.h: $header_version)."
520 die
"You may want to use the flag --with-lua or --with-lua-include. See --help."
524 if [ "$IDN_LIBRARY" = "icu" ]
526 IDNA_LIBS
="$ICU_FLAGS"
527 CFLAGS
="$CFLAGS -DUSE_STRINGPREP_ICU"
529 if [ "$IDN_LIBRARY" = "idn" ]
531 IDNA_LIBS
="-l$IDN_LIB"
534 if [ -f config.unix
]; then
538 if [ "$RUNWITH_SET" != yes ]; then
539 RUNWITH
="lua$LUA_SUFFIX"
542 OPENSSL_LIBS
="-l$OPENSSL_LIB"
544 if [ "$PRNG" = "OPENSSL" ]; then
545 PRNGLIBS
=$OPENSSL_LIBS
546 elif [ "$PRNG" = "ARC4RANDOM" ] && [ "$(uname)" = "Linux" ]; then
552 echo "Writing configuration..."
556 cat <<EOF > config.unix
557 # This file was automatically generated by the configure script.
558 # Run "./configure --help" for details.
560 LUA_VERSION=$LUA_VERSION
562 SYSCONFDIR=$SYSCONFDIR
565 LUA_SUFFIX=$LUA_SUFFIX
567 LUA_DIR_SET=$LUA_DIR_SET
568 LUA_INCDIR=$LUA_INCDIR
569 LUA_LIBDIR=$LUA_LIBDIR
570 LUA_BINDIR=$LUA_BINDIR
573 OPENSSL_LIBS=$OPENSSL_LIBS
581 RANDOM_LIBS=$PRNGLIBS
586 echo "Installation prefix: $PREFIX"
587 echo "$APP_NAME configuration directory: $SYSCONFDIR"
588 echo "Using Lua from: $LUA_DIR"
590 make clean
> /dev
/null
2> /dev
/null
593 echo "Done. You can now run 'make' to build."