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