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