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