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