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