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