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