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