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