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