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