* Brought over the SSL/TLS stuff from Citadel. I think it's complete but
[citadel.git] / webcit / configure.in
1 dnl Process this file with autoconf to produce a configure script.
2 dnl $Id$
3 AC_INIT(webserver.c)
4
5 AC_CANONICAL_HOST
6
7 AC_ARG_WITH(with_libical, [  --with-libical          use libical calendaring library])
8 AC_ARG_WITH(with_newt, [  --with-newt          use newt window library])
9 AC_ARG_WITH(ssl,
10         [  --with-ssl=PATH     Specify path to OpenSSL installation ],
11         [
12                 if test "x$withval" != "xno" ; then
13                         tryssldir=$withval
14                 fi
15         ]
16 )
17 dnl Set some system-specific variables which are OK to set before compiler
18 dnl checks:
19 PTHREAD_DEFS=-D_REENTRANT
20 case "$host" in
21         dnl Tru64 Unix requires we use -pthread instead of linking the threads
22         dnl libraries directly, and we can't build threaded programs with gcc
23         dnl due to header file problems.
24         alpha*-dec-osf*)
25                 test -z "$CC" && CC=cc
26                 LIBS=-pthread
27         ;;
28         dnl FreeBSD is similar:
29         *-*-freebsd*)
30                 LIBS=-pthread
31                 PTHREAD_DEFS=-D_THREAD_SAFE
32         ;;
33         *-*-solaris*)
34                 PTHREAD_DEFS='-D_REENTRANT -D_PTHREADS'
35         ;;
36 esac
37 AC_SUBST(PTHREAD_DEFS)
38
39 dnl Checks for programs.
40 AC_PROG_CC
41
42 dnl Configure compiler flags for GCC
43 if test "$GCC" = yes; then
44         case "$host" in
45                 *-*-solaris*)
46                         CFLAGS="$CFLAGS -Wall -Wno-char-subscripts"
47                 ;;
48                 *)
49                         CFLAGS="$CFLAGS -Wall"
50                 ;;
51         esac
52 fi
53
54 missing_dir=`cd $ac_aux_dir && pwd`
55 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
56
57 dnl Checks for libraries.
58 if test "$LIBS" != -pthread; then
59         AC_CHECK_LIB(pthread, pthread_create)
60         AC_CHECK_LIB(pthreads, pthread_create)
61 fi
62 AC_SEARCH_LIBS(gethostbyname, nsl)
63 AC_SEARCH_LIBS(connect, socket)
64
65 dnl Checks for header files.
66 AC_HEADER_STDC
67 dnl AC_HEADER_SYS_WAIT
68 AC_CHECK_HEADERS(fcntl.h limits.h sys/time.h unistd.h)
69
70 dnl Checks for typedefs, structures, and compiler characteristics.
71 AC_C_CONST
72 AC_TYPE_OFF_T
73 AC_TYPE_SIZE_T
74 dnl AC_HEADER_TIME
75
76 dnl Checks for library functions.
77 AC_TYPE_SIGNAL
78 dnl AC_FUNC_VPRINTF
79 dnl AC_CHECK_FUNCS(strerror)
80 AC_REPLACE_FUNCS(snprintf)
81
82 dnl Checks for the libical calendaring library.
83 if test "x$with_libical" != xno ; then
84         AC_CHECK_HEADERS(ical.h,
85                 [AC_CHECK_LIB(ical, icalcomponent_new,
86                         [ok_libical=yes],,
87         )])
88 fi
89
90 if test "x$ok_libical" = xyes ; then
91
92         AC_TRY_RUN(
93                 [
94 #include <ical.h>
95 main() {
96         float v;
97         int i;
98         sscanf(ICAL_VERSION, "%f", &v);
99         printf("libical version: %0.2f\n", v);
100         v = v * 100.0;
101         i = (int) v;
102         if (i >= 24) {
103                 printf("This version is ok.\n");
104                 printf("WebCit will be built with calendar support.\n");
105                 return(0);
106         }
107         printf("libical 0.24 or newer is required.\n");
108         printf("WebCit will be built without calendar support.\n");
109         return(1);
110 }
111                 ], 
112                 [
113                         LIBS="-lical $LIBS"
114                         AC_DEFINE(HAVE_LIBICAL)
115                 ]
116         )
117 fi
118
119 dnl Checks for the newt window library.
120 if test "x$with_newt" != xno ; then
121         AC_CHECK_HEADERS(newt.h,
122                 [AC_CHECK_LIB(newt, newtInit,
123                         [ok_newt=yes],,
124         )])
125 fi
126
127 if test "x$ok_newt" = xyes ; then
128         SETUP_LIBS="-lnewt $SETUP_LIBS"
129         AC_DEFINE(HAVE_NEWT)
130 fi
131
132 # The big search for OpenSSL
133 if test "$with_ssl" != "no"; then
134         saved_LIBS="$LIBS"
135         saved_LDFLAGS="$LDFLAGS"
136         saved_CFLAGS="$CFLAGS"
137         if test "x$prefix" != "xNONE"; then
138                 tryssldir="$tryssldir $prefix"
139         fi
140         AC_CACHE_CHECK([for OpenSSL], ac_cv_openssldir, [
141                 for ssldir in $tryssldir "" /usr /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/pkg /opt /opt/openssl ; do
142                         CFLAGS="$saved_CFLAGS"
143                         LDFLAGS="$saved_LDFLAGS"
144                         LIBS="$saved_LIBS -lssl -lcrypto"
145         
146                         # Skip directories if they don't exist
147                         if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
148                                 continue;
149                         fi
150                         if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
151                                 # Try to use $ssldir/lib if it exists, otherwise
152                                 # $ssldir
153                                 if test -d "$ssldir/lib" ; then
154                                         LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
155                                         if test ! -z "$need_dash_r" ; then
156                                                 LDFLAGS="-R$ssldir/lib $LDFLAGS"
157                                         fi
158                                 else
159                                         LDFLAGS="-L$ssldir $saved_LDFLAGS"
160                                         if test ! -z "$need_dash_r" ; then
161                                                 LDFLAGS="-R$ssldir $LDFLAGS"
162                                         fi
163                                 fi
164                                 # Try to use $ssldir/include if it exists, otherwise
165                                 # $ssldir
166                                 if test -d "$ssldir/include" ; then
167                                         CFLAGS="-I$ssldir/include $saved_CFLAGS"
168                                 else
169                                         CFLAGS="-I$ssldir $saved_CFLAGS"
170                                 fi
171                         fi
172         
173                         # Basic test to check for compatible version and correct linking
174                         # *does not* test for RSA - that comes later.
175                         AC_TRY_RUN(
176                                 [
177         #include <string.h>
178         #include <openssl/rand.h>
179         int main(void)
180         {
181                 char a[2048];
182                 memset(a, 0, sizeof(a));
183                 RAND_add(a, sizeof(a), sizeof(a));
184                 return(RAND_status() <= 0);
185         }
186                                 ],
187                                 [
188                                         found_crypto=1
189                                         break;
190                                 ], []
191                         )
192         
193                         if test ! -z "$found_crypto" ; then
194                                 break;
195                         fi
196                 done
197         
198                 if test -z "$ssldir" ; then
199                         ssldir="(system)"
200                 fi
201         
202                 if test ! -z "$found_crypto" ; then
203                         ac_cv_openssldir=$ssldir
204                 else
205                         ac_cv_openssldir="no"
206                 fi
207         ])
208         LIBS="$saved_LIBS"
209         LDFLAGS="$saved_LDFLAGS"
210         CFLAGS="$saved_CFLAGS"
211         
212         if test "x$ac_cv_openssldir" != "xno" ; then
213                 AC_DEFINE(HAVE_OPENSSL)
214                 LIBS="-lssl -lcrypto $LIBS"
215                 dnl Need to recover ssldir - test above runs in subshell
216                 ssldir=$ac_cv_openssldir
217                 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr" -a "x$ssldir" != "x(system)"; then
218                         # Try to use $ssldir/lib if it exists, otherwise
219                         # $ssldir
220                         if test -d "$ssldir/lib" ; then
221                                 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
222                                 if test ! -z "$need_dash_r" ; then
223                                         LDFLAGS="-R$ssldir/lib $LDFLAGS"
224                                 fi
225                         else
226                                 LDFLAGS="-L$ssldir $saved_LDFLAGS"
227                                 if test ! -z "$need_dash_r" ; then
228                                         LDFLAGS="-R$ssldir $LDFLAGS"
229                                 fi
230                         fi
231                         # Try to use $ssldir/include if it exists, otherwise
232                         # $ssldir
233                         if test -d "$ssldir/include" ; then
234                                 CFLAGS="-I$ssldir/include $saved_CFLAGS"
235                         else
236                                 CFLAGS="-I$ssldir $saved_CFLAGS"
237                         fi
238                 fi
239         fi
240 fi
241
242
243
244 AC_SUBST(SETUP_LIBS)
245
246 AC_OUTPUT(Makefile)
247