Change --with-pcap-dir to --with-pcap[=DIR]. Enable ziffy only if libpcap
[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.49 2006-11-30 08:46:52 adam Exp $
4 AC_PREREQ(2.59)
5 AC_INIT([yaz],[2.1.41],[yaz-help@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_CHECK_PROGS(TCLSH, tclsh8.5 tclsh8.4 tclsh8.3 tclsh8.2, tclsh)
18 AC_PROG_INSTALL
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 netinet/if_ether.h netinet/in_systm.h)
27 AC_HEADER_STDC
28 if test "$ac_cv_header_stdc" = "no"; then
29     AC_MSG_WARN([Your system doesn not 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=default
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" -a "$openssl" != "default"; 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         if test "$openssl" != "default"; then
102             AC_MSG_ERROR([OpenSSL development libraries missing])
103         fi
104     fi
105 fi
106 dnl
107 dnl ------ GNU Readline
108 READLINE_SHARED_LIBADD=""
109 AC_CHECK_LIB(ncurses, tgetent, [READLINE_SHARED_LIBADD="-lncurses"],
110     AC_CHECK_LIB(termcap, tgetent, [READLINE_SHARED_LIBADD="-ltermcap"])
111 )
112 READLINE_LIBS=""
113 AC_CHECK_LIB(readline, readline, [READLINE_LIBS="$READLINE_LIBS -lreadline $READLINE_SHARED_LIBADD"],,$READLINE_SHARED_LIBADD)
114 AC_CHECK_LIB(history, add_history, [READLINE_LIBS="$READLINE_LIBS -lhistory"])
115 if test "$ac_cv_lib_readline_readline" = "yes"; then
116     AC_CHECK_HEADERS(readline/readline.h readline/history.h)
117     xLIBS=$LIBS
118     LIBS="$LIBS $READLINE_LIBS"
119     AC_TRY_LINK([
120         #include <stdio.h>
121         #include <readline/readline.h>
122             ],[
123             rl_attempted_completion_over = 0;
124             ],AC_DEFINE(HAVE_READLINE_COMPLETION_OVER))
125     AC_TRY_LINK([
126         #include <stdio.h>
127         #include <readline/readline.h>
128             ],[
129             rl_completion_matches (0, 0);
130             ],[AC_DEFINE(HAVE_READLINE_RL_COMPLETION_MATCHES)])
131     LIBS=$xLIBS
132 fi
133 dnl ------ iconv
134 AC_ARG_WITH(iconv, [  --with-iconv[=PREFIX]     iconv library in PREFIX])
135 if test "$with_iconv" != "no"; then
136     AC_MSG_CHECKING(for iconv)
137     oldLIBS="$LIBS"
138     oldCPPFLAGS="${CPPFLAGS}"
139     if test "$with_iconv" != "yes" -a "$with_iconv" != ""; then
140         LIBS="$LIBS -L${with_iconv}/lib"
141         CPPFLAGS="${CPPFLAGS} -I${with_iconv}/include"
142     fi
143     AC_TRY_LINK([
144                 #include <iconv.h>
145             ],[
146             iconv_t t = iconv_open("", "");
147             ],[
148             AC_DEFINE(HAVE_ICONV_H)
149             AC_MSG_RESULT(yes)
150             ],[
151             LIBS="$LIBS -liconv"
152             AC_TRY_LINK([
153                         #include <iconv.h>
154                     ],[
155             iconv_t t = iconv_open("", "");
156                     ],[
157             AC_DEFINE(HAVE_ICONV_H)
158             AC_MSG_RESULT(yes)
159                     ],[
160             LIBS="$oldLIBS"
161             CPPFLAGS="$oldCPPFLAGS"
162             AC_MSG_RESULT(no)
163             ])
164     ])
165 fi
166 dnl ------ libpcap / ziffy
167
168 AC_SUBST(ZIFFY_PROG)
169 AC_SUBST(ZIFFY_MAN)
170 AC_SUBST(PCAP_LIBS)
171 AC_SUBST(PCAP_CFLAGS)
172 ZIFFY_PROG=
173 AC_ARG_WITH(pcap, [  --with-pcap[=DIR]         libpcap root dir located in (dir)], [PCAP_DIR="$withval"],[PCAP_DIR=default])
174
175 AC_MSG_CHECKING([for libpcap (required for ziffy)])
176 if test "${PCAP_DIR}" != "no"; then
177     if test "${PCAP_DIR}" != "yes" && test "${PCAP_DIR}" != "default"; then
178         if test -r $PCAP_DIR/libpcap.a && test -r $PCAP_DIR/pcap.h; then
179             PCAP_DIR="$PCAP_DIR"
180             PCAP_LIBS="${LIBS} -L$PCAP_DIR -lpcap"
181             PCAP_CFLAGS="${INCS} -I$PCAP_DIR"
182             ZIFFY_PROG=ziffy
183         fi
184     else
185         if test -d /usr/local &&
186             test -r /usr/local/lib/libpcap.a &&
187             test -r /usr/local/include/pcap.h; then
188             PCAP_DIR="/usr/local"
189             PCAP_LIBS="${LIBS} -L$PCAP_DIR/lib -lpcap"
190             PCAP_CFLAGS="${INCS} -I$PCAP_DIR/include"
191             ZIFFY_PROG=ziffy
192         elif test -d /usr &&
193             test -r /usr/lib/libpcap.a &&
194             test -r /usr/include/pcap.h; then
195             PCAP_DIR="/usr"
196             PCAP_LIBS="${LIBS} -lpcap"
197             ZIFFY_PROG=ziffy
198         fi
199     fi
200 fi
201 if test -z "$ZIFFY_PROG"; then
202     AC_MSG_RESULT([not found. ziffy disabled])
203     if test "${PCAP_DIR}" != "default" && test "${PCAP_DIR}" != "no"; then
204         AC_MSG_ERROR([libpcap missing])
205     fi
206 else
207     AC_MSG_RESULT([found in $PCAP_DIR])
208     ZIFFY_MAN=ziffy.1
209 fi
210
211 dnl ------ various functions
212 AC_CHECK_FUNCS(getaddrinfo vsnprintf gettimeofday poll strerror_r localtime_r usleep fopen64)
213 case $host in
214     *-*-darwin*)
215         trypoll="no";
216         ;;
217     *)
218         trypoll="yes";
219         ;;
220 esac
221
222 if test "$ac_cv_func_poll" = "yes" -a "$trypoll" = "yes"; then
223     AC_CHECK_HEADERS(sys/poll.h)
224 fi
225 dnl ------ socklen_t
226 dnl We check for socklen_t by making prototypes with the
227 dnl various types. First socklen_t, then size_t, finally int.
228 dnl If the prototype succeeds, we are probably safe.
229 dnl That works if accept is not preprocessor defined (such sa AIX)
230 AC_MSG_CHECKING([for socklen_t])
231 AC_CACHE_VAL(ac_cv_check_socklen_t,[ac_cv_check_socklen_t=''
232         AC_TRY_COMPILE([
233 #include <sys/types.h>
234 #include <sys/socket.h>
235 #ifdef __cplusplus
236 extern "C" {
237 #endif
238 #define try 1
239 #ifdef AIX
240 #if AIX >= 51
241 #define try 0
242 #endif
243 #endif
244 #if try
245 extern int accept(int, struct sockaddr *, socklen_t *);
246 #endif
247 #ifdef __cplusplus
248 }
249 #endif
250         ],,[ac_cv_check_socklen_t=socklen_t],[
251                 AC_TRY_COMPILE([
252 #include <sys/types.h>
253 #include <sys/socket.h>
254 #ifdef __cplusplus
255 extern "C" {
256 #endif
257 #define try 1
258 #ifdef AIX
259 #if AIX >= 42
260 #define try 0
261 #endif
262 #endif
263 #if try
264 extern int accept(int, struct sockaddr *, size_t t *);
265 #endif
266 #ifdef __cplusplus
267 }
268 #endif
269 ],,[ac_cv_check_socklen_t=size_t],[ac_cv_check_socklen_t=int])
270                 ])
271         ])
272 AC_MSG_RESULT($ac_cv_check_socklen_t)
273 AC_DEFINE_UNQUOTED(YAZ_SOCKLEN_T,$ac_cv_check_socklen_t)
274 AC_DEFINE(YAZ_USE_NEW_LOG)
275 dnl
276 dnl ------ tcpd
277 AC_ARG_ENABLE(tcpd,[  --enable-tcpd[=PREFIX]  enable TCP wrapper for server if available])
278 if test "$enable_tcpd" -a "$enable_tcpd" != "no"; then
279     oldLibs=$LIBS
280     oldCPPFLAGS=$CPPFLAGS
281     if test "$enable_tcpd" != "yes"; then
282         LIBS="$LIBS -L$enable_tcpd/lib"
283         CPPFLAGS="$CPPFLAGS -I$enable_tcpd/include"
284     fi
285     AC_MSG_CHECKING(for working tcpd.h)
286     LIBS="$LIBS -lwrap -lnsl"
287     AC_TRY_LINK([#include <syslog.h>
288 #include <tcpd.h>
289             int allow_severity = LOG_INFO;
290             int deny_severity = LOG_WARNING;],
291         [struct request_info request_info; int i;
292             i = hosts_access(&request_info);],
293         tcpd_ok=1, tcpd_ok=0)
294     if test "$tcpd_ok" = "0"; then
295         AC_MSG_RESULT(no)
296         AC_MSG_ERROR([tcpd development libraries missing])
297                 LIBS=$oldLibs
298                 CPPFLAGS=$oldCPPFLAGS
299     else
300         AC_MSG_RESULT(yes)
301         AC_DEFINE(HAVE_TCPD_H)
302     fi
303 fi
304 dnl
305 AC_SUBST(THREAD_CFLAGS)
306 HAVETHREADS=0
307 THREAD_CFLAGS=""
308 LIBTHREAD=""
309 dnl
310 dnl ------ GNU threads
311 AC_ARG_ENABLE(pth, [  --enable-pth            enable GNU threads],[enable_pth=$enableval],[enable_pth=no])
312 AC_SUBST(LIBPTH)
313 if test "$enable_pth" = "yes"; then
314     OLIBS=$LIBS
315     AC_CHECK_LIB(pth,main)
316     if test "$ac_cv_lib_pth_main" = "yes"; then
317         AC_CHECK_HEADERS(pth.h)
318         if test "$ac_cv_header_pth_h" = "yes"; then
319             LIBTHREAD="-lpth"
320             THREAD_CFLAGS="-DYAZ_GNU_THREADS=1"
321             HAVETHREADS=1
322         fi
323     fi  
324     LIBS="$OLIBS $LIBTHREAD"
325 fi
326 dnl
327 dnl ------ POSIX Threads
328 AC_ARG_ENABLE(threads, [  --disable-threads       disable POSIX threads],[enable_threads=$enableval],[enable_threads=yes])
329 if test "$enable_threads" = "yes" -a "$HAVETHREADS" = "0"; then
330     OLIBS=$LIBS
331     OCC=$CC
332     AC_CHECK_LIB(pthread,main)
333     AC_MSG_CHECKING(for working POSIX Threads)
334     AC_TRY_LINK([#include <pthread.h>
335             void *func(void *p) { return 0; }
336             ],[
337             pthread_t pthread_id;
338             pthread_create (&pthread_id, 0, func, 0);],
339         thread_ok=yes,thread_ok=no)
340     if test "$thread_ok" = "yes"; then
341         AC_MSG_RESULT(yes)
342         LIBTHREAD="-lpthread"
343         THREAD_CFLAGS="-DYAZ_POSIX_THREADS=1 -D_REENTRANT"
344         HAVETHREADS=1
345     else
346         CC="$CC -pthread"
347         AC_TRY_LINK([#include <pthread.h>
348                 void *func(void *p) { return 0; }
349                 ],[
350                 pthread_t pthread_id;
351                 pthread_create (&pthread_id, 0, func, 0);],
352             thread_ok=yes,thread_ok=no)
353         if test "$thread_ok" = "yes"; then
354             AC_MSG_RESULT([yes,BSD])
355             THREAD_CFLAGS="-pthread -DYAZ_POSIX_THREADS=1 -D_REENTRANT"
356             LIBTHREAD="-pthread"
357             HAVETHREADS=1
358         fi
359     fi
360     if test "$thread_ok" = "no"; then
361         AC_MSG_RESULT(no)
362     fi
363     CC=$OCC
364     LIBS="$OLIBS $LIBTHREAD"
365 fi
366
367 dnl ----- libXSLT/libEXLT/libXML2
368 AC_SUBST(XML2_CFLAGS)
369 AC_SUBST(YAZ_CONFIG_CFLAGS)
370 YAZ_CONFIG_CFLAGS=""
371
372 YAZ_LIBXML2(
373     [
374         AC_DEFINE(YAZ_HAVE_XML2) 
375         YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_HAVE_XML2=1"
376     ]
377 )
378
379 YAZ_LIBXSLT(
380     [
381         AC_DEFINE(YAZ_HAVE_XSLT)
382         YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_HAVE_XSLT=1"
383     ]
384 )
385 YAZ_LIBEXSLT(
386     [
387         AC_DEFINE(YAZ_HAVE_EXSLT)
388         YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_HAVE_EXSLT=1"
389     ]
390 )
391         
392 YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS $XML2_CFLAGS"
393
394 if test "$XML2_LIBS"; then
395     LIBS="$XML2_LIBS $LIBS"
396 fi
397
398 dnl
399 dnl ------ Memory debugging
400 AC_ARG_ENABLE(memdebug, [  --enable-memdebug       enable memory debugging],[enable_memdebug=$enableval],[enable_memdebug=none])
401 if test "$enable_memdebug" = "yes"; then
402     AC_DEFINE(TRACE_XMALLOC,2)
403 elif test "$enable_memdebug" = "no"; then
404     AC_DEFINE(TRACE_XMALLOC,0)
405 fi
406 dnl
407 dnl ------ Using this for "in-source" yaz-config
408 AC_SUBST(YAZ_SRC_ROOT)
409 AC_SUBST(YAZ_BUILD_ROOT)
410 YAZ_SRC_ROOT=`cd ${srcdir}; pwd`
411 YAZ_BUILD_ROOT=`pwd`
412 dnl
413 dnl ------ Makefiles
414 dnl
415 AC_OUTPUT([
416 Makefile
417 yaz.spec
418 src/Makefile
419 test/Makefile
420 util/Makefile
421 include/Makefile
422 include/yaz/Makefile
423 client/Makefile
424 ztest/Makefile
425 zoom/Makefile
426 ziffy/Makefile
427 doc/Makefile
428 doc/local.ent
429 doc/common/Makefile
430 doc/common/print.dsl
431 etc/Makefile
432 yaz-config
433 Doxyfile
434 ],[sed s%yaz_echo_source=yes%yaz_echo_source=no%g < yaz-config > util/yaz-config && chmod +x yaz-config util/yaz-config])
435
436
437 echo \
438 "------------------------------------------------------------------------
439 Configuration:
440
441   YAZ Package:                ${PACKAGE}
442   YAZ Version:                ${VERSION}
443   Bugreport:                  ${PACKAGE_BUGREPORT}
444   Source code location:       ${srcdir}
445   C Preprocessor:             ${CPP}
446   C Preprocessor flags:       ${CPPFLAGS}
447   C Compiler:                 ${CC}
448   C Compiler flags:           ${CFLAGS}
449   Linker flags:               ${LDFLAGS}
450   Linked libs:                ${LIBS}
451   Host System Type:           ${host}
452   Install path:               ${prefix}
453   Automake:                   ${AUTOMAKE}
454   Archiver:                   ${AR}
455   Ranlib:                     ${RANLIB}
456
457 ------------------------------------------------------------------------"
458 dnl Local Variables:
459 dnl mode:shell-script
460 dnl sh-indentation: 2
461 dnl sh-basic-offset: 4
462 dnl End: