Changed behavior of yaz_retrieval_request so that no rules, i.e. no
[yaz-moved-to-github.git] / configure.ac
1 dnl YAZ Toolkit, Index Data 1994-2006
2 dnl See the file LICENSE for details.
3 dnl $Id: configure.ac,v 1.12 2006-05-08 11:50:57 adam Exp $
4 AC_PREREQ(2.59)
5 AC_INIT([yaz],[2.1.19],[adam@indexdata.dk])
6 AC_CONFIG_SRCDIR(configure.ac)
7 AC_CONFIG_AUX_DIR([config])
8 AM_INIT_AUTOMAKE([1.8])
9 dnl
10 AC_SUBST(READLINE_LIBS)
11 AC_SUBST(YAZ_CONF_CFLAGS)
12 dnl ------ Checking programs
13 AC_PROG_CC
14 AC_PROG_CPP
15 AC_CHECK_PROGS(YACC, 'bison -y')
16 test -z "$YACC" && AC_MSG_WARN([GNU bison not found])
17 AC_PROG_INSTALL
18 AM_DISABLE_SHARED
19 AM_PROG_LIBTOOL
20 AC_PATH_PROG(pkgconfigpath, pkg-config, NONE)
21 dnl
22 YAZ_DOC
23 dnl 
24 dnl
25 dnl ------ Headers
26 AC_CHECK_HEADERS(dirent.h fnmatch.h wchar.h locale.h langinfo.h pwd.h sys/select.h sys/socket.h sys/stat.h sys/time.h sys/types.h sys/un.h sys/wait.h unistd.h)
27 AC_HEADER_STDC
28 if test "$ac_cv_header_stdc" = "no"; then
29         AC_MSG_WARN(Your system doesn't seem to support ANSI C)
30 fi
31 dnl ----- Types
32 AC_CHECK_TYPES([long long])
33 dnl
34 dnl ----- Sockets
35 checkBoth=0
36 AC_CHECK_FUNC(connect)
37 if test "$ac_cv_func_connect" = "no"; then
38         AC_CHECK_LIB(socket, main, LIBS="$LIBS -lsocket", checkBoth=1)
39 fi
40 if test "$checkBoth" = "1"; then
41         oldLibs=$LIBS
42         LIBS="$LIBS -lsocket -lnsl"
43         AC_CHECK_FUNC(accept, , [LIBS=$oldLibs])
44 fi
45 AC_CHECK_FUNC(gethostbyname, ,[AC_CHECK_LIB(nsl, main, [LIBS="$LIBS -lnsl"])])
46 dnl
47 dnl ------ OpenSSL
48 AC_SUBST(SSL_CFLAGS)
49 openssl=no
50 AC_ARG_WITH(openssl, [  --with-openssl[=PREFIX]   OpenSSL library in PREFIX], [openssl=$withval])
51 SSL_CFLAGS=""
52 SSL_LIBPATH=""
53 if test "$openssl" != "no"; then
54         sslver=no
55         if test "$openssl" != "yes"; then
56                 if test -x $openssl/bin/pkg-config; then
57                         if $openssl/bin/pkg-config --exists openssl; then
58                                 SSL_CFLAGS=`$openssl/bin/pkg-config --cflags openssl`
59                                 LIBS="$LIBS `$openssl/bin/pkg-config --libs openssl`"
60                                 sslver=`$openssl/bin/pkg-config --modversion openssl`
61                         fi
62                 fi
63                 if test "$sslver" = "no"; then
64                         SSL_CFLAGS="-I$openssl/include -I$openssl/include/openssl"
65                         SSL_LIBPATH="-L$openssl/lib"
66                 fi
67         else
68                 if test "$pkgconfigpath" != "NONE"; then
69                         if $pkgconfigpath --exists openssl; then
70                                 SSL_CFLAGS=`$pkgconfigpath --cflags openssl`
71                                 LIBS="$LIBS `$pkgconfigpath --libs openssl`"
72                                 sslver=`$pkgconfigpath --modversion openssl`
73                         fi
74                 fi
75                 if test "$sslver" = "no"; then
76                         SSL_CFLAGS="-I/usr/include/openssl"
77                 fi
78         fi
79         if test "$sslver" = "no"; then
80                 xLIBS="$LIBS";
81                 xCPPFLAGS="$CPPFLAGS";
82                 CPPFLAGS="$CPPFLAGS $SSL_CFLAGS $SSL_LIBPATH"
83                 AC_CHECK_LIB(crypto, main)
84                 AC_CHECK_LIB(ssl, SSL_new)
85                 if test "$ac_cv_lib_ssl_SSL_new" = "yes"; then
86                         AC_CHECK_HEADER(openssl/ssl.h,[sslver=yes])
87                         LIBS="$SSL_LIBPATH $LIBS"
88                 fi
89                 if test "$sslver" != "yes"; then
90                         LIBS="$xLIBS"
91                 fi
92                 CPPFLAGS="$xCPPFLAGS"
93         fi
94         AC_MSG_CHECKING([for SSL])
95         if test "$sslver" != "no"; then
96                 SSL_CFLAGS="-DHAVE_OPENSSL_SSL_H=1 $SSL_CFLAGS"
97                 AC_MSG_RESULT([$sslver])
98         else
99                 SSL_CFLAGS=""
100                 AC_MSG_RESULT([None])
101                 AC_MSG_ERROR([OpenSSL development libraries missing])
102         fi
103 fi
104 dnl
105 dnl ------ GNU Readline
106 READLINE_SHARED_LIBADD=""
107 AC_CHECK_LIB(ncurses, tgetent, [READLINE_SHARED_LIBADD="-lncurses"],
108         AC_CHECK_LIB(termcap, tgetent, [READLINE_SHARED_LIBADD="-ltermcap"])
109 )
110 READLINE_LIBS=""
111 AC_CHECK_LIB(readline, readline, [READLINE_LIBS="$READLINE_LIBS -lreadline $READLINE_SHARED_LIBADD"],,$READLINE_SHARED_LIBADD)
112 AC_CHECK_LIB(history, add_history, [READLINE_LIBS="$READLINE_LIBS -lhistory"])
113 if test "$ac_cv_lib_readline_readline" = "yes"; then
114         AC_CHECK_HEADERS(readline/readline.h readline/history.h)
115         xLIBS=$LIBS
116         LIBS="$LIBS $READLINE_LIBS"
117         AC_TRY_LINK([
118         #include <stdio.h>
119         #include <readline/readline.h>
120         ],[
121                 rl_attempted_completion_over = 0;
122         ],AC_DEFINE(HAVE_READLINE_COMPLETION_OVER))
123         AC_TRY_LINK([
124         #include <stdio.h>
125         #include <readline/readline.h>
126         ],[
127                 rl_completion_matches (0, 0);
128         ],[AC_DEFINE(HAVE_READLINE_RL_COMPLETION_MATCHES)])
129         LIBS=$xLIBS
130 fi
131 dnl ------ iconv
132 AC_ARG_WITH(iconv, [  --with-iconv[=PREFIX]     iconv library in PREFIX])
133 if test "$with_iconv" != "no"; then
134         AC_MSG_CHECKING(for iconv)
135         oldLIBS="$LIBS"
136         oldCPPFLAGS="${CPPFLAGS}"
137         if test "$with_iconv" != "yes" -a "$with_iconv" != ""; then
138                 LIBS="$LIBS -L${with_iconv}/lib"
139                 CPPFLAGS="${CPPFLAGS} -I${with_iconv}/include"
140         fi
141         AC_TRY_LINK([
142                 #include <iconv.h>
143         ],[
144                 iconv_t t = iconv_open("", "");
145         ],[
146                 AC_DEFINE(HAVE_ICONV_H)
147                 AC_MSG_RESULT(yes)
148         ],[
149                 LIBS="$LIBS -liconv"
150                 AC_TRY_LINK([
151                         #include <iconv.h>
152                 ],[
153                         iconv_t t = iconv_open("", "");
154                 ],[
155                         AC_DEFINE(HAVE_ICONV_H)
156                         AC_MSG_RESULT(yes)
157                 ],[
158                         LIBS="$oldLIBS"
159                         CPPFLAGS="$oldCPPFLAGS"
160                         AC_MSG_RESULT(no)
161                 ])
162         ])
163 fi
164 dnl ------ various functions
165 AC_CHECK_FUNCS(vsnprintf gettimeofday poll strerror_r localtime_r usleep fopen64)
166 case $host in
167 *-*-darwin*)
168         trypoll="no";
169                 ;;
170 *)
171         trypoll="yes";
172         ;;
173 esac
174
175 if test "$ac_cv_func_poll" = "yes" -a "$trypoll" = "yes"; then
176         AC_CHECK_HEADERS(sys/poll.h)
177 fi
178 dnl ------ socklen_t
179 dnl We check for socklen_t by making prototypes with the
180 dnl various types. First socklen_t, then size_t, finally int.
181 dnl If the prototype succeeds, we're probably safe.
182 dnl That works if accept is not preprocessor defined (such sa AIX)
183 AC_MSG_CHECKING([for socklen_t])
184 AC_CACHE_VAL(ac_cv_check_socklen_t,[ac_cv_check_socklen_t=''
185         AC_TRY_COMPILE([
186 #include <sys/types.h>
187 #include <sys/socket.h>
188 #ifdef __cplusplus
189 extern "C" {
190 #endif
191 #define try 1
192 #ifdef AIX
193 #if AIX >= 51
194 #define try 0
195 #endif
196 #endif
197 #if try
198 extern int accept(int, struct sockaddr *, socklen_t *);
199 #endif
200 #ifdef __cplusplus
201 }
202 #endif
203         ],,[ac_cv_check_socklen_t=socklen_t],[
204                 AC_TRY_COMPILE([
205 #include <sys/types.h>
206 #include <sys/socket.h>
207 #ifdef __cplusplus
208 extern "C" {
209 #endif
210 #define try 1
211 #ifdef AIX
212 #if AIX >= 42
213 #define try 0
214 #endif
215 #endif
216 #if try
217 extern int accept(int, struct sockaddr *, size_t t *);
218 #endif
219 #ifdef __cplusplus
220 }
221 #endif
222                 ],,[ac_cv_check_socklen_t=size_t],[ac_cv_check_socklen_t=int])
223         ])
224 ])
225 AC_MSG_RESULT($ac_cv_check_socklen_t)
226 AC_DEFINE_UNQUOTED(YAZ_SOCKLEN_T,$ac_cv_check_socklen_t)
227 AC_DEFINE(YAZ_USE_NEW_LOG)
228 dnl
229 dnl ------ tcpd
230 AC_ARG_ENABLE(tcpd,[  --enable-tcpd[=PREFIX]  enable TCP wrapper for server if available])
231 if test "$enable_tcpd" -a "$enable_tcpd" != "no"; then
232         oldLibs=$LIBS
233         oldCPPFLAGS=$CPPFLAGS
234         if test "$enable_tcpd" != "yes"; then
235                 LIBS="$LIBS -L$enable_tcpd/lib"
236                 CPPFLAGS="$CPPFLAGS -I$enable_tcpd/include"
237         fi
238         AC_MSG_CHECKING(for working tcpd.h)
239         LIBS="$LIBS -lwrap -lnsl"
240         AC_TRY_LINK([#include <syslog.h>
241 #include <tcpd.h>
242         int allow_severity = LOG_INFO;
243         int deny_severity = LOG_WARNING;],
244         [struct request_info request_info; int i;
245         i = hosts_access(&request_info);],
246         tcpd_ok=1, tcpd_ok=0)
247         if test "$tcpd_ok" = "0"; then
248                 AC_MSG_RESULT(no)
249                 AC_MSG_ERROR([tcpd development libraries missing])
250                 LIBS=$oldLibs
251                 CPPFLAGS=$oldCPPFLAGS
252         else
253                 AC_MSG_RESULT(yes)
254                 AC_DEFINE(HAVE_TCPD_H)
255         fi
256 fi
257 dnl
258 AC_SUBST(THREAD_CFLAGS)
259 HAVETHREADS=0
260 THREAD_CFLAGS=""
261 LIBTHREAD=""
262 dnl
263 dnl ------ GNU threads
264 AC_ARG_ENABLE(pth, [  --enable-pth            enable GNU threads],[enable_pth=$enableval],[enable_pth=no])
265 AC_SUBST(LIBPTH)
266 if test "$enable_pth" = "yes"; then
267         OLIBS=$LIBS
268         AC_CHECK_LIB(pth,main)
269         if test "$ac_cv_lib_pth_main" = "yes"; then
270                 AC_CHECK_HEADERS(pth.h)
271                 if test "$ac_cv_header_pth_h" = "yes"; then
272                         LIBTHREAD="-lpth"
273                         THREAD_CFLAGS="-DYAZ_GNU_THREADS=1"
274                         HAVETHREADS=1
275                 fi
276         fi      
277         LIBS="$OLIBS $LIBTHREAD"
278 fi
279 dnl
280 dnl ------ POSIX Threads
281 AC_ARG_ENABLE(threads, [  --disable-threads       disable POSIX threads],[enable_threads=$enableval],[enable_threads=yes])
282 if test "$enable_threads" = "yes" -a "$HAVETHREADS" = "0"; then
283         OLIBS=$LIBS
284         OCC=$CC
285         AC_CHECK_LIB(pthread,main)
286         AC_MSG_CHECKING(for working POSIX Threads)
287         AC_TRY_LINK([#include <pthread.h>
288         void *func(void *p) { return 0; }
289         ],[
290         pthread_t pthread_id;
291         pthread_create (&pthread_id, 0, func, 0);],
292                 thread_ok=yes,thread_ok=no)
293         if test "$thread_ok" = "yes"; then
294                 AC_MSG_RESULT(yes)
295                 LIBTHREAD="-lpthread"
296                 THREAD_CFLAGS="-DYAZ_POSIX_THREADS=1 -D_REENTRANT"
297                 HAVETHREADS=1
298         else
299                 CC="$CC -pthread"
300                 AC_TRY_LINK([#include <pthread.h>
301                         void *func(void *p) { return 0; }
302                         ],[
303                         pthread_t pthread_id;
304                         pthread_create (&pthread_id, 0, func, 0);],
305                         thread_ok=yes,thread_ok=no)
306                 if test "$thread_ok" = "yes"; then
307                         AC_MSG_RESULT([yes,BSD])
308                         THREAD_CFLAGS="-pthread -DYAZ_POSIX_THREADS=1 -D_REENTRANT"
309                         LIBTHREAD="-pthread"
310                         HAVETHREADS=1
311                 fi
312         fi
313         if test "$thread_ok" = "no"; then
314                 AC_MSG_RESULT(no)
315         fi
316         CC=$OCC
317         LIBS="$OLIBS $LIBTHREAD"
318 fi
319
320 dnl ----- libXSLT/libEXLT/libXML2
321 AC_SUBST(XML2_CFLAGS)
322
323 xml2dir=default
324 AC_ARG_WITH(xml2,[[  --with-xml2[=PREFIX]    use libxml2 in PREFIX]],xml2dir=$withval)
325 dnl -- if no PREFIX or not specified we just search in default locations
326 dnl -- try pkg-config. If not found, use xml2-config
327 if test "$xml2dir" = "yes" -o "$xml2dir" = "default"; then
328         if test "$pkgconfigpath" != "NONE"; then
329                 if $pkgconfigpath --exists libxml-2.0; then
330                         pkgmodule="libxml-2.0"
331                 fi
332         fi
333         if test -z "$pkgmodule"; then
334                 for d in /usr /usr/local; do
335                         if test -x $d/bin/xml2-config; then
336                                 xml2dir=$d
337                         fi
338                 done
339         fi
340 fi
341 dnl --- do the real check (pkg-config, xml2-config, not-found)
342 if test "$xml2dir" != "no"; then
343         AC_MSG_CHECKING(for libXML2)
344         if test "$pkgmodule"; then
345                 XML2_LIBS=`$pkgconfigpath --libs $pkgmodule`
346                 XML2_CFLAGS=`$pkgconfigpath --cflags $pkgmodule`
347                 XML2_VER=`$pkgconfigpath --modversion $pkgmodule`
348                 AC_MSG_RESULT($XML2_VER)
349                 AC_DEFINE(HAVE_XML2)
350         elif test -x $xml2dir/bin/xml2-config; then
351                 XML2_LIBS=`$xml2dir/bin/xml2-config --libs`
352                 XML2_CFLAGS=`$xml2dir/bin/xml2-config --cflags`
353                 XML2_VER=`$xml2dir/bin/xml2-config --version`
354                 AC_MSG_RESULT($XML2_VER)
355                 AC_DEFINE(HAVE_XML2)
356         else
357                 AC_MSG_RESULT(Not found)
358
359                 if test "$xml2dir" = "default"; then
360                         AC_MSG_WARN([libxml2 development libraries not found.])
361                         AC_MSG_WARN([YAZ will NOT support SRU.])
362                 else
363                         AC_MSG_ERROR([libxml2 development libraries not found.])
364                 fi
365         fi
366 fi
367
368 dnl ----- libXSLT
369 xsltdir=default
370 pkgmodule=""
371 AC_ARG_WITH(xslt,[[  --with-xslt[=PREFIX]    use libXSLT in PREFIX]],xsltdir=$withval)
372
373 dnl -- if no PREFIX or not specified we just search in default locations
374 dnl -- try pkg-config. If not found, use xslt-config
375 if test "$xsltdir" = "yes" -o "$xsltdir" = "default"; then
376         if test "$pkgconfigpath" != "NONE"; then
377                 # pkg-config on woody reports bad CFLAGS which does 
378                 # not include libxml2 CFLAGS, so avoid it..
379                 if $pkgconfigpath --atleast-version 1.1.0 libxslt; then
380                         pkgmodule="libxslt"
381                 fi
382         fi
383         if test -z "$pkgmodule"; then
384                 for d in /usr /usr/local; do
385                         if test -x $d/bin/xslt-config; then
386                                 xsltdir=$d
387                         fi
388                 done
389         fi
390 fi
391 dnl --- do the real check (pkg-config, xslt-config, not-found)
392 if test "$xsltdir" != "no"; then
393         AC_MSG_CHECKING(for libXSLT)
394         if test "$pkgmodule"; then
395                 XML2_LIBS=`$pkgconfigpath --libs $pkgmodule`
396                 XML2_CFLAGS=`$pkgconfigpath --cflags $pkgmodule`
397                 XSLT_VER=`$pkgconfigpath --modversion $pkgmodule`
398                 AC_MSG_RESULT($XSLT_VER)
399                 AC_DEFINE(HAVE_XSLT)
400         elif test -x $xsltdir/bin/xslt-config; then
401                 XML2_LIBS=`$xsltdir/bin/xslt-config --libs`
402                 XML2_CFLAGS=`$xsltdir/bin/xslt-config --cflags`
403                 XSLT_VER=`$xsltdir/bin/xslt-config --version`
404                 AC_MSG_RESULT($XSLT_VER)
405                 AC_DEFINE(HAVE_XSLT)
406         else
407                 AC_MSG_RESULT(Not found)
408
409                 if test "$xsltdir" = "default"; then
410                         AC_MSG_WARN([libXSLT development libraries not found.])
411                 else
412                         AC_MSG_ERROR([libXSLT development libraries not found.])
413                 fi
414         fi
415 fi
416
417 dnl -- get libEXSLT. xslt-config is no good. So use pkg-config only
418 exsltdir=default
419 pkgmodule=""
420 AC_ARG_WITH(exslt,[[  --with-exslt[=PREFIX]   use libEXSLT in PREFIX]],exsltdir=$withval)
421 if test "$exsltdir" = "yes" -o "$exsltdir" = "default"; then
422         if test "$pkgconfigpath" != "NONE"; then
423                 if $pkgconfigpath --exists libexslt; then
424                         pkgmodule="libexslt"
425                 fi
426         fi
427 fi
428 if test "$exsltdir" != "no"; then
429         AC_MSG_CHECKING(for libEXSLT)
430         if test "$pkgmodule"; then
431                 XML2_LIBS=`$pkgconfigpath --libs $pkgmodule`
432                 XML2_CFLAGS=`$pkgconfigpath --cflags $pkgmodule`
433                 EXSLT_VER=`$pkgconfigpath --modversion $pkgmodule`
434                 AC_MSG_RESULT($EXSLT_VER)
435                 AC_DEFINE(HAVE_EXSLT)
436         else
437                 AC_MSG_RESULT(Not found)
438
439                 if test "$exsltdir" = "default"; then
440                         AC_MSG_WARN([libEXSLT development libraries not found.])
441                 else
442                         AC_MSG_ERROR([libEXSLT development libraries not found.])
443                 fi
444         fi
445 fi
446
447 if test "$XML2_LIBS"; then
448         LIBS="$XML2_LIBS $LIBS"
449 fi
450
451 dnl
452 dnl ------ Memory debugging
453 AC_ARG_ENABLE(memdebug, [  --enable-memdebug       enable memory debugging],[enable_memdebug=$enableval],[enable_memdebug=none])
454 if test "$enable_memdebug" = "yes"; then
455         AC_DEFINE(TRACE_XMALLOC,2)
456 elif test "$enable_memdebug" = "no"; then
457         AC_DEFINE(TRACE_XMALLOC,0)
458 fi
459 dnl
460 dnl ------ Using this for "in-source" yaz-config
461 AC_SUBST(YAZ_SRC_ROOT)
462 AC_SUBST(YAZ_BUILD_ROOT)
463 YAZ_SRC_ROOT=`cd ${srcdir}; pwd`
464 YAZ_BUILD_ROOT=`pwd`
465 dnl
466 dnl ------ Makefiles
467 dnl
468 AC_OUTPUT([
469 Makefile
470 yaz.spec
471 src/Makefile
472 test/Makefile
473 util/Makefile
474 include/Makefile
475 include/yaz/Makefile
476 client/Makefile
477 ztest/Makefile
478 zoom/Makefile
479 doc/Makefile
480 doc/yaz.xml
481 doc/common/Makefile
482 doc/common/html.dsl
483 doc/common/html.xsl
484 doc/common/print.dsl
485 doc/common/tkl.xsl
486 etc/Makefile
487 yaz-config
488 Doxyfile
489 ],[sed s%yaz_echo_source=yes%yaz_echo_source=no%g < yaz-config > util/yaz-config && chmod +x yaz-config util/yaz-config])