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