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