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