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