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