MUC: Fix delay@from to be room JID (fixes #1416)
[prosody.git] / configure
blob0fe186b57075a8d69ebd61c49d1e8e5bef6b510d
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 -Wall -pedantic -std=c99"
27 LDFLAGS="-shared"
29 IDN_LIBRARY="idn"
30 # Help
32 show_help() {
33 cat <<EOF
34 Configure $APP_NAME prior to building.
36 --help This help.
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.
40 Default is $PREFIX
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.
57 Default is $RUNWITH
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.
63 Default is $IDN_LIB
64 --idn-library=(idn|icu) Select library to use for IDNA functionality.
65 idn: use GNU libidn (default)
66 icu: use ICU from IBM
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
75 Default is $CFLAGS
76 --add-cflags=FLAGS Adds additional CFLAGS, preserving defaults.
77 Can be repeated.
78 --ldflags=FLAGS Flags to pass to the linker
79 Default is $LDFLAGS
80 --add-ldflags=FLAGS Adds additional linker flags, preserving defaults.
81 Can be repeated.
82 --c-compiler=CC The C compiler to use when building modules.
83 Default is $CC
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.
87 Default is $LD
88 --no-example-certs Disables generation of example certificates.
89 EOF
92 # Helper functions
94 find_program() {
95 prog=$(command -v "$1" 2>/dev/null)
96 if [ -n "$prog" ]
97 then
98 dirname "$prog"
102 die() {
103 echo "$*"
104 echo
105 echo "configure failed."
106 echo
107 exit 1
110 # shellcheck disable=SC2039
111 case $(echo -n x) in
112 -n*) echo_n_flag='';;
113 *) echo_n_flag='-n';;
114 esac
116 echo_n() {
117 echo $echo_n_flag "$*"
120 # ----------------------------------------------------------------------------
121 # MAIN PROGRAM
122 # ----------------------------------------------------------------------------
124 # Parse options
126 while [ -n "$1" ]
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
132 then
133 echo
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.'
137 echo
139 case "$key" in
140 --help)
141 show_help
142 exit 0
144 --prefix)
145 [ -n "$value" ] || die "Missing value in flag $key."
146 PREFIX="$value"
147 PREFIX_SET=yes
149 --sysconfdir)
150 [ -n "$value" ] || die "Missing value in flag $key."
151 SYSCONFDIR="$value"
152 SYSCONFDIR_SET=yes
154 --ostype)
155 # TODO make this a switch?
156 OSPRESET="$value"
157 if [ "$OSPRESET" = "debian" ]; then
158 if [ "$LUA_SUFFIX_SET" != "yes" ]; then
159 LUA_SUFFIX="5.1";
160 LUA_SUFFIX_SET=yes
162 if [ "$RUNWITH_SET" != "yes" ]; then
163 RUNWITH="lua$LUA_SUFFIX";
164 RUNWITH_SET=yes
166 LUA_INCDIR="/usr/include/lua$LUA_SUFFIX"
167 LUA_INCDIR_SET=yes
168 CFLAGS="$CFLAGS -ggdb"
170 if [ "$OSPRESET" = "macosx" ]; then
171 LUA_INCDIR=/usr/local/include;
172 LUA_INCDIR_SET=yes
173 LUA_LIBDIR=/usr/local/lib
174 LUA_LIBDIR_SET=yes
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;
180 LUA_INCDIR_SET=yes
181 LUA_LIBDIR=/usr/local/lib
182 LUA_LIBDIR_SET=yes
183 CFLAGS="$CFLAGS -ggdb"
185 if [ "$OSPRESET" = "freebsd" ] || [ "$OSPRESET" = "openbsd" ]; then
186 LUA_INCDIR="/usr/local/include/lua51"
187 LUA_INCDIR_SET=yes
188 CFLAGS="-Wall -fPIC -I/usr/local/include"
189 LDFLAGS="-I/usr/local/include -L/usr/local/lib -shared"
190 LUA_SUFFIX="51"
191 LUA_SUFFIX_SET=yes
192 LUA_DIR=/usr/local
193 LUA_DIR_SET=yes
194 CC=cc
195 LD=ld
197 if [ "$OSPRESET" = "openbsd" ]; then
198 LUA_INCDIR="/usr/local/include";
199 LUA_INCDIR_SET="yes"
201 if [ "$OSPRESET" = "netbsd" ]; then
202 LUA_INCDIR="/usr/pkg/include/lua-5.1"
203 LUA_INCDIR_SET=yes
204 LUA_LIBDIR="/usr/pkg/lib/lua/5.1"
205 LUA_LIBDIR_SET=yes
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
211 LUA_SUFFIX="5.1";
212 LUA_SUFFIX_SET=yes
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
218 LUA_INCDIR="$LUA_CF"
219 LUA_INCDIR_SET=yes
221 CFLAGS="$CFLAGS"
224 --libdir)
225 LIBDIR="$value"
226 LIBDIR_SET=yes
228 --datadir)
229 DATADIR="$value"
230 DATADIR_SET=yes
232 --lua-suffix)
233 [ -n "$value" ] || die "Missing value in flag $key."
234 LUA_SUFFIX="$value"
235 LUA_SUFFIX_SET=yes
237 --lua-version|--with-lua-version)
238 [ -n "$value" ] || die "Missing value in flag $key."
239 LUA_VERSION="$value"
240 [ "$LUA_VERSION" = "5.1" ] || [ "$LUA_VERSION" = "5.2" ] || [ "$LUA_VERSION" = "5.3" ] || die "Invalid Lua version in flag $key."
241 LUA_VERSION_SET=yes
243 --with-lua)
244 [ -n "$value" ] || die "Missing value in flag $key."
245 LUA_DIR="$value"
246 LUA_DIR_SET=yes
248 --with-lua-bin)
249 [ -n "$value" ] || die "Missing value in flag $key."
250 LUA_BINDIR="$value"
251 LUA_BINDIR_SET=yes
253 --with-lua-include)
254 [ -n "$value" ] || die "Missing value in flag $key."
255 LUA_INCDIR="$value"
256 LUA_INCDIR_SET=yes
258 --with-lua-lib)
259 [ -n "$value" ] || die "Missing value in flag $key."
260 LUA_LIBDIR="$value"
261 LUA_LIBDIR_SET=yes
263 --with-idn)
264 IDN_LIB="$value"
266 --idn-library)
267 IDN_LIBRARY="$value"
269 --with-ssl)
270 OPENSSL_LIB="$value"
272 --with-random)
273 case "$value" in
274 getrandom)
275 PRNG=GETRANDOM
277 openssl)
278 PRNG=OPENSSL
280 arc4random)
281 PRNG=ARC4RANDOM
283 esac
285 --cflags)
286 CFLAGS="$value"
288 --add-cflags)
289 CFLAGS="$CFLAGS $value"
291 --ldflags)
292 LDFLAGS="$value"
294 --add-ldflags)
295 LDFLAGS="$LDFLAGS $value"
297 --c-compiler)
298 CC="$value"
300 --linker)
301 LD="$value"
303 --runwith)
304 RUNWITH="$value"
305 RUNWITH_SET=yes
307 --no-example-certs)
308 EXCERTS=
310 --compiler-wrapper)
311 CC="$value $CC"
312 LD="$value $LD"
315 die "Error: Unknown flag: $1"
317 esac
318 shift
319 done
321 if [ "$PREFIX_SET" = "yes" ] && [ ! "$SYSCONFDIR_SET" = "yes" ]
322 then
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" ]
330 then
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" ]
338 then
339 LIBDIR=$PREFIX/lib
342 detect_lua_version() {
343 detected_lua=$("$1" -e 'print(_VERSION:match(" (5%.[123])$"))' 2> /dev/null)
344 if [ "$detected_lua" != "nil" ]
345 then
346 if [ "$LUA_VERSION_SET" != "yes" ]
347 then
348 echo "Lua version detected: $detected_lua"
349 LUA_VERSION=$detected_lua
350 return 0
351 elif [ "$LUA_VERSION" = "$detected_lua" ]
352 then
353 return 0
356 return 1
359 search_interpreter() {
360 suffix="$1"
361 if [ "$LUA_BINDIR_SET" = "yes" ]
362 then
363 find_lua="$LUA_BINDIR"
364 elif [ "$LUA_DIR_SET" = "yes" ]
365 then
366 LUA_BINDIR="$LUA_DIR/bin"
367 if [ -f "$LUA_BINDIR/lua$suffix" ]
368 then
369 find_lua="$LUA_BINDIR"
371 else
372 find_lua=$(find_program lua"$suffix")
374 if [ -n "$find_lua" ] && [ -x "$find_lua/lua$suffix" ]
375 then
376 if detect_lua_version "$find_lua/lua$suffix"
377 then
378 echo "Lua interpreter found: $find_lua/lua$suffix..."
379 if [ "$LUA_BINDIR_SET" != "yes" ]
380 then
381 LUA_BINDIR="$find_lua"
383 if [ "$LUA_DIR_SET" != "yes" ]
384 then
385 LUA_DIR=$(dirname "$find_lua")
387 LUA_SUFFIX="$suffix"
388 return 0
391 return 1
394 lua_interp_found=no
395 if [ "$LUA_SUFFIX_SET" != "yes" ]
396 then
397 if [ "$LUA_VERSION_SET" = "yes" ] && [ "$LUA_VERSION" = "5.1" ]
398 then
399 suffixes="5.1 51 -5.1 -51"
400 elif [ "$LUA_VERSION_SET" = "yes" ] && [ "$LUA_VERSION" = "5.2" ]
401 then
402 suffixes="5.2 52 -5.2 -52"
403 elif [ "$LUA_VERSION_SET" = "yes" ] && [ "$LUA_VERSION" = "5.3" ]
404 then
405 suffixes="5.3 53 -5.3 -53"
406 else
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" && {
412 lua_interp_found=yes
413 break
415 done
416 else
417 search_interpreter "$LUA_SUFFIX" && {
418 lua_interp_found=yes
422 # See #1353
423 if [ "$LUA_DIR_SET" != "yes" ] && [ "$LUA_DIR" = "/" ]
424 then
425 LUA_DIR="/usr"
429 if [ "$lua_interp_found" != "yes" ] && [ "$RUNWITH_SET" != "yes" ]
430 then
431 if [ "$LUA_VERSION_SET" ]; then
432 interp="Lua $LUA_VERSION";
433 else
434 interp="Lua";
436 if [ "$LUA_DIR_SET" ] || [ "$LUA_BINDIR_SET" ]; then
437 where="$LUA_BINDIR";
438 else
439 where="\$PATH";
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" ]
446 then
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"
449 then
450 echo "yes"
451 else
452 echo "no"
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" ]
458 then
459 LUA_INCDIR="$LUA_DIR/include"
462 if [ "$LUA_LIBDIR_SET" != "yes" ]
463 then
464 LUA_LIBDIR="$LUA_DIR/lib"
467 echo_n "Checking Lua includes... "
468 lua_h="$LUA_INCDIR/lua.h"
469 if [ -f "$lua_h" ]
470 then
471 echo "lua.h found in $lua_h"
472 else
473 v_dir="$LUA_INCDIR/lua/$LUA_VERSION"
474 lua_h="$v_dir/lua.h"
475 if [ -f "$lua_h" ]
476 then
477 echo "lua.h found in $lua_h"
478 LUA_INCDIR="$v_dir"
479 else
480 d_dir="$LUA_INCDIR/lua$LUA_VERSION"
481 lua_h="$d_dir/lua.h"
482 if [ -f "$lua_h" ]
483 then
484 echo "lua.h found in $lua_h (Debian/Ubuntu)"
485 LUA_INCDIR="$d_dir"
486 else
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" ]
494 then
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" ]
498 then
499 echo "yes"
500 else
501 echo "no"
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" ]
508 then
509 IDNA_LIBS="$ICU_FLAGS"
510 CFLAGS="$CFLAGS -DUSE_STRINGPREP_ICU"
512 if [ "$IDN_LIBRARY" = "idn" ]
513 then
514 IDNA_LIBS="-l$IDN_LIB"
517 if [ -f config.unix ]; then
518 rm -f config.unix
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
530 PRNGLIBS="-lbsd"
533 # Write config
535 echo "Writing configuration..."
536 echo
538 rm -f built
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
544 PREFIX=$PREFIX
545 SYSCONFDIR=$SYSCONFDIR
546 LIBDIR=$LIBDIR
547 DATADIR=$DATADIR
548 LUA_SUFFIX=$LUA_SUFFIX
549 LUA_DIR=$LUA_DIR
550 LUA_DIR_SET=$LUA_DIR_SET
551 LUA_INCDIR=$LUA_INCDIR
552 LUA_LIBDIR=$LUA_LIBDIR
553 LUA_BINDIR=$LUA_BINDIR
554 IDN_LIB=$IDN_LIB
555 IDNA_LIBS=$IDNA_LIBS
556 OPENSSL_LIBS=$OPENSSL_LIBS
557 CFLAGS=$CFLAGS
558 LDFLAGS=$LDFLAGS
559 CC=$CC
560 LD=$LD
561 RUNWITH=$RUNWITH
562 EXCERTS=$EXCERTS
563 RANDOM=$PRNG
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
575 echo
576 echo "Done. You can now run 'make' to build."
577 echo