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 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" ]; then
98         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" ]; then
106         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" ]; then
113         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 -D_GNU_SOURCE"
118         LDFLAGS="-shared"
119       fi
120       if [ "$OSTYPE" = "freebsd" -o "$OSTYPE" = "openbsd" ]; then
121         LUA_INCDIR="/usr/local/include/lua51"
122         LUA_INCDIR_SET=yes
123         CFLAGS="-Wall -fPIC -I/usr/local/include"
124         LDFLAGS="-I/usr/local/include -L/usr/local/lib -shared"
125         LUA_SUFFIX="-5.1"
126         LUA_SUFFIX_SET=yes
127         LUA_DIR=/usr/local
128         LUA_DIR_SET=yes
129       fi
130       if [ "$OSTYPE" = "openbsd" ]; then
131         LUA_INCDIR="/usr/local/include";
132       fi
133       ;;
134    --datadir=*)
135         DATADIR="$value"
136         DATADIR_SET=yes
137       ;;
138    --require-config)
139       REQUIRE_CONFIG=yes
140       ;;
141    --lua-suffix=*)
142       LUA_SUFFIX="$value"
143       LUA_SUFFIX_SET=yes
144       ;;
145    --with-lua=*)
146       LUA_DIR="$value"
147       LUA_DIR_SET=yes
148       ;;
149    --with-lua-include=*)
150       LUA_INCDIR="$value"
151       LUA_INCDIR_SET=yes
152       ;;
153    --with-lua-lib=*)
154       LUA_LIBDIR="$value" LUA_LIBDIR_SET=yes
155       ;;
156    --with-idn=*)
157       IDN_LIB="$value"
158       ;;
159         --idn-library=*)
160                 IDN_LIBRARY="$value"
161                 ;;
162    --with-ssl=*)
163       OPENSSL_LIB="$value"
164       ;;
165    --cflags=*)
166       CFLAGS="$value"
167       ;;
168    --ldflags=*)
169       LDFLAGS="$value"
170       ;;
171    --c-compiler=*)
172       CC="$value"
173       ;;
174    --linker=*)
175       LD="$value"
176       ;;
177    --runwith=*)
178       RUNWITH="$value"
179       ;;
180    *)
181       echo "Error: Unknown flag: $1"
182       exit 1
183       ;;
184    esac
185    shift
186 done
187
188 if [ "$PREFIX_SET" = "yes" -a ! "$SYSCONFDIR_SET" = "yes" ]
189 then
190    if [ "$PREFIX" = "/usr" ]
191    then SYSCONFDIR=/etc/prosody
192    else SYSCONFDIR=$PREFIX/etc/prosody
193    fi
194 fi
195
196 if [ "$PREFIX_SET" = "yes" -a ! "$DATADIR_SET" = "yes" ]
197 then
198    if [ "$PREFIX" = "/usr" ]
199    then DATADIR=/var/lib/prosody
200    else DATADIR=$PREFIX/var/lib/prosody
201    fi
202 fi
203
204 find_program() {
205    path="$PATH"
206    item="`echo "$path" | sed 's/\([^:]*\):.*/\1/'`"
207    path="`echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p'`"
208    found="no"
209    while [ "$item" ]
210    do
211       if [ -e "$item/$1" ]
212       then
213          found="yes"
214          break
215       fi
216       item="`echo "$path" | sed 's/\([^:]*\):.*/\1/'`"
217       path="`echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p'`"
218    done
219    if [ "$found" = "yes" ]
220    then
221       echo "$item"
222    else
223       echo ""
224    fi
225 }
226
227 if [ "$LUA_SUFFIX_SET" != "yes" ]
228 then
229    for suffix in "5.1" "51" ""
230    do
231       LUA_SUFFIX="$suffix"
232       if [ "$LUA_DIR_SET" = "yes" ]
233       then
234          if [ -e "$LUA_DIR/bin/lua$suffix" ]
235          then
236             find_lua="$LUA_DIR"
237          fi
238       else
239          find_lua=`find_program lua$suffix`
240       fi
241       if [ "$find_lua" ]
242       then
243          echo "Lua interpreter found: $find_lua/lua$suffix..."
244          break
245       fi
246    done
247 fi
248
249 if ! [ "$LUA_DIR_SET" = "yes" ]
250 then
251    echo -n "Looking for Lua... "
252    if [ ! "$find_lua" ]
253    then
254       find_lua=`find_program lua$LUA_SUFFIX`
255       echo "lua$LUA_SUFFIX found in \$PATH: $find_lua"
256    fi
257    if [ "$find_lua" ]
258    then
259       LUA_DIR=`dirname $find_lua`
260       LUA_BINDIR="$find_lua"
261    else
262       echo "lua$LUA_SUFFIX not found in \$PATH."
263       echo "You may want to use the flags --with-lua and/or --lua-suffix. See --help."
264       exit 1
265    fi
266 fi
267
268 if ! [ "$LUA_INCDIR_SET" = "yes" ]
269 then
270    LUA_INCDIR="$LUA_DIR/include"
271 fi
272
273 if ! [ "$LUA_LIBDIR_SET" = "yes" ]
274 then
275    LUA_LIBDIR="$LUA_DIR/lib"
276 fi
277
278 if [ "$LUA_DIR_SET" = "yes" ]
279 then
280    LUA_BINDIR="$LUA_DIR/bin"
281 fi
282
283 if [ "$IDN_LIBRARY" = "icu" ]
284 then
285         IDNA_LIBS="$ICU_FLAGS"
286         CFLAGS="$CFLAGS -DUSE_STRINGPREP_ICU"
287 fi
288 if [ "$IDN_LIBRARY" = "idn" ]
289 then
290         IDNA_LIBS="-l$IDN_LIB"
291 fi
292
293 echo -n "Checking Lua includes... "
294 lua_h="$LUA_INCDIR/lua.h"
295 if [ -e "$lua_h" ]
296 then
297    echo "lua.h found in $lua_h"
298 else
299    echo "lua.h not found (looked in $lua_h)"
300    echo "You may want to use the flag --with-lua-include. See --help."
301    exit 1
302 fi
303
304 find_helper() {
305    explanation="$1"
306    shift
307    tried="$*"
308    while [ "$1" ]
309    do
310       found=`find_program "$1"`
311       if [ "$found" ]
312       then
313          echo "$1 found at $found"
314          HELPER=$1
315          return
316       fi
317       shift
318    done
319    echo "Could not find a $explanation. Tried: $tried."
320    echo "Make sure one of them is installed and available in your PATH."
321    exit 1
322 }
323
324 # Write config
325
326 echo "Writing configuration..."
327 echo
328
329 cat <<EOF > config.unix
330 # This file was automatically generated by the configure script.
331 # Run "./configure --help" for details.
332
333 PREFIX=$PREFIX
334 SYSCONFDIR=$SYSCONFDIR
335 DATADIR=$DATADIR
336 LUA_SUFFIX=$LUA_SUFFIX
337 LUA_DIR=$LUA_DIR
338 LUA_INCDIR=$LUA_INCDIR
339 LUA_LIBDIR=$LUA_LIBDIR
340 LUA_BINDIR=$LUA_BINDIR
341 REQUIRE_CONFIG=$REQUIRE_CONFIG
342 IDN_LIB=$IDN_LIB
343 IDNA_LIBS=$IDNA_LIBS
344 OPENSSL_LIB=$OPENSSL_LIB
345 CFLAGS=$CFLAGS
346 LDFLAGS=$LDFLAGS
347 CC=$CC
348 CXX=$CXX
349 LD=$LD
350 RUNWITH=$RUNWITH
351
352 EOF
353
354 echo "Installation prefix: $PREFIX"
355 echo "Prosody configuration directory: $SYSCONFDIR"
356 echo "Using Lua from: $LUA_DIR"
357
358 make clean > /dev/null 2> /dev/null
359
360 echo
361 echo "Done. You can now run 'make' to build."
362 echo