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