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