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