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