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