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