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