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