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" ]
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
      ;;
126
   --datadir=*)
127
   	DATADIR="$value"
128
   	DATADIR_SET=yes
129
      ;;
130
   --require-config)
131
      REQUIRE_CONFIG=yes
132
      ;;
133
   --lua-suffix=*)
134
      LUA_SUFFIX="$value"
135
      LUA_SUFFIX_SET=yes
136
      ;;
137
   --with-lua=*)
138
      LUA_DIR="$value"
139
      LUA_DIR_SET=yes
140
      ;;
141
   --with-lua-include=*)
142
      LUA_INCDIR="$value"
143
      LUA_INCDIR_SET=yes
144
      ;;
145
   --with-lua-lib=*)
146
      LUA_LIBDIR="$value" LUA_LIBDIR_SET=yes
147
      ;;
148
   --with-idn=*)
149
      IDN_LIB="$value"
150
      ;;
151
	--idn-library=*)
152
		IDN_LIBRARY="$value"
153
		;;
154
   --with-ssl=*)
155
      OPENSSL_LIB="$value"
156
      ;;
157
   --cflags=*)
158
      CFLAGS="$value"
159
      ;;
160
   --ldflags=*)
161
      LDFLAGS="$value"
162
      ;;
163
   --c-compiler=*)
164
      CC="$value"
165
      ;;
166
   --linker=*)
167
      LD="$value"
168
      ;;
169
   *)
170
      echo "Error: Unknown flag: $1"
171
      exit 1
172
      ;;
173
   esac
174
   shift
175
done
176
 
177
if [ "$PREFIX_SET" = "yes" -a ! "$SYSCONFDIR_SET" = "yes" ]
178
then
179
   if [ "$PREFIX" = "/usr" ]
180
   then SYSCONFDIR=/etc/prosody
181
   else SYSCONFDIR=$PREFIX/etc/prosody
182
   fi
183
fi
184
 
185
if [ "$PREFIX_SET" = "yes" -a ! "$DATADIR_SET" = "yes" ]
186
then
187
   if [ "$PREFIX" = "/usr" ]
188
   then DATADIR=/var/lib/prosody
189
   else DATADIR=$PREFIX/var/lib/prosody
190
   fi
191
fi
192
 
193
find_program() {
194
   path="$PATH"
195
   item="`echo "$path" | sed 's/\([^:]*\):.*/\1/'`"
196
   path="`echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p'`"
197
   found="no"
198
   while [ "$item" ]
199
   do
200
      if [ -e "$item/$1" ]
201
      then
202
         found="yes"
203
         break
204
      fi
205
      item="`echo "$path" | sed 's/\([^:]*\):.*/\1/'`"
206
      path="`echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p'`"
207
   done
208
   if [ "$found" = "yes" ]
209
   then
210
      echo "$item"
211
   else
212
      echo ""
213
   fi
214
}
215
 
216
if [ "$LUA_SUFFIX_SET" != "yes" ]
217
then
218
   for suffix in "5.1" "51" ""
219
   do
220
      LUA_SUFFIX="$suffix"
221
      if [ "$LUA_DIR_SET" = "yes" ]
222
      then
223
         if [ -e "$LUA_DIR/bin/lua$suffix" ]
224
         then
225
            find_lua="$LUA_DIR"
226
         fi
227
      else
228
         find_lua=`find_program lua$suffix`
229
      fi
230
      if [ "$find_lua" ]
231
      then
232
         echo "Lua interpreter found: $find_lua/lua$suffix..."
233
         break
234
      fi
235
   done
236
fi
237
 
238
if ! [ "$LUA_DIR_SET" = "yes" ]
239
then
240
   echo -n "Looking for Lua... "
241
   if [ ! "$find_lua" ]
242
   then
243
      find_lua=`find_program lua$LUA_SUFFIX`
244
      echo "lua$LUA_SUFFIX found in \$PATH: $find_lua"
245
   fi
246
   if [ "$find_lua" ]
247
   then
248
      LUA_DIR=`dirname $find_lua`
249
      LUA_BINDIR="$find_lua"
250
   else
251
      echo "lua$LUA_SUFFIX not found in \$PATH."
252
      echo "You may want to use the flags --with-lua and/or --lua-suffix. See --help."
253
      exit 1
254
   fi
255
fi
256
 
257
if ! [ "$LUA_INCDIR_SET" = "yes" ]
258
then
259
   LUA_INCDIR="$LUA_DIR/include"
260
fi
261
 
262
if ! [ "$LUA_LIBDIR_SET" = "yes" ]
263
then
264
   LUA_LIBDIR="$LUA_DIR/lib"
265
fi
266
 
267
if [ "$LUA_DIR_SET" = "yes" ]
268
then
269
   LUA_BINDIR="$LUA_DIR/bin"
270
fi
271
 
272
if [ "$IDN_LIBRARY" = "icu" ]
273
then
274
	IDNA_LIBS="$ICU_FLAGS"
275
	CFLAGS="$CFLAGS -DUSE_STRINGPREP_ICU"
276
fi
277
if [ "$IDN_LIBRARY" = "idn" ] 
278
then
279
	IDNA_LIBS="-l$IDN_LIB"
280
fi
281
 
282
echo -n "Checking Lua includes... "
283
lua_h="$LUA_INCDIR/lua.h"
284
if [ -e "$lua_h" ]
285
then
286
   echo "lua.h found in $lua_h"
287
else
288
   echo "lua.h not found (looked in $lua_h)"
289
   echo "You may want to use the flag --with-lua-include. See --help."
290
   exit 1
291
fi
292
 
293
find_helper() {
294
   explanation="$1"
295
   shift
296
   tried="$*"
297
   while [ "$1" ]
298
   do
299
      found=`find_program "$1"`
300
      if [ "$found" ]
301
      then
302
         echo "$1 found at $found"
303
         HELPER=$1
304
         return
305
      fi
306
      shift
307
   done
308
   echo "Could not find a $explanation. Tried: $tried."
309
   echo "Make sure one of them is installed and available in your PATH."
310
   exit 1
311
}
312
 
313
# Write config
314
 
315
echo "Writing configuration..."
316
echo
317
 
318
cat <<EOF > config.unix
319
# This file was automatically generated by the configure script.
320
# Run "./configure --help" for details.
321
 
322
PREFIX=$PREFIX
323
SYSCONFDIR=$SYSCONFDIR
324
DATADIR=$DATADIR
325
LUA_SUFFIX=$LUA_SUFFIX
326
LUA_DIR=$LUA_DIR
327
LUA_INCDIR=$LUA_INCDIR
328
LUA_LIBDIR=$LUA_LIBDIR
329
LUA_BINDIR=$LUA_BINDIR
330
REQUIRE_CONFIG=$REQUIRE_CONFIG
331
IDN_LIB=$IDN_LIB
332
IDNA_LIBS=$IDNA_LIBS
333
OPENSSL_LIB=$OPENSSL_LIB
334
CFLAGS=$CFLAGS
335
LDFLAGS=$LDFLAGS
336
CC=$CC
337
CXX=$CXX
338
LD=$LD
339
 
340
EOF
341
 
342
echo "Installation prefix: $PREFIX"
343
echo "Prosody configuration directory: $SYSCONFDIR"
344
echo "Using Lua from: $LUA_DIR"
345
 
346
make clean > /dev/null 2> /dev/null
347
 
348
echo
349
echo "Done. You can now run 'make' to build."
350
echo