Version 5.14.12
[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([1.9 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" -a ! -f src/cql.c && AC_MSG_ERROR([GNU Bison not found])
20 test -z "$YACC" && AC_MSG_WARN([GNU Bison not found])
21 AC_CHECK_PROGS([TCLSH], [tclsh tclsh8.5 tclsh8.4 tclsh8.3 tclsh8.2], [tclsh])
22 AC_PROG_INSTALL
23 AM_PROG_LIBTOOL
24 AM_PROG_CC_C_O
25 AC_PATH_PROG([pkgconfigpath],[pkg-config],[NONE])
26 dnl
27 YAZ_DOC
28 dnl
29 dnl
30 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 execinfo.h],[],[],[])
31 AC_CHECK_HEADERS([net/if.h netinet/in.h netinet/if_ether.h],[],[],[
32  #if HAVE_SYS_TYPES_H
33  #include <sys/types.h>
34  #endif
35  #if HAVE_SYS_SOCKET_H
36  #include <sys/socket.h>
37  #endif
38  #if HAVE_NET_IF_H
39  #include <net/if.h>
40  #endif
41  #if HAVE_NETINET_IN_H
42  #include <netinet/in.h>
43  #endif
44 ])
45 AC_HEADER_STDC
46 if test "$ac_cv_header_stdc" = "no"; then
47     AC_MSG_WARN([Your system doesn not seem to support ANSI C])
48 fi
49 dnl ----- Types
50 AC_CHECK_TYPES([long long])
51 dnl
52 dnl ----- Sockets
53 checkBoth=0
54 AC_CHECK_FUNC([connect])
55 if test "$ac_cv_func_connect" = "no"; then
56     AC_CHECK_LIB([socket],[main], LIBS="$LIBS -lsocket", checkBoth=1)
57 fi
58 if test "$checkBoth" = "1"; then
59     oldLibs=$LIBS
60     LIBS="$LIBS -lsocket -lnsl"
61     AC_CHECK_FUNC([accept], , [LIBS=$oldLibs])
62 fi
63 AC_CHECK_FUNC([gethostbyname], ,[AC_CHECK_LIB(nsl, main, [LIBS="$LIBS -lnsl"])])
64 dnl
65 dnl ------ nettle
66 nettle=default
67 AC_SUBST([NETTLE_LIBS])
68 AC_ARG_WITH([nettle], [  --with-nettle           Nettle library], [nettle=$withval])
69 if test "$nettle" != "no"; then
70     AC_MSG_CHECKING([for nettle])
71     if $pkgconfigpath --cflags nettle >/dev/null 2>&1 ; then
72         if $pkgconfigpath --atleast-version 2.0 nettle; then
73             AC_MSG_RESULT([yes])
74             CFLAGS="$CFLAGS `$pkgconfigpath --cflags nettle`"
75             NETTLE_LIBS="`$pkgconfigpath --libs nettle`"
76             libgcryptversion=2enable
77             AC_DEFINE([HAVE_NETTLE],[1],[Define to 1 if nettle is enabled])
78         else
79             AC_MSG_RESULT([no. Version 2.0 required])
80             if test "$nettle" != "default"; then
81                 AC_MSG_ERROR([nettle libraries missing])
82             fi
83         fi
84     else
85         AC_MSG_RESULT([no])
86         if test "$nettle" != "default"; then
87             AC_MSG_ERROR([nettle libraries missing])
88         fi
89     fi
90 fi
91 dnl
92 dnl
93 dnl ------ libgcrypt
94 AC_SUBST([GCRYPT_LIBS])
95 libgcryptpath=NONE
96 AC_ARG_WITH(libgcrypt, [  --with-libgcrypt=DIR    use libgcrypt-config in DIR],[libgcryptpath=$withval])
97 if test "$libgcryptpath" != "no" -a -z "$libgcryptversion"; then
98     if test "$libgcryptpath" = "NONE"; then
99         AC_PATH_PROG([libgcrypt],[libgcrypt-config],[NONE])
100     elif test -x $libgcryptpath/libgcrypt-config; then
101         libgcrypt=$libgcryptpath/libgcrypt-config
102     else
103         libgcrypt=$libgcryptpath
104     fi
105     AC_MSG_CHECKING([for libgcrypt])
106     if "$libgcrypt" --version >/dev/null 2>&1; then
107         libgcryptversion=`$libgcrypt --version`
108         libgcryptversion2=`echo "$libgcryptversion" | awk 'BEGIN { FS = "."; } { printf "%d", [$]1 * 1000 + [$]2;}'`
109         AC_MSG_RESULT([$libgcryptversion])
110         if test $libgcryptversion2 -ge 1002; then
111             GCRYPT_LIBS="`$libgcrypt --libs`"
112             CFLAGS="$CFLAGS `$libgcrypt --cflags`"
113             AC_DEFINE([HAVE_GCRYPT_H],[1],[Define to 1 if libgcrypt is present])
114         else
115             if test "$libgcryptpath" = "NONE"; then
116                 AC_MSG_WARN([Only libgcrypt version 1.2 and later supported])
117             else
118                 AC_MSG_ERROR([Only libgcrypt version 1.2 and later supported])
119             fi
120             libgcryptversion=""
121         fi
122     else
123         AC_MSG_RESULT([no])
124     fi
125 fi
126 dnl ------ redis
127 hiredis=default
128 AC_SUBST([HIREDIS_LIBS])
129 AC_ARG_WITH([redis], [  --with-redis            hiredis library], [hiredis=$withval])
130 if test "$hiredis" != "no" -a "$pkgconfigpath" != "NONE" -a "$libgcryptversion"; then
131     AC_CHECK_LIB([hiredis],[redisCommandArgv],[HIREDIS_LIBS=-lhiredis])
132     AC_MSG_CHECKING([for redis])
133     if $pkgconfigpath --cflags hiredis >/dev/null 2>&1 ; then
134         if $pkgconfigpath --atleast-version 0.10 hiredis; then
135             AC_MSG_RESULT([yes])
136             CFLAGS="$CFLAGS `$pkgconfigpath --cflags hiredis`"
137             HIREDIS_LIBS="`$pkgconfigpath --libs hiredis`"
138             AC_DEFINE([HAVE_HIREDIS],[1],[Define to 1 if hiredis is enabled])
139         else
140             AC_MSG_RESULT([no. Version 0.10 required])
141             if test "$hiredis" != "default"; then
142                 AC_MSG_ERROR([hiredis libraries missing])
143             fi
144         fi
145     else
146         if test "$ac_cv_lib_hiredis_redisCommandArgv" = "yes"; then
147             AC_DEFINE([HAVE_HIREDIS],[1])
148             AC_MSG_RESULT([yes])
149         else
150             AC_MSG_RESULT([no])
151             if test "$hiredis" != "default"; then
152                 AC_MSG_ERROR([hiredis libraries missing])
153             fi
154         fi
155     fi
156 fi
157 dnl ------ memcached
158 memcached=default
159 AC_SUBST([MEMCACHED_LIBS])
160 AC_ARG_WITH([memcached], [  --with-memcached        Memcached library], [memcached=$withval])
161 if test "$memcached" != "no" -a -n "$libgcryptversion" -a "$pkgconfigpath" != "NONE"; then
162     AC_MSG_CHECKING([for libmemcached])
163     if $pkgconfigpath --cflags libmemcached >/dev/null 2>&1 ; then
164         if $pkgconfigpath --atleast-version 0.40 libmemcached; then
165             AC_MSG_RESULT([yes])
166             CFLAGS="$CFLAGS `$pkgconfigpath --cflags libmemcached`"
167             MEMCACHED_LIBS="`$pkgconfigpath --libs libmemcached`"
168             AC_DEFINE([HAVE_LIBMEMCACHED],[1],[Define to 1 if memcached is enabled])
169         else
170             AC_MSG_RESULT([no. Version 0.40 required])
171             if test "$memcached" != "default"; then
172                 AC_MSG_ERROR([libmemcached libraries missing])
173             fi
174         fi
175     else
176         AC_MSG_RESULT([no])
177         if test "$memcached" != "default"; then
178             AC_MSG_ERROR([libmemcached libraries missing])
179         fi
180     fi
181 fi
182 dnl
183 dnl
184 dnl
185 dnl ------ GNU TLS
186 AC_SUBST([SSL_CFLAGS])
187 AC_SUBST([SSL_LIBS])
188 gnutls=default
189 AC_ARG_WITH([gnutls], [  --with-gnutls[=PREFIX]    GNU TLS library in PREFIX], [gnutls=$withval])
190 if test "$gnutls" != "no"; then
191     gnutlsver=no
192     if test "$gnutls" != "yes" -a "$gnutls" != "default"; then
193         if test -x $gnutls/bin/pkg-config; then
194             if $gnutls/bin/pkg-config --exists gnutls; then
195                 SSL_CFLAGS=`$gnutls/bin/pkg-config --cflags gnutls`
196                 SSL_LIBS="`$gnutls/bin/pkg-config --libs gnutls`"
197                 gnutlsver=`$gnutls/bin/pkg-config --modversion gnutls`
198             fi
199         fi
200     else
201         if test "$pkgconfigpath" != "NONE"; then
202             if $pkgconfigpath --exists gnutls; then
203                 SSL_CFLAGS=`$pkgconfigpath --cflags gnutls`
204                 SSL_LIBS="`$pkgconfigpath --libs gnutls`"
205                 gnutlsver=`$pkgconfigpath --modversion gnutls`
206             fi
207         fi
208     fi
209     AC_MSG_CHECKING([for GNU TLS])
210     if test "$gnutlsver" != "no"; then
211         AC_DEFINE([HAVE_GNUTLS_H],[1],[Define to 1 if GNUTLS is present])
212         AC_MSG_RESULT([$gnutlsver])
213     else
214         SSL_CFLAGS=""
215         AC_MSG_RESULT([None])
216         if test "$gnutls" != "default"; then
217             AC_MSG_ERROR([GNU TLS development libraries missing])
218         fi
219     fi
220 fi
221 dnl
222 dnl ------ GNU Readline
223 READLINE_SHARED_LIBADD=""
224 AC_CHECK_LIB([ncurses],[tgetent],[READLINE_SHARED_LIBADD="-lncurses"],
225     AC_CHECK_LIB([termcap],[tgetent],[READLINE_SHARED_LIBADD="-ltermcap"])
226 )
227 READLINE_LIBS=""
228 AC_CHECK_LIB([readline],[readline],[READLINE_LIBS="$READLINE_LIBS -lreadline $READLINE_SHARED_LIBADD"],,$READLINE_SHARED_LIBADD)
229 AC_CHECK_LIB([history],[add_history],[READLINE_LIBS="$READLINE_LIBS -lhistory"])
230 if test "$ac_cv_lib_readline_readline" = "yes"; then
231     AC_CHECK_HEADERS([readline/readline.h readline/history.h])
232     xLIBS=$LIBS
233     LIBS="$LIBS $READLINE_LIBS"
234     AC_TRY_LINK([
235         #include <stdio.h>
236         #include <readline/readline.h>
237             ],[
238             rl_attempted_completion_over = 0;
239             ],AC_DEFINE([HAVE_READLINE_COMPLETION_OVER],1,[Define to 1 if rl_attempted_completion_over is defined]))
240     AC_TRY_LINK([
241         #include <stdio.h>
242         #include <readline/readline.h>
243             ],[
244             rl_completion_matches (0, 0);
245             ],[AC_DEFINE([HAVE_READLINE_RL_COMPLETION_MATCHES],1,[Define to 1 if rl_completion_matches is defined])])
246     LIBS=$xLIBS
247 fi
248 dnl ------ iconv
249 AC_ARG_WITH([iconv],[  --with-iconv[=PREFIX]     iconv library in PREFIX])
250 if test "$with_iconv" != "no"; then
251     AC_MSG_CHECKING([for iconv])
252     oldLIBS="$LIBS"
253     oldCPPFLAGS="${CPPFLAGS}"
254     if test "$with_iconv" != "yes" -a "$with_iconv" != ""; then
255         LIBS="$LIBS -L${with_iconv}/lib"
256         CPPFLAGS="${CPPFLAGS} -I${with_iconv}/include"
257     fi
258     AC_TRY_LINK([
259                 #include <iconv.h>
260             ],[
261             iconv_t t = iconv_open("", "");
262             ],[
263             AC_DEFINE([HAVE_ICONV_H],1,[Define to 1 if iconv.h is present])
264             AC_MSG_RESULT([yes])
265             ],[
266             LIBS="$LIBS -liconv"
267             AC_TRY_LINK([
268                         #include <iconv.h>
269                     ],[
270             iconv_t t = iconv_open("", "");
271                     ],[
272             AC_DEFINE([HAVE_ICONV_H],1)
273             AC_MSG_RESULT([yes])
274                     ],[
275             LIBS="$oldLIBS"
276             CPPFLAGS="$oldCPPFLAGS"
277             AC_MSG_RESULT([no])
278             ])
279     ])
280 fi
281 dnl ------ various functions
282 AC_CHECK_FUNCS([getaddrinfo vsnprintf gettimeofday poll strerror_r localtime_r usleep fopen64])
283 case $host in
284     *-*-darwin*)
285         trypoll="no";
286         ;;
287     *)
288         trypoll="yes";
289         ;;
290 esac
291
292 if test "$ac_cv_func_poll" = "yes" -a "$trypoll" = "yes"; then
293     AC_CHECK_HEADERS([sys/poll.h])
294 fi
295 dnl ------ socklen_t
296 dnl We check for socklen_t by making prototypes with the
297 dnl various types. First socklen_t, then size_t, finally int.
298 dnl If the prototype succeeds, we are probably safe.
299 dnl That works if accept is not preprocessor defined (such sa AIX)
300 AC_MSG_CHECKING([for socklen_t])
301 AC_CACHE_VAL(ac_cv_check_socklen_t,[ac_cv_check_socklen_t=''
302         AC_TRY_COMPILE([
303 #include <sys/types.h>
304 #include <sys/socket.h>
305 #ifdef __cplusplus
306 extern "C" {
307 #endif
308 #define try 1
309 #ifdef AIX
310 #if AIX >= 51
311 #define try 0
312 #endif
313 #endif
314 #if try
315 extern int accept(int, struct sockaddr *, socklen_t *);
316 #endif
317 #ifdef __cplusplus
318 }
319 #endif
320         ],,[ac_cv_check_socklen_t=socklen_t],[
321                 AC_TRY_COMPILE([
322 #include <sys/types.h>
323 #include <sys/socket.h>
324 #ifdef __cplusplus
325 extern "C" {
326 #endif
327 #define try 1
328 #ifdef AIX
329 #if AIX >= 42
330 #define try 0
331 #endif
332 #endif
333 #if try
334 extern int accept(int, struct sockaddr *, size_t t *);
335 #endif
336 #ifdef __cplusplus
337 }
338 #endif
339 ],,[ac_cv_check_socklen_t=size_t],[ac_cv_check_socklen_t=int])
340                 ])
341         ])
342 AC_MSG_RESULT([$ac_cv_check_socklen_t])
343 AC_DEFINE_UNQUOTED([YAZ_SOCKLEN_T],[$ac_cv_check_socklen_t],[socklen_t type])
344 dnl
345 dnl ------ tcpd
346 AC_ARG_ENABLE([tcpd],[  --enable-tcpd[=PREFIX]  enable TCP wrapper for server if available])
347 if test "$enable_tcpd" -a "$enable_tcpd" != "no"; then
348     oldLibs=$LIBS
349     oldCPPFLAGS=$CPPFLAGS
350     if test "$enable_tcpd" != "yes"; then
351         LIBS="$LIBS -L$enable_tcpd/lib"
352         CPPFLAGS="$CPPFLAGS -I$enable_tcpd/include"
353     fi
354     AC_MSG_CHECKING([for working tcpd.h])
355     LIBS="$LIBS -lwrap"
356     AC_TRY_LINK([#include <syslog.h>
357 #include <tcpd.h>
358             int allow_severity = LOG_INFO;
359             int deny_severity = LOG_WARNING;],
360         [struct request_info request_info; int i;
361             i = hosts_access(&request_info);],
362         tcpd_ok=1, tcpd_ok=0)
363     LIBS=$oldLibs
364     if test "$tcpd_ok" = "0"; then
365         AC_MSG_RESULT([no])
366         AC_MSG_ERROR([tcpd development libraries missing])
367         CPPFLAGS=$oldCPPFLAGS
368     else
369         TCPD_LIBS="-lwrap"
370         AC_MSG_RESULT([yes])
371         AC_DEFINE([HAVE_TCPD_H],1,[Define to 1 if tcp wrap library is present])
372     fi
373 fi
374 AC_SUBST([TCPD_LIBS])
375 dnl
376 AC_SUBST([YAZ_CONFIG_CFLAGS])
377 dnl
378 dnl ------ POSIX Threads
379 HAVETHREADS=0
380 AC_ARG_ENABLE([threads],[  --disable-threads       disable POSIX threads],[enable_threads=$enableval],[enable_threads=yes])
381 if test "$enable_threads" = "yes" -a "$HAVETHREADS" = "0"; then
382     ACX_PTHREAD([
383             OCFLAGS=$CFLAGS
384             CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
385             dnl unfortunately empty thread lib spec is problematic because
386             dnl 'yaz-config --cflags' is not always passed to linker in
387             dnl applications using YAZ (such as Zebra).
388             if test "x$PTHREAD_LIBS" = "x"; then
389                 OLIBS=$LIBS
390                 for lib in -lpthread -lpthreads -lc_r; do
391                     LIBS="$lib $OLIBS"
392                     AC_TRY_LINK([ #include <pthread.h> ],
393                             [ pthread_t id; pthread_join(id, 0); ],
394                             [ PTHREAD_LIBS=$lib; break ]
395                         )
396                 done
397                 LIBS=$OLIBS
398             fi
399             LIBS="$LIBS $PTHREAD_LIBS"
400             AC_DEFINE(YAZ_POSIX_THREADS,1,[Define to 1 if POSIX threads is present])
401             YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_POSIX_THREADS=1"
402             ])
403 fi
404
405 dnl ----- libXSLT/libEXLT/libXML2
406 AC_SUBST([XML2_CFLAGS])
407
408 xml_enabled=false
409 YAZ_LIBXML2([
410         AC_DEFINE(YAZ_HAVE_XML2,1,[Define to 1 if Libxml2 is present])
411         YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_HAVE_XML2=1"
412         xml_enabled=true
413     ])
414
415 if test "$xml_enabled" = "true"; then
416     YAZ_LIBXSLT([
417             AC_DEFINE(YAZ_HAVE_XSLT,1,[Define to 1 if Libxslt is present])
418             YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_HAVE_XSLT=1"
419         ])
420     YAZ_LIBEXSLT([
421             AC_DEFINE(YAZ_HAVE_EXSLT,1,[Define to 1 if EXSLT is present])
422             YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_HAVE_EXSLT=1"
423         ])
424
425 fi
426 YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS $XML2_CFLAGS"
427
428 if test "$XML2_LIBS"; then
429     LIBS="$XML2_LIBS $LIBS"
430 fi
431
432 dnl
433 dnl
434 AC_CHECK_ICU([3.4],[
435         if test "$xml_enabled" = "true"; then
436             ICU_CPPFLAGS="$ICU_CPPFLAGS -D YAZ_HAVE_ICU=1"
437         else
438             ICU_CPPFLAGS=""
439             AC_MSG_WARN([ICU support disabled because XML support is unavailable])
440         fi
441 ])
442 dnl ------ versioning
443 dnl
444 WIN_FILEVERSION=`echo $PACKAGE_VERSION | $AWK 'BEGIN { FS = "."; } { m = $4; printf("%d,%d,%d,%d", $1, $2, $3 == "" ? "0" : $3, $4 == "" ? "1" : $4);}'`
445 AC_SUBST([WIN_FILEVERSION])
446 VERSION_HEX=`echo $PACKAGE_VERSION | $AWK 'BEGIN { FS = "."; } { printf("%x", ($1 * 256 + $2) * 256 + $3);}'`
447 AC_SUBST([VERSION_HEX])
448 if test -d ${srcdir}/.git; then
449     VERSION_SHA1=`git show --pretty=format:%H|head -1`
450 else
451     VERSION_SHA1=`head -1 ${srcdir}/ChangeLog|awk '{print $2}'`
452 fi
453 AC_SUBST([VERSION_SHA1])
454 dnl
455 dnl ------ Makefiles
456 dnl
457 AC_OUTPUT([
458 Makefile
459 src/Makefile
460 test/Makefile
461 util/Makefile
462 include/Makefile
463 include/yaz/Makefile
464 client/Makefile
465 ztest/Makefile
466 zoom/Makefile
467 doc/Makefile
468 doc/local0.ent
469 doc/common/Makefile
470 doc/common/print.dsl
471 etc/Makefile
472 yaz-config
473 yaz.pc
474 Doxyfile
475 win/version.nsi
476 include/yaz/yaz-version.h
477 ],[
478         sed s%echo_source=yes%echo_source=no%g < yaz-config > util/yaz-config && chmod +x yaz-config util/yaz-config
479         diff doc/local.ent doc/local0.ent >/dev/null 2>/dev/null \
480                 || cp doc/local0.ent doc/local.ent
481     ]
482 )
483
484
485 echo \
486 "------------------------------------------------------------------------
487 Configuration:
488
489   YAZ Package:                ${PACKAGE}
490   YAZ Version:                ${VERSION}
491   Bugreport:                  ${PACKAGE_BUGREPORT}
492   Source code location:       ${srcdir}
493   C Preprocessor:             ${CPP}
494   C Preprocessor flags:       ${CPPFLAGS}
495   C Compiler:                 ${CC}
496   C Compiler flags:           ${CFLAGS}
497   Linker flags:               ${LDFLAGS}
498   Linked libs:                ${LIBS}
499   Host System Type:           ${host}
500   Install path:               ${prefix}
501   Automake:                   ${AUTOMAKE}
502   Archiver:                   ${AR}
503   Ranlib:                     ${RANLIB}
504
505 ------------------------------------------------------------------------"
506 dnl Local Variables:
507 dnl mode:shell-script
508 dnl sh-indentation: 2
509 dnl sh-basic-offset: 4
510 dnl End: