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