Better check for SSL on non pkg-config systems
[yaz-moved-to-github.git] / configure.in
1 dnl YAZ Toolkit, Index Data 1994-2004
2 dnl See the file LICENSE for details.
3 dnl $Id: configure.in,v 1.140 2004-05-02 00:07:34 adam Exp $
4 AC_INIT(include/yaz/yaz-version.h)
5 AM_INIT_AUTOMAKE(yaz, 2.0.19)
6 AM_MAINTAINER_MODE
7 dnl
8 AC_SUBST(READLINE_LIBS)
9 AC_SUBST(YAZ_CONF_CFLAGS)
10 dnl ------ Checking programs
11 AC_PROG_CC
12 AC_PROG_CPP
13 AC_CHECK_PROGS(YACC, 'bison -y')
14 test -z "$YACC" && AC_MSG_WARN([GNU bison not found])
15 AC_PROG_INSTALL
16 AM_DISABLE_SHARED
17 AM_PROG_LIBTOOL
18 AC_PATH_PROG(pkgconfig, pkg-config, NONE)
19 dnl
20 YAZ_DOC
21 dnl 
22 dnl ----- Sockets
23 checkBoth=0
24 AC_CHECK_FUNC(connect)
25 if test "$ac_cv_func_connect" = "no"; then
26         AC_CHECK_LIB(socket, main, LIBS="$LIBS -lsocket", checkBoth=1)
27 fi
28 if test "$checkBoth" = "1"; then
29         oldLibs=$LIBS
30         LIBS="$LIBS -lsocket -lnsl"
31         AC_CHECK_FUNC(accept, , [LIBS=$oldLibs])
32 fi
33 AC_CHECK_FUNC(gethostbyname, , AC_CHECK_LIB(nsl, main, [LIBS="$LIBS -lnsl"]))
34 dnl
35 dnl ------ OpenSSL
36 openssl=no
37 AC_ARG_WITH(openssl, [  --with-openssl[=PREFIX] OpenSSL library in PREFIX], [openssl=$withval])
38 USE_SSL=0
39 SSL_CFLAGS=""
40 SSL_LIBS=""
41 if test "$openssl" != "no"; then
42         sslver=no
43         if test "$openssl" != "yes"; then
44                 if $openssl/bin/pkg-config --exists openssl; then
45                         SSL_CFLAGS=`$openssl/bin/pkg-config --cflags openssl`
46                         SSL_LIBS=`$openssl/bin/pkg-config --libs openssl`
47                         sslver=`$openssl/bin/pkg-config --modversion openssl`
48                 else
49                         SSL_CFLAGS="-I$openssl/include -I$openssl/include/openssl"
50                         SSL_LIBS="-L$openssl/lib"
51                 fi
52         else
53                 if test "$pkgconfig" != "NONE"; then
54                         if $pkgconfig --exists openssl; then
55                                 SSL_CFLAGS=`$pkgconfig --cflags openssl`
56                                 SSL_LIBS=`$pkgconfig --libs openssl`
57                                 sslver=`$pkgconfig --modversion openssl`
58                         fi
59                 fi
60                 if test "$sslver" = "no"; then
61                         SSL_CFLAGS="-I/usr/include/openssl"
62                         SSL_LIBS=""
63                 fi
64         fi
65         if test "$sslver" = "no"; then
66                 xLIBS="$LIBS";
67                 xCFLAGS="$CFLAGS";
68                 CFLAGS="$CFLAGS $SSL_CFLAGS"
69                 LIBS="$SSL_LIBS $LIBS"
70                 AC_CHECK_LIB(crypto, main,[SSL_LIBS="$SSL_LIBS -lcrypto"])
71                 LIBS="$LIBS $SSL_LIBS"
72                 AC_CHECK_LIB(ssl, SSL_new)
73                 if test "$ac_cv_lib_ssl_SSL_new" = "yes"; then
74                         AC_CHECK_HEADER(openssl/ssl.h,[sslver=yes])
75                 fi
76                 if test "$sslver" = "yes"; then
77                         SSL_LIBS="-lssl $SSL_LIBS"
78                 fi
79                 LIBS="$xLIBS"
80                 CFLAGS="$xCFLAGS"
81         fi
82         if test "$sslver" != "no"; then
83                 LIBS="$SSL_LIBS $LIBS"
84                 CFLAGS="$CFLAGS -DHAVE_OPENSSL_SSL_H=1 $SSL_CFLAGS"
85                 USE_SSL=1
86         fi
87         AC_MSG_CHECKING([for SSL])
88         AC_MSG_RESULT($sslver)
89 fi
90 dnl
91 dnl ------ GNU Readline
92 READLINE_SHARED_LIBADD=""
93 AC_CHECK_LIB(ncurses, tgetent, [READLINE_SHARED_LIBADD="-lncurses"],
94         AC_CHECK_LIB(termcap, tgetent, [READLINE_SHARED_LIBADD="-ltermcap"])
95 )
96 READLINE_LIBS=""
97 AC_CHECK_LIB(readline, readline, [READLINE_LIBS="$READLINE_LIBS -lreadline $READLINE_SHARED_LIBADD"],,$READLINE_SHARED_LIBADD)
98 AC_CHECK_LIB(history, add_history, [READLINE_LIBS="$READLINE_LIBS -lhistory"])
99 if test "$ac_cv_lib_readline_readline" = "yes"; then
100         AC_CHECK_HEADERS(readline/readline.h readline/history.h)
101         xLIBS=$LIBS
102         LIBS="$LIBS $READLINE_LIBS"
103         AC_TRY_LINK([
104         #include <stdio.h>
105         #include <readline/readline.h>
106         ],[
107         static void f()
108         {
109                 rl_attempted_completion_over = 0;
110         }
111         ],AC_DEFINE(HAVE_READLINE_COMPLETION_OVER))
112         AC_TRY_LINK([
113         #include <stdio.h>
114         #include <readline/readline.h>
115         ],[
116         static void f()
117         {
118                 rl_completion_matches (0, 0);
119         }
120         ],AC_DEFINE(HAVE_READLINE_RL_COMPLETION_MATCHES))
121         LIBS=$xLIBS
122 fi
123 dnl ------ iconv
124 AC_ARG_WITH(iconv, [  --with-iconv[=PREFIX]   iconv library in PREFIX])
125 if test "$with_iconv" != "no"; then
126         AC_MSG_CHECKING(for iconv)
127         oldLIBS="$LIBS"
128         oldCPPFLAGS="${CPPFLAGS}"
129         if test "$with_iconv" != "yes" -a "$with_iconv" != ""; then
130                 LIBS="$LIBS -L${with_iconv}/lib"
131                 CPPFLAGS="${CPPFLAGS} -I${with_iconv}/include"
132         fi
133         AC_TRY_LINK([
134                 #include <iconv.h>
135         ],[
136                 static void f() {iconv_t t = iconv_open("", ""); }
137         ],[
138                 AC_DEFINE(HAVE_ICONV_H)
139                 AC_MSG_RESULT(yes)
140         ],[
141                 LIBS="$LIBS -liconv"
142                 AC_TRY_LINK([
143                         #include <iconv.h>
144                 ],[
145                         static void f() {iconv_t t = iconv_open("", ""); }
146                 ],[
147                         AC_DEFINE(HAVE_ICONV_H)
148                         AC_MSG_RESULT(yes)
149                 ],[
150                         LIBS="$oldLIBS"
151                         CPPFLAGS="$oldCPPFLAGS"
152                         AC_MSG_RESULT(no)
153                 ])
154         ])
155 fi
156 dnl ------ various functions
157 AC_CHECK_FUNCS(vsnprintf gettimeofday poll strerror_r)
158 if test "$ac_cv_func_poll" = "yes"; then
159         AC_CHECK_HEADERS(sys/poll.h)
160 fi
161 dnl ------ socklen_t
162 dnl We check for socklen_t by making prototypes with the
163 dnl various types. First socklen_t, then size_t, finally int.
164 dnl If the prototype succeeds, we're probably safe.
165 dnl That works if accept is not preprocessor defined (such sa AIX)
166 AC_MSG_CHECKING([for socklen_t])
167 AC_CACHE_VAL(ac_cv_check_socklen_t,[ac_cv_check_socklen_t=''
168         AC_TRY_COMPILE([
169 #include <sys/types.h>
170 #include <sys/socket.h>
171 #ifdef __cplusplus
172 extern "C" {
173 #endif
174 #define try 1
175 #ifdef AIX
176 #if AIX >= 51
177 #define try 0
178 #endif
179 #endif
180 #if try
181 extern int accept(int, struct sockaddr *, socklen_t *);
182 #endif
183 #ifdef __cplusplus
184 }
185 #endif
186         ],,[ac_cv_check_socklen_t=socklen_t],[
187                 AC_TRY_COMPILE([
188 #include <sys/types.h>
189 #include <sys/socket.h>
190 #ifdef __cplusplus
191 extern "C" {
192 #endif
193 #define try 1
194 #ifdef AIX
195 #if AIX >= 42
196 #define try 0
197 #endif
198 #endif
199 #if try
200 extern int accept(int, struct sockaddr *, size_t t *);
201 #endif
202 #ifdef __cplusplus
203 }
204 #endif
205                 ],,[ac_cv_check_socklen_t=size_t],[ac_cv_check_socklen_t=int])
206         ])
207 ])
208 AC_MSG_RESULT($ac_cv_check_socklen_t)
209 AC_DEFINE_UNQUOTED(YAZ_SOCKLEN_T,$ac_cv_check_socklen_t)
210 dnl
211 dnl ------ tcpd
212 AC_ARG_ENABLE(tcpd,[  --enable-tcpd[=PREFIX]  enable TCP wrapper for server if available])
213 if test "$enable_tcpd" != "" && test "$enable_tcpd" != "no"; then
214         oldLibs=$LIBS
215         oldCPPFLAGS=$CPPFLAGS
216         if test "$enable_tcpd" != "yes"; then
217                 LIBS="$LIBS -L$enable_tcpd/lib"
218                 CPPFLAGS="$CPPFLAGS -I$enable_tcpd/include"
219         fi
220         AC_MSG_CHECKING(for working tcpd.h)
221         LIBS="$LIBS -lwrap -lnsl"
222         AC_TRY_LINK([#include <syslog.h>
223 #include <tcpd.h>
224         int allow_severity = LOG_INFO;
225         int deny_severity = LOG_WARNING;],
226         [struct request_info request_info; int i;
227         i = hosts_access(&request_info);],
228         tcpd_ok=1, tcpd_ok=0)
229         if test "$tcpd_ok" = "0"; then
230                 AC_MSG_RESULT(no)
231                 LIBS=$oldLibs
232                 CPPFLAGS=$oldCPPFLAGS
233         else
234                 AC_MSG_RESULT(yes)
235                 AC_DEFINE(HAVE_TCPD_H)
236         fi
237 fi
238 dnl
239 dnl ------ Headers
240 AC_CHECK_HEADERS(fnmatch.h wchar.h locale.h langinfo.h)
241 AC_STDC_HEADERS
242 if test "$ac_cv_header_stdc" = "no"; then
243         AC_MSG_WARN(Your system doesn't seem to support ANSI C)
244 fi
245 dnl
246 AC_SUBST(LIBTHREAD)
247 AC_SUBST(CFLAGSTHREADS)
248 HAVETHREADS=0
249 CFLAGSTHREADS=""
250 LIBTHREAD=""
251 dnl
252 dnl ------ GNU threads
253 AC_ARG_ENABLE(pth, [  --enable-pth            enable GNU threads],[enable_pth=$enableval],[enable_pth=no])
254 AC_SUBST(LIBPTH)
255 if test "$enable_pth" = "yes"; then
256         OLIBS=$LIBS
257         AC_CHECK_LIB(pth,main)
258         if test "$ac_cv_lib_pth_main" = "yes"; then
259                 AC_CHECK_HEADERS(pth.h)
260                 if test "$ac_cv_header_pth_h" = "yes"; then
261                         LIBTHREAD="-lpth"
262                         CFLAGSTHREADS="-DYAZ_GNU_THREADS=1"
263                         HAVETHREADS=1
264                 fi
265         fi      
266         LIBS=$OLIBS
267 fi
268 dnl
269 dnl ------ POSIX Threads
270 AC_ARG_ENABLE(threads, [  --disable-threads       disable POSIX threads],[enable_threads=$enableval],[enable_threads=yes])
271 if test "$enable_threads" = "yes" -a "$HAVETHREADS" = "0"; then
272         OLIBS=$LIBS
273         OCC=$CC
274         AC_CHECK_LIB(pthread,main)
275         AC_MSG_CHECKING(for working POSIX Threads)
276         AC_TRY_LINK([#include <pthread.h>
277         void *func(void *p) { return 0; }
278         ],[
279         pthread_t pthread_id;
280         pthread_create (&pthread_id, 0, func, 0);],
281                 thread_ok=yes,thread_ok=no)
282         if test "$thread_ok" = "yes"; then
283                 AC_MSG_RESULT(yes)
284                 LIBTHREAD="-lpthread"
285                 CFLAGSTHREADS="-DYAZ_POSIX_THREADS=1 -D_REENTRANT"
286                 HAVETHREADS=1
287         else
288                 CC="$CC -pthread"
289                 AC_TRY_LINK([#include <pthread.h>
290                         void *func(void *p) { return 0; }
291                         ],[
292                         pthread_t pthread_id;
293                         pthread_create (&pthread_id, 0, func, 0);],
294                         thread_ok=yes,thread_ok=no)
295                 if test "$thread_ok" = "yes"; then
296                         AC_MSG_RESULT([yes,BSD])
297                         CFLAGSTHREADS="-pthread -DYAZ_POSIX_THREADS=1 -D_REENTRANT"
298                         LIBTHREAD="-pthread"
299                         HAVETHREADS=1
300                 fi
301         fi
302         if test "$thread_ok" = "no"; then
303                 AC_MSG_RESULT(no)
304         fi
305         CC=$OCC
306         LIBS=$OLIBS
307 fi
308 AM_CONDITIONAL(ISTHR, test $HAVETHREADS = "1")
309 dnl
310 dnl ----- libXML2
311 AC_SUBST(XML2_LIBS)
312 AC_SUBST(XML2_CFLAGS)
313 xml2dir=yes
314 AC_ARG_WITH(xml2, [  --with-xml2[=PREFIX]    use libxml2 in PREFIX],[xml2dir=$withval])
315 if test "$xml2dir" = "yes"; then
316         for d in /usr /usr/local; do
317                 if test -x $d/bin/xml2-config; then
318                         xml2dir=$d
319                 fi
320         done
321 fi
322 if test "$xml2dir" != "no"; then
323         AC_MSG_CHECKING(for libXML2)
324         if test -x $xml2dir/bin/xml2-config; then
325                 XML2_LIBS=`$xml2dir/bin/xml2-config --libs`
326                 LIBS="$XML2_LIBS $LIBS"
327                 XML2_CFLAGS=`$xml2dir/bin/xml2-config --cflags`
328                 XML2_VER=`$xml2dir/bin/xml2-config --version`
329                 AC_MSG_RESULT($XML2_VER)
330                 AC_DEFINE(HAVE_XML2)
331         else
332                 AC_MSG_RESULT(Not found)
333         fi
334 fi
335 dnl
336 dnl ------ Memory debugging
337 AC_ARG_ENABLE(memdebug, [  --enable-memdebug       enable memory debugging],[enable_memdebug=$enableval],[enable_memdebug=none])
338 if test "$enable_memdebug" = "yes"; then
339         AC_DEFINE(TRACE_XMALLOC,2)
340 elif test "$enable_memdebug" = "no"; then
341         AC_DEFINE(TRACE_XMALLOC,0)
342 fi
343 dnl
344 dnl ------ Using this for "in-source" yaz-config
345 AC_SUBST(YAZ_SRC_ROOT)
346 AC_SUBST(YAZ_BUILD_ROOT)
347 YAZ_SRC_ROOT=`cd ${srcdir}; pwd`
348 YAZ_BUILD_ROOT=`pwd`
349 dnl
350 dnl ------ Makefiles
351 dnl
352 AC_OUTPUT([
353 Makefile
354 yaz.spec
355 src/Makefile
356 test/Makefile
357 util/Makefile
358 include/Makefile
359 include/yaz/Makefile
360 client/Makefile
361 ztest/Makefile
362 zoom/Makefile
363 doc/Makefile
364 doc/yaz.xml
365 doc/yazhtml.dsl
366 doc/yazphp.dsl
367 doc/yazprint.dsl
368 doc/tkl.xsl
369 doc/yazhtml.xsl
370 etc/Makefile
371 yaz-config
372 ],[sed s%yaz_echo_source=yes%yaz_echo_source=no%g < yaz-config > util/yaz-config && chmod +x yaz-config util/yaz-config])