mod_csi_simple: Consider messages encrypted payload as important (fixes part of ...
[prosody.git] / configure
blob4307997cf455a749fe0a57cb6ffd3b6f2b6d5071
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 if [ "$lua_interp_found" != "yes" ] && [ "$RUNWITH_SET" != "yes" ]
423 then
424 if [ "$LUA_VERSION_SET" ]; then
425 interp="Lua $LUA_VERSION";
426 else
427 interp="Lua";
429 if [ "$LUA_DIR_SET" ] || [ "$LUA_BINDIR_SET" ]; then
430 where="$LUA_BINDIR";
431 else
432 where="\$PATH";
434 echo "$interp interpreter not found in $where"
435 die "You may want to use the flags --with-lua, --with-lua-bin and/or --lua-suffix. See --help."
438 if [ "$LUA_VERSION_SET" = "yes" ] && [ "$RUNWITH_SET" != "yes" ]
439 then
440 echo_n "Checking if $LUA_BINDIR/lua$LUA_SUFFIX is Lua version $LUA_VERSION... "
441 if detect_lua_version "$LUA_BINDIR/lua$LUA_SUFFIX"
442 then
443 echo "yes"
444 else
445 echo "no"
446 die "You may want to use the flags --with-lua, --with-lua-bin and/or --lua-suffix. See --help."
450 if [ "$LUA_INCDIR_SET" != "yes" ]
451 then
452 LUA_INCDIR="$LUA_DIR/include"
455 if [ "$LUA_LIBDIR_SET" != "yes" ]
456 then
457 LUA_LIBDIR="$LUA_DIR/lib"
460 echo_n "Checking Lua includes... "
461 lua_h="$LUA_INCDIR/lua.h"
462 if [ -f "$lua_h" ]
463 then
464 echo "lua.h found in $lua_h"
465 else
466 v_dir="$LUA_INCDIR/lua/$LUA_VERSION"
467 lua_h="$v_dir/lua.h"
468 if [ -f "$lua_h" ]
469 then
470 echo "lua.h found in $lua_h"
471 LUA_INCDIR="$v_dir"
472 else
473 d_dir="$LUA_INCDIR/lua$LUA_VERSION"
474 lua_h="$d_dir/lua.h"
475 if [ -f "$lua_h" ]
476 then
477 echo "lua.h found in $lua_h (Debian/Ubuntu)"
478 LUA_INCDIR="$d_dir"
479 else
480 echo "lua.h not found (looked in $LUA_INCDIR, $v_dir, $d_dir)"
481 die "You may want to use the flag --with-lua or --with-lua-include. See --help."
486 if [ "$lua_interp_found" = "yes" ]
487 then
488 echo_n "Checking if Lua header version matches that of the interpreter... "
489 header_version=$(sed -n 's/.*LUA_VERSION_NUM.*5.\(.\).*/5.\1/p' "$lua_h")
490 if [ "$header_version" = "$LUA_VERSION" ]
491 then
492 echo "yes"
493 else
494 echo "no"
495 echo "lua.h version mismatch (interpreter: $LUA_VERSION; lua.h: $header_version)."
496 die "You may want to use the flag --with-lua or --with-lua-include. See --help."
500 if [ "$IDN_LIBRARY" = "icu" ]
501 then
502 IDNA_LIBS="$ICU_FLAGS"
503 CFLAGS="$CFLAGS -DUSE_STRINGPREP_ICU"
505 if [ "$IDN_LIBRARY" = "idn" ]
506 then
507 IDNA_LIBS="-l$IDN_LIB"
510 if [ -f config.unix ]; then
511 rm -f config.unix
514 if [ "$RUNWITH_SET" != yes ]; then
515 RUNWITH="lua$LUA_SUFFIX"
518 OPENSSL_LIBS="-l$OPENSSL_LIB"
520 if [ "$PRNG" = "OPENSSL" ]; then
521 PRNGLIBS=$OPENSSL_LIBS
522 elif [ "$PRNG" = "ARC4RANDOM" ] && [ "$(uname)" = "Linux" ]; then
523 PRNGLIBS="-lbsd"
526 # Write config
528 echo "Writing configuration..."
529 echo
531 rm -f built
532 cat <<EOF > config.unix
533 # This file was automatically generated by the configure script.
534 # Run "./configure --help" for details.
536 LUA_VERSION=$LUA_VERSION
537 PREFIX=$PREFIX
538 SYSCONFDIR=$SYSCONFDIR
539 LIBDIR=$LIBDIR
540 DATADIR=$DATADIR
541 LUA_SUFFIX=$LUA_SUFFIX
542 LUA_DIR=$LUA_DIR
543 LUA_DIR_SET=$LUA_DIR_SET
544 LUA_INCDIR=$LUA_INCDIR
545 LUA_LIBDIR=$LUA_LIBDIR
546 LUA_BINDIR=$LUA_BINDIR
547 IDN_LIB=$IDN_LIB
548 IDNA_LIBS=$IDNA_LIBS
549 OPENSSL_LIBS=$OPENSSL_LIBS
550 CFLAGS=$CFLAGS
551 LDFLAGS=$LDFLAGS
552 CC=$CC
553 LD=$LD
554 RUNWITH=$RUNWITH
555 EXCERTS=$EXCERTS
556 RANDOM=$PRNG
557 RANDOM_LIBS=$PRNGLIBS
562 echo "Installation prefix: $PREFIX"
563 echo "$APP_NAME configuration directory: $SYSCONFDIR"
564 echo "Using Lua from: $LUA_DIR"
566 make clean > /dev/null 2> /dev/null
568 echo
569 echo "Done. You can now run 'make' to build."
570 echo