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