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