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