Merge 0.10->trunk
[prosody.git] / configure
1 #!/bin/sh
2
3 # Defaults
4
5 PREFIX=/usr/local
6 SYSCONFDIR="$PREFIX/etc/prosody"
7 LIBDIR="$PREFIX/lib"
8 DATADIR="$PREFIX/var/lib/prosody"
9 LUA_SUFFIX=""
10 LUA_DIR="/usr"
11 LUA_BINDIR="/usr/bin"
12 LUA_INCDIR="/usr/include"
13 LUA_LIBDIR="/usr/lib"
14 IDN_LIB=idn
15 ICU_FLAGS="-licui18n -licudata -licuuc"
16 OPENSSL_LIB=crypto
17 CC=gcc
18 CXX=g++
19 LD=gcc
20 RUNWITH=lua
21 EXCERTS=yes
22 PRNG=
23 PRNGLIBS=
24
25 CFLAGS="-fPIC -Wall"
26 LDFLAGS="-shared"
27
28 IDN_LIBRARY=idn
29 # Help
30
31 show_help() {
32 cat <<EOF
33 Configure Prosody prior to building.
34
35 --help                      This help.
36 --ostype=OS                 Use one of the OS presets.
37                             May be one of: debian, macosx, linux, freebsd, openbsd
38 --prefix=DIR                Prefix where Prosody should be installed.
39                             Default is $PREFIX
40 --sysconfdir=DIR            Location where the config file should be installed.
41                             Default is \$PREFIX/etc/prosody
42 --libdir=DIR                Location where the server files should be stored.
43                             Default is \$PREFIX/lib
44 --datadir=DIR               Location where the server data should be stored.
45                             Default is \$PREFIX/var/lib/prosody
46 --lua-suffix=SUFFIX         Versioning suffix to use in Lua filenames.
47                             Default is "$LUA_SUFFIX" (lua$LUA_SUFFIX...)
48 --with-lua=PREFIX           Use Lua from given prefix.
49                             Default is $LUA_DIR
50 --runwith=BINARY            What Lua binary to set as runtime environment.
51                             Default is $RUNWITH
52 --with-lua-include=DIR      You can also specify Lua's includes dir.
53                             Default is \$LUA_DIR/include
54 --with-lua-lib=DIR          You can also specify Lua's libraries dir.
55                             Default is \$LUA_DIR/lib
56 --with-idn=LIB              The name of the IDN library to link with.
57                             Default is $IDN_LIB
58 --idn-library=(idn|icu)     Select library to use for IDNA functionality.
59                             idn: use GNU libidn (default)
60                             icu: use ICU from IBM
61 --with-ssl=LIB              The name of the SSL to link with.
62                             Default is $OPENSSL_LIB
63 --with-random=METHOD        CSPRNG backend to use. One of
64                             getrandom: Linux kernel
65                             arc4random: OpenBSD kernel
66                             openssl: OpenSSL RAND method
67                             Default is to use /dev/urandom
68 --cflags=FLAGS              Flags to pass to the compiler
69                             Default is $CFLAGS
70 --ldflags=FLAGS             Flags to pass to the linker
71                             Default is $LDFLAGS
72 --c-compiler=CC             The C compiler to use when building modules.
73                             Default is $CC
74 --linker=CC                 The linker to use when building modules.
75                             Default is $LD
76 --require-config            Will cause Prosody to refuse to run when
77                             it fails to find a configuration file
78 --no-example-certs          Disables generation of example certificates.
79 EOF
80 }
81
82
83 while [ "$1" ]
84 do
85    value="`echo $1 | sed 's/[^=]*=\(.*\)/\1/'`"
86    if echo "$value" | grep -q "~"
87    then
88       echo
89       echo '*WARNING*: the "~" sign is not expanded in flags.'
90       echo 'If you mean the home directory, use $HOME instead.'
91       echo
92    fi
93    case "$1" in
94    --help)
95       show_help
96       exit 0
97       ;;
98    --prefix=*)
99       PREFIX="$value"
100       PREFIX_SET=yes
101       ;;
102    --sysconfdir=*)
103       SYSCONFDIR="$value"
104       SYSCONFDIR_SET=yes
105       ;;
106    --ostype=*)
107       OSTYPE="$value"
108       OSTYPE_SET=yes
109       if [ "$OSTYPE" = "debian" ]; then
110         LUA_SUFFIX="5.1";
111         LUA_SUFFIX_SET=yes
112         RUNWITH="lua5.1"
113         LUA_INCDIR=/usr/include/lua5.1;
114         LUA_INCDIR_SET=yes
115         CFLAGS="$CFLAGS -D_GNU_SOURCE"
116         fi
117         if [ "$OSTYPE" = "macosx" ]; then
118         LUA_INCDIR=/usr/local/include;
119         LUA_INCDIR_SET=yes
120         LUA_LIBDIR=/usr/local/lib
121         LUA_LIBDIR_SET=yes
122         CFLAGS="$CFLAGS -mmacosx-version-min=10.3"
123         LDFLAGS="-bundle -undefined dynamic_lookup"
124         fi
125       if [ "$OSTYPE" = "linux" ]; then
126         LUA_INCDIR=/usr/local/include;
127         LUA_INCDIR_SET=yes
128         LUA_LIBDIR=/usr/local/lib
129         LUA_LIBDIR_SET=yes
130         CFLAGS="-Wall -fPIC -D_GNU_SOURCE"
131         LDFLAGS="-shared"
132       fi
133       if [ "$OSTYPE" = "freebsd" -o "$OSTYPE" = "openbsd" ]; then
134         LUA_INCDIR="/usr/local/include/lua51"
135         LUA_INCDIR_SET=yes
136         CFLAGS="-Wall -fPIC -I/usr/local/include"
137         LDFLAGS="-I/usr/local/include -L/usr/local/lib -shared"
138         LUA_SUFFIX="-5.1"
139         LUA_SUFFIX_SET=yes
140         LUA_DIR=/usr/local
141         LUA_DIR_SET=yes
142         CC=cc
143         LD=ld
144       fi
145       if [ "$OSTYPE" = "openbsd" ]; then
146         LUA_INCDIR="/usr/local/include";
147       fi
148       ;;
149    --libdir=*)
150       LIBDIR="$value"
151       LIBDIR_SET=yes
152       ;;
153    --datadir=*)
154         DATADIR="$value"
155         DATADIR_SET=yes
156       ;;
157    --require-config)
158       REQUIRE_CONFIG=yes
159       ;;
160    --lua-suffix=*)
161       LUA_SUFFIX="$value"
162       LUA_SUFFIX_SET=yes
163       ;;
164    --with-lua=*)
165       LUA_DIR="$value"
166       LUA_DIR_SET=yes
167       ;;
168    --with-lua-include=*)
169       LUA_INCDIR="$value"
170       LUA_INCDIR_SET=yes
171       ;;
172    --with-lua-lib=*)
173       LUA_LIBDIR="$value" LUA_LIBDIR_SET=yes
174       ;;
175    --with-idn=*)
176       IDN_LIB="$value"
177       ;;
178         --idn-library=*)
179                 IDN_LIBRARY="$value"
180                 ;;
181    --with-ssl=*)
182       OPENSSL_LIB="$value"
183       ;;
184   --with-random=getrandom)
185       PRNG=GETRANDOM
186       ;;
187   --with-random=openssl)
188       PRNG=OPENSSL
189       PRNGLIBS=-lcrypto
190       ;;
191   --with-random=arc4random)
192       PRNG=ARC4RANDOM
193       ;;
194    --cflags=*)
195       CFLAGS="$value"
196       ;;
197    --ldflags=*)
198       LDFLAGS="$value"
199       ;;
200    --c-compiler=*)
201       CC="$value"
202       ;;
203    --linker=*)
204       LD="$value"
205       ;;
206    --runwith=*)
207       RUNWITH="$value"
208       ;;
209     --no-example-certs)
210       EXCERTS=
211       ;;
212    *)
213       echo "Error: Unknown flag: $1"
214       exit 1
215       ;;
216    esac
217    shift
218 done
219
220 if [ "$PREFIX_SET" = "yes" -a ! "$SYSCONFDIR_SET" = "yes" ]
221 then
222    if [ "$PREFIX" = "/usr" ]
223    then SYSCONFDIR=/etc/prosody
224    else SYSCONFDIR=$PREFIX/etc/prosody
225    fi
226 fi
227
228 if [ "$PREFIX_SET" = "yes" -a ! "$DATADIR_SET" = "yes" ]
229 then
230    if [ "$PREFIX" = "/usr" ]
231    then DATADIR=/var/lib/prosody
232    else DATADIR=$PREFIX/var/lib/prosody
233    fi
234 fi
235
236 if [ "$PREFIX_SET" = "yes" -a ! "$LIBDIR_SET" = "yes" ]
237 then
238    LIBDIR=$PREFIX/lib
239 fi
240
241 find_program() {
242    path="$PATH"
243    item="`echo "$path" | sed 's/\([^:]*\):.*/\1/'`"
244    path="`echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p'`"
245    found="no"
246    while [ "$item" ]
247    do
248       if [ -f "$item/$1" ]
249       then
250          found="yes"
251          break
252       fi
253       item="`echo "$path" | sed 's/\([^:]*\):.*/\1/'`"
254       path="`echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p'`"
255    done
256    if [ "$found" = "yes" ]
257    then
258       echo "$item"
259    else
260       echo ""
261    fi
262 }
263
264 if [ "$LUA_SUFFIX_SET" != "yes" ]
265 then
266    for suffix in "5.1" "51" ""
267    do
268       LUA_SUFFIX="$suffix"
269       if [ "$LUA_DIR_SET" = "yes" ]
270       then
271          if [ -f "$LUA_DIR/bin/lua$suffix" ]
272          then
273             find_lua="$LUA_DIR"
274          fi
275       else
276          find_lua=`find_program lua$suffix`
277       fi
278       if [ "$find_lua" ]
279       then
280          echo "Lua interpreter found: $find_lua/lua$suffix..."
281          break
282       fi
283    done
284 fi
285
286 if [ "$LUA_DIR_SET" != "yes" ]
287 then
288    echo -n "Looking for Lua... "
289    if [ ! "$find_lua" ]
290    then
291       find_lua=`find_program lua$LUA_SUFFIX`
292       echo "lua$LUA_SUFFIX found in \$PATH: $find_lua"
293    fi
294    if [ "$find_lua" ]
295    then
296       LUA_DIR=`dirname $find_lua`
297       LUA_BINDIR="$find_lua"
298    else
299       echo "lua$LUA_SUFFIX not found in \$PATH."
300       echo "You may want to use the flags --with-lua and/or --lua-suffix. See --help."
301       exit 1
302    fi
303 fi
304
305 if [ "$LUA_INCDIR_SET" != "yes" ]
306 then
307    LUA_INCDIR="$LUA_DIR/include"
308 fi
309
310 if [ "$LUA_LIBDIR_SET" != "yes" ]
311 then
312    LUA_LIBDIR="$LUA_DIR/lib"
313 fi
314
315 if [ "$LUA_DIR_SET" = "yes" ]
316 then
317    LUA_BINDIR="$LUA_DIR/bin"
318 fi
319
320 if [ "$IDN_LIBRARY" = "icu" ]
321 then
322         IDNA_LIBS="$ICU_FLAGS"
323         CFLAGS="$CFLAGS -DUSE_STRINGPREP_ICU"
324 fi
325 if [ "$IDN_LIBRARY" = "idn" ]
326 then
327         IDNA_LIBS="-l$IDN_LIB"
328 fi
329
330 OPENSSL_LIBS="-l$OPENSSL_LIB"
331
332 echo -n "Checking Lua includes... "
333 lua_h="$LUA_INCDIR/lua.h"
334 if [ -f "$lua_h" ]
335 then
336    echo "lua.h found in $lua_h"
337 else
338    echo "lua.h not found (looked in $lua_h)"
339    echo "You may want to use the flag --with-lua-include. See --help."
340    exit 1
341 fi
342
343 find_helper() {
344    explanation="$1"
345    shift
346    tried="$*"
347    while [ "$1" ]
348    do
349       found=`find_program "$1"`
350       if [ "$found" ]
351       then
352          echo "$1 found at $found"
353          HELPER=$1
354          return
355       fi
356       shift
357    done
358    echo "Could not find a $explanation. Tried: $tried."
359    echo "Make sure one of them is installed and available in your PATH."
360    exit 1
361 }
362
363 # Write config
364
365 echo "Writing configuration..."
366 echo
367
368 cat <<EOF > config.unix
369 # This file was automatically generated by the configure script.
370 # Run "./configure --help" for details.
371
372 PREFIX=$PREFIX
373 SYSCONFDIR=$SYSCONFDIR
374 LIBDIR=$LIBDIR
375 DATADIR=$DATADIR
376 LUA_SUFFIX=$LUA_SUFFIX
377 LUA_DIR=$LUA_DIR
378 LUA_INCDIR=$LUA_INCDIR
379 LUA_LIBDIR=$LUA_LIBDIR
380 LUA_BINDIR=$LUA_BINDIR
381 REQUIRE_CONFIG=$REQUIRE_CONFIG
382 IDN_LIB=$IDN_LIB
383 IDNA_LIBS=$IDNA_LIBS
384 OPENSSL_LIBS=$OPENSSL_LIBS
385 CFLAGS=$CFLAGS
386 LDFLAGS=$LDFLAGS
387 CC=$CC
388 CXX=$CXX
389 LD=$LD
390 RUNWITH=$RUNWITH
391 EXCERTS=$EXCERTS
392 RANDOM=$PRNG
393 RANDOM_LIBS=$PRNGLIBS
394
395
396 EOF
397
398 echo "Installation prefix: $PREFIX"
399 echo "Prosody configuration directory: $SYSCONFDIR"
400 echo "Using Lua from: $LUA_DIR"
401
402 make clean > /dev/null 2> /dev/null
403
404 echo
405 echo "Done. You can now run 'make' to build."
406 echo