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