ChangeLog part of dist
[yaz-moved-to-github.git] / configure.ac
1 dnl YAZ Toolkit, Index Data 1995-2007
2 dnl See the file LICENSE for details.
3 dnl $Id: configure.ac,v 1.68 2007-03-15 14:07:41 adam Exp $
4 AC_PREREQ(2.59)
5 AC_INIT([yaz],[2.1.53],[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 unistd.h sys/select.h sys/socket.h sys/stat.h sys/time.h sys/times.h sys/types.h sys/un.h sys/wait.h netdb.h arpa/inet.h netinet/tcp.h netinet/in_systm.h])
27 AC_CHECK_HEADERS([net/if.h netinet/in.h netinet/if_ether.h],[],[],[
28  #if HAVE_SYS_TYPES_H
29  #include <sys/types.h>
30  #endif
31  #if HAVE_SYS_SOCKET_H
32  #include <sys/socket.h>
33  #endif
34  #if HAVE_NET_IF_H
35  #include <net/if.h>
36  #endif
37  #if HAVE_NETINET_IN_H
38  #include <netinet/in.h>
39  #endif
40 ])
41 AC_HEADER_STDC
42 if test "$ac_cv_header_stdc" = "no"; then
43     AC_MSG_WARN([Your system doesn not seem to support ANSI C])
44 fi
45 dnl ----- Types
46 AC_CHECK_TYPES([long long])
47 dnl
48 dnl ----- Sockets
49 checkBoth=0
50 AC_CHECK_FUNC(connect)
51 if test "$ac_cv_func_connect" = "no"; then
52     AC_CHECK_LIB(socket, main, LIBS="$LIBS -lsocket", checkBoth=1)
53 fi
54 if test "$checkBoth" = "1"; then
55     oldLibs=$LIBS
56     LIBS="$LIBS -lsocket -lnsl"
57     AC_CHECK_FUNC(accept, , [LIBS=$oldLibs])
58 fi
59 AC_CHECK_FUNC(gethostbyname, ,[AC_CHECK_LIB(nsl, main, [LIBS="$LIBS -lnsl"])])
60 dnl
61 dnl ------ OpenSSL
62 AC_SUBST(SSL_CFLAGS)
63 openssl=default
64 AC_ARG_WITH(openssl, [  --with-openssl[=PREFIX]   OpenSSL library in PREFIX], [openssl=$withval])
65 SSL_CFLAGS=""
66 SSL_LIBPATH=""
67 if test "$openssl" != "no"; then
68     sslver=no
69     if test "$openssl" != "yes" -a "$openssl" != "default"; then
70         if test -x $openssl/bin/pkg-config; then
71             if $openssl/bin/pkg-config --exists openssl; then
72                 SSL_CFLAGS=`$openssl/bin/pkg-config --cflags openssl`
73                 LIBS="$LIBS `$openssl/bin/pkg-config --libs openssl`"
74                 sslver=`$openssl/bin/pkg-config --modversion openssl`
75             fi
76         fi
77         if test "$sslver" = "no"; then
78             SSL_CFLAGS="-I$openssl/include -I$openssl/include/openssl"
79             SSL_LIBPATH="-L$openssl/lib"
80         fi
81     else
82         if test "$pkgconfigpath" != "NONE"; then
83             if $pkgconfigpath --exists openssl; then
84                 SSL_CFLAGS=`$pkgconfigpath --cflags openssl`
85                 LIBS="$LIBS `$pkgconfigpath --libs openssl`"
86                 sslver=`$pkgconfigpath --modversion openssl`
87             fi
88         fi
89         if test "$sslver" = "no"; then
90             SSL_CFLAGS="-I/usr/include/openssl"
91         fi
92     fi
93     if test "$sslver" = "no"; then
94         xLIBS="$LIBS";
95         xCPPFLAGS="$CPPFLAGS";
96         CPPFLAGS="$CPPFLAGS $SSL_CFLAGS $SSL_LIBPATH"
97         AC_CHECK_LIB(crypto, main)
98         AC_CHECK_LIB(ssl, SSL_new)
99         if test "$ac_cv_lib_ssl_SSL_new" = "yes"; then
100             AC_CHECK_HEADER(openssl/ssl.h,[sslver=yes])
101             LIBS="$SSL_LIBPATH $LIBS"
102         fi
103         if test "$sslver" != "yes"; then
104             LIBS="$xLIBS"
105         fi
106         CPPFLAGS="$xCPPFLAGS"
107     fi
108     AC_MSG_CHECKING([for SSL])
109     if test "$sslver" != "no"; then
110         SSL_CFLAGS="-DHAVE_OPENSSL_SSL_H=1 $SSL_CFLAGS"
111         AC_MSG_RESULT([$sslver])
112     else
113         SSL_CFLAGS=""
114         AC_MSG_RESULT([None])
115         if test "$openssl" != "default"; then
116             AC_MSG_ERROR([OpenSSL development libraries missing])
117         fi
118     fi
119 fi
120 dnl
121 dnl ------ GNU Readline
122 READLINE_SHARED_LIBADD=""
123 AC_CHECK_LIB(ncurses, tgetent, [READLINE_SHARED_LIBADD="-lncurses"],
124     AC_CHECK_LIB(termcap, tgetent, [READLINE_SHARED_LIBADD="-ltermcap"])
125 )
126 READLINE_LIBS=""
127 AC_CHECK_LIB(readline, readline, [READLINE_LIBS="$READLINE_LIBS -lreadline $READLINE_SHARED_LIBADD"],,$READLINE_SHARED_LIBADD)
128 AC_CHECK_LIB(history, add_history, [READLINE_LIBS="$READLINE_LIBS -lhistory"])
129 if test "$ac_cv_lib_readline_readline" = "yes"; then
130     AC_CHECK_HEADERS(readline/readline.h readline/history.h)
131     xLIBS=$LIBS
132     LIBS="$LIBS $READLINE_LIBS"
133     AC_TRY_LINK([
134         #include <stdio.h>
135         #include <readline/readline.h>
136             ],[
137             rl_attempted_completion_over = 0;
138             ],AC_DEFINE(HAVE_READLINE_COMPLETION_OVER))
139     AC_TRY_LINK([
140         #include <stdio.h>
141         #include <readline/readline.h>
142             ],[
143             rl_completion_matches (0, 0);
144             ],[AC_DEFINE(HAVE_READLINE_RL_COMPLETION_MATCHES)])
145     LIBS=$xLIBS
146 fi
147 dnl ------ iconv
148 AC_ARG_WITH(iconv, [  --with-iconv[=PREFIX]     iconv library in PREFIX])
149 if test "$with_iconv" != "no"; then
150     AC_MSG_CHECKING(for iconv)
151     oldLIBS="$LIBS"
152     oldCPPFLAGS="${CPPFLAGS}"
153     if test "$with_iconv" != "yes" -a "$with_iconv" != ""; then
154         LIBS="$LIBS -L${with_iconv}/lib"
155         CPPFLAGS="${CPPFLAGS} -I${with_iconv}/include"
156     fi
157     AC_TRY_LINK([
158                 #include <iconv.h>
159             ],[
160             iconv_t t = iconv_open("", "");
161             ],[
162             AC_DEFINE(HAVE_ICONV_H)
163             AC_MSG_RESULT(yes)
164             ],[
165             LIBS="$LIBS -liconv"
166             AC_TRY_LINK([
167                         #include <iconv.h>
168                     ],[
169             iconv_t t = iconv_open("", "");
170                     ],[
171             AC_DEFINE(HAVE_ICONV_H)
172             AC_MSG_RESULT(yes)
173                     ],[
174             LIBS="$oldLIBS"
175             CPPFLAGS="$oldCPPFLAGS"
176             AC_MSG_RESULT(no)
177             ])
178     ])
179 fi
180 dnl ------ libpcap / ziffy
181
182 echo "ether_h = ${ac_cv_header_netinet_if_ether_h}"
183 AC_SUBST(ZIFFY_PROG)
184 AC_SUBST(PCAP_LIBS)
185 AC_SUBST(PCAP_CFLAGS)
186 ZIFFY_PROG=
187 AC_ARG_WITH(pcap, [  --with-pcap[=DIR]         libpcap root dir located in (dir)], [PCAP_DIR="$withval"],[PCAP_DIR=default])
188
189 AC_MSG_CHECKING([for libpcap (required for ziffy)])
190 if test "${PCAP_DIR}" != "no"; then
191     if test "${ac_cv_header_netinet_if_ether_h}" = "no"; then
192         :
193     elif test "${PCAP_DIR}" != "yes" && test "${PCAP_DIR}" != "default"; then
194         if test -r $PCAP_DIR/libpcap.a && test -r $PCAP_DIR/pcap.h; then
195             PCAP_DIR="$PCAP_DIR"
196             PCAP_LIBS="${LIBS} -L$PCAP_DIR -lpcap"
197             PCAP_CFLAGS="${INCS} -I$PCAP_DIR"
198             ZIFFY_PROG=ziffy
199         fi
200     elif test -d /usr/local &&
201         test -r /usr/local/lib/libpcap.a &&
202         test -r /usr/local/include/pcap.h; then
203         PCAP_DIR="/usr/local"
204         PCAP_LIBS="${LIBS} -L$PCAP_DIR/lib -lpcap"
205         PCAP_CFLAGS="${INCS} -I$PCAP_DIR/include"
206         ZIFFY_PROG=ziffy
207     elif test -d /usr &&
208         test -r /usr/lib/libpcap.a &&
209         test -r /usr/include/pcap.h; then
210         PCAP_DIR="/usr"
211         PCAP_LIBS="${LIBS} -lpcap"
212         ZIFFY_PROG=ziffy
213     fi
214 fi
215 if test -z "$ZIFFY_PROG"; then
216     AC_MSG_RESULT([not found. ziffy disabled])
217     if test "${PCAP_DIR}" != "default" && test "${PCAP_DIR}" != "no"; then
218         AC_MSG_ERROR([libpcap missing])
219     fi
220 else
221     AC_MSG_RESULT([found in $PCAP_DIR])
222 fi
223
224 dnl ------ various functions
225 AC_CHECK_FUNCS(getaddrinfo vsnprintf gettimeofday poll strerror_r localtime_r usleep fopen64)
226 case $host in
227     *-*-darwin*)
228         trypoll="no";
229         ;;
230     *)
231         trypoll="yes";
232         ;;
233 esac
234
235 if test "$ac_cv_func_poll" = "yes" -a "$trypoll" = "yes"; then
236     AC_CHECK_HEADERS(sys/poll.h)
237 fi
238 dnl ------ socklen_t
239 dnl We check for socklen_t by making prototypes with the
240 dnl various types. First socklen_t, then size_t, finally int.
241 dnl If the prototype succeeds, we are probably safe.
242 dnl That works if accept is not preprocessor defined (such sa AIX)
243 AC_MSG_CHECKING([for socklen_t])
244 AC_CACHE_VAL(ac_cv_check_socklen_t,[ac_cv_check_socklen_t=''
245         AC_TRY_COMPILE([
246 #include <sys/types.h>
247 #include <sys/socket.h>
248 #ifdef __cplusplus
249 extern "C" {
250 #endif
251 #define try 1
252 #ifdef AIX
253 #if AIX >= 51
254 #define try 0
255 #endif
256 #endif
257 #if try
258 extern int accept(int, struct sockaddr *, socklen_t *);
259 #endif
260 #ifdef __cplusplus
261 }
262 #endif
263         ],,[ac_cv_check_socklen_t=socklen_t],[
264                 AC_TRY_COMPILE([
265 #include <sys/types.h>
266 #include <sys/socket.h>
267 #ifdef __cplusplus
268 extern "C" {
269 #endif
270 #define try 1
271 #ifdef AIX
272 #if AIX >= 42
273 #define try 0
274 #endif
275 #endif
276 #if try
277 extern int accept(int, struct sockaddr *, size_t t *);
278 #endif
279 #ifdef __cplusplus
280 }
281 #endif
282 ],,[ac_cv_check_socklen_t=size_t],[ac_cv_check_socklen_t=int])
283                 ])
284         ])
285 AC_MSG_RESULT($ac_cv_check_socklen_t)
286 AC_DEFINE_UNQUOTED(YAZ_SOCKLEN_T,$ac_cv_check_socklen_t)
287 AC_DEFINE(YAZ_USE_NEW_LOG)
288 dnl
289 dnl ------ tcpd
290 AC_ARG_ENABLE(tcpd,[  --enable-tcpd[=PREFIX]  enable TCP wrapper for server if available])
291 if test "$enable_tcpd" -a "$enable_tcpd" != "no"; then
292     oldLibs=$LIBS
293     oldCPPFLAGS=$CPPFLAGS
294     if test "$enable_tcpd" != "yes"; then
295         LIBS="$LIBS -L$enable_tcpd/lib"
296         CPPFLAGS="$CPPFLAGS -I$enable_tcpd/include"
297     fi
298     AC_MSG_CHECKING(for working tcpd.h)
299     LIBS="$LIBS -lwrap -lnsl"
300     AC_TRY_LINK([#include <syslog.h>
301 #include <tcpd.h>
302             int allow_severity = LOG_INFO;
303             int deny_severity = LOG_WARNING;],
304         [struct request_info request_info; int i;
305             i = hosts_access(&request_info);],
306         tcpd_ok=1, tcpd_ok=0)
307     if test "$tcpd_ok" = "0"; then
308         AC_MSG_RESULT(no)
309         AC_MSG_ERROR([tcpd development libraries missing])
310                 LIBS=$oldLibs
311                 CPPFLAGS=$oldCPPFLAGS
312     else
313         AC_MSG_RESULT(yes)
314         AC_DEFINE(HAVE_TCPD_H)
315     fi
316 fi
317 dnl
318 AC_SUBST(YAZ_CONFIG_CFLAGS)
319 dnl
320 HAVETHREADS=0
321 dnl
322 dnl ------ GNU threads
323 AC_ARG_ENABLE(pth, [  --enable-pth            enable GNU threads],[enable_pth=$enableval],[enable_pth=no])
324 AC_SUBST(LIBPTH)
325 if test "$enable_pth" = "yes"; then
326     PTH_LIBS=""
327     OLIBS=$LIBS
328     AC_CHECK_LIB(pth,main)
329     if test "$ac_cv_lib_pth_main" = "yes"; then
330         AC_CHECK_HEADERS(pth.h)
331         if test "$ac_cv_header_pth_h" = "yes"; then
332             PTH_LIBS="-lpth"
333             CFLAGS="$CFLAGS -DYAZ_GNU_THREADS=1"
334             HAVETHREADS=1
335         fi
336     fi  
337     LIBS="$OLIBS $PTH_LIBS"
338 fi
339 dnl
340 dnl ------ POSIX Threads
341 AC_ARG_ENABLE(threads, [  --disable-threads       disable POSIX threads],[enable_threads=$enableval],[enable_threads=yes])
342 if test "$enable_threads" = "yes" -a "$HAVETHREADS" = "0"; then
343     ACX_PTHREAD([
344             CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
345             AC_DEFINE(YAZ_POSIX_THREADS)
346             dnl unfortunately empty thread lib spec is problematic because 
347             dnl 'yaz-config --cflags' is not always passed to linker in 
348             dnl applications using YAZ (such as Zebra).
349             if test "x$PTHREAD_LIBS" = "x"; then
350                 OLIBS=$LIBS
351                 for lib in -lpthread -lpthreads -lc_r; do
352                     LIBS="$lib $OLIBS"
353                     AC_TRY_LINK([ #include <pthread.h> ],
354                             [ pthread_t id; pthread_join(id, 0); ],
355                             [ PTHREAD_LIBS=$lib; break ]
356                         )
357                 done
358                 LIBS=$OLIBS
359             fi
360             LIBS="$PTHREAD_LIBS $LIBS"
361             YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS $PTHREAD_CFLAGS -DYAZ_POSIX_THREADS=1"
362             ])
363 fi
364
365 dnl ----- libXSLT/libEXLT/libXML2
366 AC_SUBST(XML2_CFLAGS)
367
368 YAZ_LIBXML2(
369     [
370         AC_DEFINE(YAZ_HAVE_XML2) 
371         YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_HAVE_XML2=1"
372     ]
373 )
374
375 YAZ_LIBXSLT(
376     [
377         AC_DEFINE(YAZ_HAVE_XSLT)
378         YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_HAVE_XSLT=1"
379     ]
380 )
381 YAZ_LIBEXSLT(
382     [
383         AC_DEFINE(YAZ_HAVE_EXSLT)
384         YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_HAVE_EXSLT=1"
385     ]
386 )
387         
388 YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS $XML2_CFLAGS"
389
390 if test "$XML2_LIBS"; then
391     LIBS="$XML2_LIBS $LIBS"
392 fi
393
394 dnl
395 dnl ------ Memory debugging
396 AC_ARG_ENABLE(memdebug, [  --enable-memdebug       enable memory debugging],[enable_memdebug=$enableval],[enable_memdebug=none])
397 if test "$enable_memdebug" = "yes"; then
398     AC_DEFINE(TRACE_XMALLOC,2)
399 elif test "$enable_memdebug" = "no"; then
400     AC_DEFINE(TRACE_XMALLOC,0)
401 fi
402 dnl
403 dnl ------ Using this for "in-source" yaz-config
404 AC_SUBST(YAZ_SRC_ROOT)
405 AC_SUBST(YAZ_BUILD_ROOT)
406 YAZ_SRC_ROOT=`cd ${srcdir}; pwd`
407 YAZ_BUILD_ROOT=`pwd`
408 dnl
409 dnl ------ Makefiles
410 dnl
411 AC_OUTPUT([
412 Makefile
413 yaz.spec
414 src/Makefile
415 test/Makefile
416 util/Makefile
417 include/Makefile
418 include/yaz/Makefile
419 client/Makefile
420 ztest/Makefile
421 zoom/Makefile
422 ziffy/Makefile
423 doc/Makefile
424 doc/local.ent
425 doc/common/Makefile
426 doc/common/print.dsl
427 etc/Makefile
428 yaz-config
429 yaz.pc
430 Doxyfile
431 ],[sed s%yaz_echo_source=yes%yaz_echo_source=no%g < yaz-config > util/yaz-config && chmod +x yaz-config util/yaz-config])
432
433
434 echo \
435 "------------------------------------------------------------------------
436 Configuration:
437
438   YAZ Package:                ${PACKAGE}
439   YAZ Version:                ${VERSION}
440   Bugreport:                  ${PACKAGE_BUGREPORT}
441   Source code location:       ${srcdir}
442   C Preprocessor:             ${CPP}
443   C Preprocessor flags:       ${CPPFLAGS}
444   C Compiler:                 ${CC}
445   C Compiler flags:           ${CFLAGS}
446   Linker flags:               ${LDFLAGS}
447   Linked libs:                ${LIBS}
448   Host System Type:           ${host}
449   Install path:               ${prefix}
450   Automake:                   ${AUTOMAKE}
451   Archiver:                   ${AR}
452   Ranlib:                     ${RANLIB}
453
454 ------------------------------------------------------------------------"
455 dnl Local Variables:
456 dnl mode:shell-script
457 dnl sh-indentation: 2
458 dnl sh-basic-offset: 4
459 dnl End: