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