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