util.encodings: Spell out all IDNA 2008 options ICU has
[prosody.git] / configure
blob2b58efe5d0c1e54ea415544744651a4e3b2a533a
1 #!/bin/sh
3 # Defaults
5 APP_NAME="Prosody"
6 APP_DIRNAME="prosody"
7 PREFIX="/usr/local"
8 SYSCONFDIR="$PREFIX/etc/$APP_DIRNAME"
9 LIBDIR="$PREFIX/lib"
10 DATADIR="$PREFIX/var/lib/$APP_DIRNAME"
11 LUA_SUFFIX=""
12 LUA_DIR="/usr"
13 LUA_BINDIR="/usr/bin"
14 LUA_INCDIR="/usr/include"
15 LUA_LIBDIR="/usr/lib"
16 IDN_LIB="idn"
17 ICU_FLAGS="-licui18n -licudata -licuuc"
18 OPENSSL_LIB="crypto"
19 CC="gcc"
20 LD="gcc"
21 RUNWITH="lua"
22 EXCERTS="yes"
23 PRNG=
24 PRNGLIBS=
26 CFLAGS="-fPIC -std=c99"
27 CFLAGS="$CFLAGS -Wall -pedantic -Wextra -Wshadow -Wformat=2"
28 LDFLAGS="-shared"
30 IDN_LIBRARY="idn"
31 # Help
33 show_help() {
34 cat <<EOF
35 Configure $APP_NAME prior to building.
37 --help This help.
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.
41 Default is $PREFIX
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.
58 Default is $RUNWITH
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.
64 Default is $IDN_LIB
65 --idn-library=(idn|icu) Select library to use for IDNA functionality.
66 idn: use GNU libidn (default)
67 icu: use ICU from IBM
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
76 Default is $CFLAGS
77 --add-cflags=FLAGS Adds additional CFLAGS, preserving defaults.
78 Can be repeated.
79 --ldflags=FLAGS Flags to pass to the linker
80 Default is $LDFLAGS
81 --add-ldflags=FLAGS Adds additional linker flags, preserving defaults.
82 Can be repeated.
83 --c-compiler=CC The C compiler to use when building modules.
84 Default is $CC
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.
88 Default is $LD
89 --no-example-certs Disables generation of example certificates.
90 EOF
93 # Helper functions
95 find_program() {
96 prog=$(command -v "$1" 2>/dev/null)
97 if [ -n "$prog" ]
98 then
99 dirname "$prog"
103 die() {
104 echo "$*"
105 echo
106 echo "configure failed."
107 echo
108 exit 1
111 # shellcheck disable=SC2039
112 case $(echo -n x) in
113 -n*) echo_n_flag='';;
114 *) echo_n_flag='-n';;
115 esac
117 echo_n() {
118 echo $echo_n_flag "$*"
121 # ----------------------------------------------------------------------------
122 # MAIN PROGRAM
123 # ----------------------------------------------------------------------------
125 # Parse options
127 while [ -n "$1" ]
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
133 then
134 echo
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.'
138 echo
140 case "$key" in
141 --help)
142 show_help
143 exit 0
145 --prefix)
146 [ -n "$value" ] || die "Missing value in flag $key."
147 PREFIX="$value"
148 PREFIX_SET=yes
150 --sysconfdir)
151 [ -n "$value" ] || die "Missing value in flag $key."
152 SYSCONFDIR="$value"
153 SYSCONFDIR_SET=yes
155 --ostype)
156 OSPRESET="$value"
157 OSPRESET_SET="yes"
159 --libdir)
160 LIBDIR="$value"
161 LIBDIR_SET=yes
163 --datadir)
164 DATADIR="$value"
165 DATADIR_SET=yes
167 --lua-suffix)
168 [ -n "$value" ] || die "Missing value in flag $key."
169 LUA_SUFFIX="$value"
170 LUA_SUFFIX_SET=yes
172 --lua-version|--with-lua-version)
173 [ -n "$value" ] || die "Missing value in flag $key."
174 LUA_VERSION="$value"
175 [ "$LUA_VERSION" = "5.1" ] || [ "$LUA_VERSION" = "5.2" ] || [ "$LUA_VERSION" = "5.3" ] || [ "$LUA_VERSION" = "5.4" ] || die "Invalid Lua version in flag $key."
176 LUA_VERSION_SET=yes
178 --with-lua)
179 [ -n "$value" ] || die "Missing value in flag $key."
180 LUA_DIR="$value"
181 LUA_DIR_SET=yes
183 --with-lua-bin)
184 [ -n "$value" ] || die "Missing value in flag $key."
185 LUA_BINDIR="$value"
186 LUA_BINDIR_SET=yes
188 --with-lua-include)
189 [ -n "$value" ] || die "Missing value in flag $key."
190 LUA_INCDIR="$value"
191 LUA_INCDIR_SET=yes
193 --with-lua-lib)
194 [ -n "$value" ] || die "Missing value in flag $key."
195 LUA_LIBDIR="$value"
196 LUA_LIBDIR_SET=yes
198 --with-idn)
199 IDN_LIB="$value"
201 --idn-library)
202 IDN_LIBRARY="$value"
204 --with-ssl)
205 OPENSSL_LIB="$value"
207 --with-random)
208 case "$value" in
209 getrandom)
210 PRNG=GETRANDOM
212 openssl)
213 PRNG=OPENSSL
215 arc4random)
216 PRNG=ARC4RANDOM
218 esac
220 --cflags)
221 CFLAGS="$value"
223 --add-cflags)
224 CFLAGS="$CFLAGS $value"
226 --ldflags)
227 LDFLAGS="$value"
229 --add-ldflags)
230 LDFLAGS="$LDFLAGS $value"
232 --c-compiler)
233 CC="$value"
235 --linker)
236 LD="$value"
238 --runwith)
239 RUNWITH="$value"
240 RUNWITH_SET=yes
242 --no-example-certs)
243 EXCERTS=
245 --compiler-wrapper)
246 CC="$value $CC"
247 LD="$value $LD"
250 die "Error: Unknown flag: $1"
252 esac
253 shift
254 done
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;
264 LUA_INCDIR_SET=yes
266 if [ "$LUA_LIBDIR_SET" != "yes" ]; then
267 LUA_LIBDIR=/usr/local/lib
268 LUA_LIBDIR_SET=yes
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"
278 LUA_INCDIR_SET=yes
279 CFLAGS="-Wall -fPIC -I/usr/local/include"
280 LDFLAGS="-I/usr/local/include -L/usr/local/lib -shared"
281 LUA_SUFFIX="51"
282 LUA_SUFFIX_SET=yes
283 LUA_DIR=/usr/local
284 LUA_DIR_SET=yes
285 CC=cc
286 LD=ld
288 if [ "$OSPRESET" = "openbsd" ]; then
289 LUA_INCDIR="/usr/local/include";
290 LUA_INCDIR_SET="yes"
292 if [ "$OSPRESET" = "netbsd" ]; then
293 LUA_INCDIR="/usr/pkg/include/lua-5.1"
294 LUA_INCDIR_SET=yes
295 LUA_LIBDIR="/usr/pkg/lib/lua/5.1"
296 LUA_LIBDIR_SET=yes
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
302 LUA_SUFFIX="5.1";
303 LUA_SUFFIX_SET=yes
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
309 LUA_INCDIR="$LUA_CF"
310 LUA_INCDIR_SET=yes
312 CFLAGS="$CFLAGS"
316 if [ "$PREFIX_SET" = "yes" ] && [ ! "$SYSCONFDIR_SET" = "yes" ]
317 then
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" ]
325 then
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" ]
333 then
334 LIBDIR=$PREFIX/lib
337 detect_lua_version() {
338 detected_lua=$("$1" -e 'print(_VERSION:match(" (5%.[1234])$"))' 2> /dev/null)
339 if [ "$detected_lua" != "nil" ]
340 then
341 if [ "$LUA_VERSION_SET" != "yes" ]
342 then
343 echo "Lua version detected: $detected_lua"
344 LUA_VERSION=$detected_lua
345 return 0
346 elif [ "$LUA_VERSION" = "$detected_lua" ]
347 then
348 return 0
351 return 1
354 search_interpreter() {
355 suffix="$1"
356 if [ "$LUA_BINDIR_SET" = "yes" ]
357 then
358 find_lua="$LUA_BINDIR"
359 elif [ "$LUA_DIR_SET" = "yes" ]
360 then
361 LUA_BINDIR="$LUA_DIR/bin"
362 if [ -f "$LUA_BINDIR/lua$suffix" ]
363 then
364 find_lua="$LUA_BINDIR"
366 else
367 find_lua=$(find_program lua"$suffix")
369 if [ -n "$find_lua" ] && [ -x "$find_lua/lua$suffix" ]
370 then
371 if detect_lua_version "$find_lua/lua$suffix"
372 then
373 echo "Lua interpreter found: $find_lua/lua$suffix..."
374 if [ "$LUA_BINDIR_SET" != "yes" ]
375 then
376 LUA_BINDIR="$find_lua"
378 if [ "$LUA_DIR_SET" != "yes" ]
379 then
380 LUA_DIR=$(dirname "$find_lua")
382 LUA_SUFFIX="$suffix"
383 return 0
386 return 1
389 lua_interp_found=no
390 if [ "$LUA_SUFFIX_SET" != "yes" ]
391 then
392 if [ "$LUA_VERSION_SET" = "yes" ] && [ "$LUA_VERSION" = "5.1" ]
393 then
394 suffixes="5.1 51 -5.1 -51"
395 elif [ "$LUA_VERSION_SET" = "yes" ] && [ "$LUA_VERSION" = "5.2" ]
396 then
397 suffixes="5.2 52 -5.2 -52"
398 elif [ "$LUA_VERSION_SET" = "yes" ] && [ "$LUA_VERSION" = "5.3" ]
399 then
400 suffixes="5.3 53 -5.3 -53"
401 elif [ "$LUA_VERSION_SET" = "yes" ] && [ "$LUA_VERSION" = "5.4" ]
402 then
403 suffixes="5.4 54 -5.4 -54"
404 else
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" && {
413 lua_interp_found=yes
414 break
416 done
417 else
418 search_interpreter "$LUA_SUFFIX" && {
419 lua_interp_found=yes
423 # See #1353
424 if [ "$LUA_DIR_SET" != "yes" ] && [ "$LUA_DIR" = "/" ]
425 then
426 LUA_DIR="/usr"
430 if [ "$lua_interp_found" != "yes" ] && [ "$RUNWITH_SET" != "yes" ]
431 then
432 if [ "$LUA_VERSION_SET" ]; then
433 interp="Lua $LUA_VERSION";
434 else
435 interp="Lua";
437 if [ "$LUA_DIR_SET" ] || [ "$LUA_BINDIR_SET" ]; then
438 where="$LUA_BINDIR";
439 else
440 where="\$PATH";
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" ]
447 then
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"
450 then
451 echo "yes"
452 else
453 echo "no"
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" ]
459 then
460 LUA_INCDIR="$LUA_DIR/include"
463 if [ "$LUA_LIBDIR_SET" != "yes" ]
464 then
465 LUA_LIBDIR="$LUA_DIR/lib"
468 lua_h="$LUA_INCDIR/lua.h"
469 echo_n "Looking for lua.h at $lua_h..."
470 if [ -f "$lua_h" ]
471 then
472 echo found
473 else
474 echo "not found"
475 for postfix in "$LUA_VERSION" "$LUA_SUFFIX"; do
476 if ! [ "$postfix" = "" ]; then
477 v_dir="$LUA_INCDIR/lua/$postfix";
478 else
479 v_dir="$LUA_INCDIR/lua";
481 lua_h="$v_dir/lua.h"
482 echo_n "Looking for lua.h at $lua_h..."
483 if [ -f "$lua_h" ]
484 then
485 LUA_INCDIR="$v_dir"
486 echo found
487 break;
488 else
489 echo "not found"
490 d_dir="$LUA_INCDIR/lua$postfix"
491 lua_h="$d_dir/lua.h"
492 echo_n "Looking for lua.h at $lua_h..."
493 if [ -f "$lua_h" ]
494 then
495 echo found
496 LUA_INCDIR="$d_dir"
497 break;
498 else
499 echo "not found"
502 done
503 if [ ! -f "$lua_h" ]; then
504 echo "lua.h not found."
505 echo
506 die "You may want to use the flag --with-lua or --with-lua-include. See --help."
510 if [ "$lua_interp_found" = "yes" ]
511 then
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" ]
515 then
516 echo "yes"
517 else
518 echo "no"
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" ]
525 then
526 IDNA_LIBS="$ICU_FLAGS"
527 CFLAGS="$CFLAGS -DUSE_STRINGPREP_ICU"
529 if [ "$IDN_LIBRARY" = "idn" ]
530 then
531 IDNA_LIBS="-l$IDN_LIB"
534 if [ -f config.unix ]; then
535 rm -f config.unix
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
547 PRNGLIBS="-lbsd"
550 # Write config
552 echo "Writing configuration..."
553 echo
555 rm -f built
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
561 PREFIX=$PREFIX
562 SYSCONFDIR=$SYSCONFDIR
563 LIBDIR=$LIBDIR
564 DATADIR=$DATADIR
565 LUA_SUFFIX=$LUA_SUFFIX
566 LUA_DIR=$LUA_DIR
567 LUA_DIR_SET=$LUA_DIR_SET
568 LUA_INCDIR=$LUA_INCDIR
569 LUA_LIBDIR=$LUA_LIBDIR
570 LUA_BINDIR=$LUA_BINDIR
571 IDN_LIB=$IDN_LIB
572 IDNA_LIBS=$IDNA_LIBS
573 OPENSSL_LIBS=$OPENSSL_LIBS
574 CFLAGS=$CFLAGS
575 LDFLAGS=$LDFLAGS
576 CC=$CC
577 LD=$LD
578 RUNWITH=$RUNWITH
579 EXCERTS=$EXCERTS
580 RANDOM=$PRNG
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
592 echo
593 echo "Done. You can now run 'make' to build."
594 echo