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