Potential fixes for building on Mac OSX
[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_INCDIR=/usr/include/lua5.1;
120         fi
121         if [ "$OSTYPE" = "macosx" ]
122         then LUA_INCDIR=/usr/local/include;
123         LUA_LIBDIR=/usr/local/lib
124         CFLAGS="-bundle -Wl,-undefined,dynamic_lookup"
125         fi      
126 fi
127
128 if [ "$PREFIX_SET" = "yes" -a ! "$SYSCONFDIR_SET" = "yes" ]
129 then
130    if [ "$PREFIX" = "/usr" ]
131    then SYSCONFDIR=/etc/prosody
132    else SYSCONFDIR=$PREFIX/etc/prosody
133    fi
134 fi
135
136 if [ "$PREFIX_SET" = "yes" -a ! "$DATADIR_SET" = "yes" ]
137 then
138    if [ "$PREFIX" = "/usr" ]
139    then DATADIR=/var/lib/prosody
140    else DATADIR=$PREFIX/var/lib/prosody
141    fi
142 fi
143
144 find_program() {
145    path="$PATH"
146    item="`echo "$path" | sed 's/\([^:]*\):.*/\1/'`"
147    path="`echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p'`"
148    found="no"
149    while [ "$item" ]
150    do
151       if [ -e "$item/$1" ]
152       then
153          found="yes"
154          break
155       fi
156       item="`echo "$path" | sed 's/\([^:]*\):.*/\1/'`"
157       path="`echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p'`"
158    done
159    if [ "$found" = "yes" ]
160    then
161       echo "$item"
162    else
163       echo ""
164    fi
165 }
166
167 if [ "$LUA_SUFFIX_SET" != "yes" ]
168 then
169    for suffix in "5.1" "51" ""
170    do
171       LUA_SUFFIX="$suffix"
172       if [ "$LUA_DIR_SET" = "yes" ]
173       then
174          if [ -e "$LUA_DIR/bin/lua$suffix" ]
175          then
176             find_lua="$LUA_DIR"
177          fi
178       else
179          find_lua=`find_program lua$suffix`
180       fi
181       if [ "$find_lua" ]
182       then
183          echo "Lua interpreter found: $find_lua/lua$suffix..."
184          break
185       fi
186    done
187 fi
188
189 if ! [ "$LUA_DIR_SET" = "yes" ]
190 then
191    echo -n "Looking for Lua... "
192    if [ ! "$find_lua" ]
193    then
194       find_lua=`find_program lua$LUA_SUFFIX`
195       echo "lua$LUA_SUFFIX found in \$PATH: $find_lua"
196    fi
197    if [ "$find_lua" ]
198    then
199       LUA_DIR=`dirname $find_lua`
200       LUA_BINDIR="$find_lua"
201    else
202       echo "lua$LUA_SUFFIX not found in \$PATH."
203       echo "You may want to use the flags --with-lua and/or --lua-suffix. See --help."
204       exit 1
205    fi
206 fi
207
208 if ! [ "$LUA_INCDIR_SET" = "yes" ]
209 then
210    LUA_INCDIR="$LUA_DIR/include"
211 fi
212
213 if ! [ "$LUA_LIBDIR_SET" = "yes" ]
214 then
215    LUA_LIBDIR="$LUA_DIR/lib"
216 fi
217
218 if [ "$LUA_DIR_SET" = "yes" ]
219 then
220    LUA_BINDIR="$LUA_DIR/bin"
221 fi
222
223 echo -n "Checking Lua includes... "
224 lua_h="$LUA_INCDIR/lua.h"
225 if [ -e "$lua_h" ]
226 then
227    echo "lua.h found in $lua_h"
228 else
229    echo "lua.h not found (looked in $lua_h)"
230    echo "You may want to use the flag --with-lua-include. See --help."
231    exit 1
232 fi
233
234 find_helper() {
235    explanation="$1"
236    shift
237    tried="$*"
238    while [ "$1" ]
239    do
240       found=`find_program "$1"`
241       if [ "$found" ]
242       then
243          echo "$1 found at $found"
244          HELPER=$1
245          return
246       fi
247       shift
248    done
249    echo "Could not find a $explanation. Tried: $tried."
250    echo "Make sure one of them is installed and available in your PATH."
251    exit 1
252 }
253
254 # Write config
255
256 echo "Writing configuration..."
257 echo
258
259 cat <<EOF > config.unix
260 # This file was automatically generated by the configure script.
261 # Run "./configure --help" for details.
262
263 PREFIX=$PREFIX
264 SYSCONFDIR=$SYSCONFDIR
265 DATADIR=$DATADIR
266 LUA_SUFFIX=$LUA_SUFFIX
267 LUA_DIR=$LUA_DIR
268 LUA_INCDIR=$LUA_INCDIR
269 LUA_LIBDIR=$LUA_LIBDIR
270 LUA_BINDIR=$LUA_BINDIR
271 REQUIRE_CONFIG=$REQUIRE_CONFIG
272 IDN_LIB=$IDN_LIB
273 OPENSSL_LIB=$OPENSSL_LIB
274 CFLAGS=$CFLAGS
275
276 EOF
277
278 echo "Installation prefix: $PREFIX"
279 echo "Prosody configuration directory: $SYSCONFDIR"
280 echo "Using Lua from: $LUA_DIR"
281
282 make clean > /dev/null 2> /dev/null
283
284 echo
285 echo "Done. You can now run 'make' to build."
286 echo