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