Bump version to 3.0.45 due to new functions.
[yaz-moved-to-github.git] / configure.ac
1 dnl This file is part of the YAZ toolkit.
2 dnl Copyright (C) 1995-2009 Index Data
3 AC_PREREQ([2.60])
4 AC_INIT([yaz],[3.0.45],[yaz-help@indexdata.dk])
5 AC_CONFIG_SRCDIR([configure.ac])
6 AC_CONFIG_AUX_DIR([config])
7 AM_INIT_AUTOMAKE([1.9])
8 dnl
9 AC_SUBST([READLINE_LIBS])
10 AC_SUBST([YAZ_CONF_CFLAGS])
11 dnl ------ Checking programs
12 AC_PROG_CC
13 AC_PROG_CPP
14 AC_CHECK_PROGS([YACC], 'bison -y')
15 test -z "$YACC" && AC_MSG_WARN([GNU bison not found])
16 AC_CHECK_PROGS([TCLSH], [tclsh tclsh8.5 tclsh8.4 tclsh8.3 tclsh8.2], [tclsh])
17 AC_PROG_INSTALL
18 AM_PROG_LIBTOOL
19 AC_PATH_PROG([pkgconfigpath],[pkg-config],[NONE])
20 dnl
21 YAZ_DOC
22 dnl 
23 dnl
24 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 netdb.h arpa/inet.h netinet/tcp.h netinet/in_systm.h],[],[],[])
25 AC_CHECK_HEADERS([net/if.h netinet/in.h netinet/if_ether.h],[],[],[
26  #if HAVE_SYS_TYPES_H
27  #include <sys/types.h>
28  #endif
29  #if HAVE_SYS_SOCKET_H
30  #include <sys/socket.h>
31  #endif
32  #if HAVE_NET_IF_H
33  #include <net/if.h>
34  #endif
35  #if HAVE_NETINET_IN_H
36  #include <netinet/in.h>
37  #endif
38 ])
39 AC_HEADER_STDC
40 if test "$ac_cv_header_stdc" = "no"; then
41     AC_MSG_WARN([Your system doesn not seem to support ANSI C])
42 fi
43 dnl ----- Types
44 AC_CHECK_TYPES([long long])
45 dnl
46 dnl ----- Sockets
47 checkBoth=0
48 AC_CHECK_FUNC([connect])
49 if test "$ac_cv_func_connect" = "no"; then
50     AC_CHECK_LIB([socket],[main], LIBS="$LIBS -lsocket", checkBoth=1)
51 fi
52 if test "$checkBoth" = "1"; then
53     oldLibs=$LIBS
54     LIBS="$LIBS -lsocket -lnsl"
55     AC_CHECK_FUNC([accept], , [LIBS=$oldLibs])
56 fi
57 AC_CHECK_FUNC([gethostbyname], ,[AC_CHECK_LIB(nsl, main, [LIBS="$LIBS -lnsl"])])
58 dnl
59
60 dnl ------ OpenSSL
61 AC_SUBST([SSL_CFLAGS])
62 AC_SUBST([SSL_LIBS])
63 openssl=no
64 sslver=no
65 AC_ARG_WITH([openssl], [  --with-openssl[=PREFIX]   OpenSSL library in PREFIX], [openssl=$withval])
66 SSL_CFLAGS=""
67 SSL_LIBPATH=""
68 if test "$openssl" != "no"; then
69     if test "$openssl" != "yes" -a "$openssl" != "default"; then
70         if test -x $openssl/bin/pkg-config; then
71             if $openssl/bin/pkg-config --exists openssl; then
72                 SSL_CFLAGS=`$openssl/bin/pkg-config --cflags openssl`
73                 SSL_LIBS="`$openssl/bin/pkg-config --libs openssl`"
74                 sslver=`$openssl/bin/pkg-config --modversion openssl`
75             fi
76         fi
77         if test "$sslver" = "no"; then
78             SSL_CFLAGS="-I$openssl/include -I$openssl/include/openssl"
79             SSL_LIBPATH="-L$openssl/lib"
80         fi
81     else
82         if test "$pkgconfigpath" != "NONE"; then
83             if $pkgconfigpath --exists openssl; then
84                 SSL_CFLAGS=`$pkgconfigpath --cflags openssl`
85                 SSL_LIBS="`$pkgconfigpath --libs openssl`"
86                 sslver=`$pkgconfigpath --modversion openssl`
87             fi
88         fi
89         if test "$sslver" = "no"; then
90             SSL_CFLAGS="-I/usr/include/openssl"
91         fi
92     fi
93     if test "$sslver" = "no"; then
94         xLIBS="$LIBS";
95         xCPPFLAGS="$CPPFLAGS";
96         CPPFLAGS="$CPPFLAGS ${SSL_CFLAGS} ${SSL_LIBPATH}"
97         SSL_LIBS="${SSL_LIBPATH}"
98         AC_CHECK_LIB([crypto],[main])
99         if test "$ac_cv_lib_crypto_main" = "yes"; then
100             SSL_LIBS="${SSL_LIBS} -lcrypto"
101         fi
102         AC_CHECK_LIB([ssl],[SSL_new])
103         if test "$ac_cv_lib_ssl_SSL_new" = "yes"; then
104             AC_CHECK_HEADER([openssl/ssl.h],[sslver=yes])
105             SSL_LIBS="${SSL_LIBS} -lssl"
106         fi
107         if test "$sslver" != "yes"; then
108             SSL_LIBS=""
109         fi
110         LIBS="$xLIBS"
111         CPPFLAGS="$xCPPFLAGS"
112     fi
113     AC_MSG_CHECKING([for SSL])
114     if test "$sslver" != "no"; then
115         SSL_CFLAGS="-DHAVE_OPENSSL_SSL_H=1 $SSL_CFLAGS"
116         AC_MSG_RESULT([$sslver])
117     else
118         SSL_CFLAGS=""
119         AC_MSG_RESULT([None])
120         if test "$openssl" != "default"; then
121             AC_MSG_ERROR([OpenSSL development libraries missing])
122         fi
123     fi
124 fi
125 dnl ------ GNU TLS
126 gnutls=default
127 AC_ARG_WITH([gnutls], [  --with-gnutls[=PREFIX]    GNU TLS library in PREFIX], [gnutls=$withval])
128 if test "$gnutls" != "no" -a "$sslver" = "no"; then
129     gnutlsver=no
130     if test "$gnutls" != "yes" -a "$gnutls" != "default"; then
131         if test -x $gnutls/bin/pkg-config; then
132             if $gnutls/bin/pkg-config --exists gnutls; then
133                 SSL_CFLAGS=`$gnutls/bin/pkg-config --cflags gnutls`
134                 SSL_LIBS="`$gnutls/bin/pkg-config --libs gnutls`"
135                 gnutlsver=`$gnutls/bin/pkg-config --modversion gnutls`
136             fi
137         fi
138     else
139         if test "$pkgconfigpath" != "NONE"; then
140             if $pkgconfigpath --exists gnutls; then
141                 SSL_CFLAGS=`$pkgconfigpath --cflags gnutls`
142                 SSL_LIBS="`$pkgconfigpath --libs gnutls`"
143                 gnutlsver=`$pkgconfigpath --modversion gnutls`
144             fi
145         fi
146     fi
147     AC_MSG_CHECKING([for GNU TLS])
148     if test "$gnutlsver" != "no"; then
149         SSL_CFLAGS="-DHAVE_GNUTLS_H=1 $SSL_CFLAGS"
150         AC_MSG_RESULT([$gnutlsver])
151     else
152         SSL_CFLAGS=""
153         AC_MSG_RESULT([None])
154         if test "$gnutls" != "default"; then
155             AC_MSG_ERROR([GNU TLS development libraries missing])
156         fi
157     fi
158 fi
159 dnl
160 dnl ------ GNU Readline
161 READLINE_SHARED_LIBADD=""
162 AC_CHECK_LIB([ncurses],[tgetent],[READLINE_SHARED_LIBADD="-lncurses"],
163     AC_CHECK_LIB([termcap],[tgetent],[READLINE_SHARED_LIBADD="-ltermcap"])
164 )
165 READLINE_LIBS=""
166 AC_CHECK_LIB([readline],[readline],[READLINE_LIBS="$READLINE_LIBS -lreadline $READLINE_SHARED_LIBADD"],,$READLINE_SHARED_LIBADD)
167 AC_CHECK_LIB([history],[add_history],[READLINE_LIBS="$READLINE_LIBS -lhistory"])
168 if test "$ac_cv_lib_readline_readline" = "yes"; then
169     AC_CHECK_HEADERS([readline/readline.h readline/history.h])
170     xLIBS=$LIBS
171     LIBS="$LIBS $READLINE_LIBS"
172     AC_TRY_LINK([
173         #include <stdio.h>
174         #include <readline/readline.h>
175             ],[
176             rl_attempted_completion_over = 0;
177             ],AC_DEFINE([HAVE_READLINE_COMPLETION_OVER]))
178     AC_TRY_LINK([
179         #include <stdio.h>
180         #include <readline/readline.h>
181             ],[
182             rl_completion_matches (0, 0);
183             ],[AC_DEFINE([HAVE_READLINE_RL_COMPLETION_MATCHES])])
184     LIBS=$xLIBS
185 fi
186 dnl ------ iconv
187 AC_ARG_WITH([iconv],[  --with-iconv[=PREFIX]     iconv library in PREFIX])
188 if test "$with_iconv" != "no"; then
189     AC_MSG_CHECKING([for iconv])
190     oldLIBS="$LIBS"
191     oldCPPFLAGS="${CPPFLAGS}"
192     if test "$with_iconv" != "yes" -a "$with_iconv" != ""; then
193         LIBS="$LIBS -L${with_iconv}/lib"
194         CPPFLAGS="${CPPFLAGS} -I${with_iconv}/include"
195     fi
196     AC_TRY_LINK([
197                 #include <iconv.h>
198             ],[
199             iconv_t t = iconv_open("", "");
200             ],[
201             AC_DEFINE([HAVE_ICONV_H])
202             AC_MSG_RESULT([yes])
203             ],[
204             LIBS="$LIBS -liconv"
205             AC_TRY_LINK([
206                         #include <iconv.h>
207                     ],[
208             iconv_t t = iconv_open("", "");
209                     ],[
210             AC_DEFINE([HAVE_ICONV_H])
211             AC_MSG_RESULT([yes])
212                     ],[
213             LIBS="$oldLIBS"
214             CPPFLAGS="$oldCPPFLAGS"
215             AC_MSG_RESULT([no])
216             ])
217     ])
218 fi
219 dnl ------ various functions
220 AC_CHECK_FUNCS([getaddrinfo vsnprintf gettimeofday poll strerror_r localtime_r usleep fopen64])
221 case $host in
222     *-*-darwin*)
223         trypoll="no";
224         ;;
225     *)
226         trypoll="yes";
227         ;;
228 esac
229
230 if test "$ac_cv_func_poll" = "yes" -a "$trypoll" = "yes"; then
231     AC_CHECK_HEADERS([sys/poll.h])
232 fi
233 dnl ------ socklen_t
234 dnl We check for socklen_t by making prototypes with the
235 dnl various types. First socklen_t, then size_t, finally int.
236 dnl If the prototype succeeds, we are probably safe.
237 dnl That works if accept is not preprocessor defined (such sa AIX)
238 AC_MSG_CHECKING([for socklen_t])
239 AC_CACHE_VAL(ac_cv_check_socklen_t,[ac_cv_check_socklen_t=''
240         AC_TRY_COMPILE([
241 #include <sys/types.h>
242 #include <sys/socket.h>
243 #ifdef __cplusplus
244 extern "C" {
245 #endif
246 #define try 1
247 #ifdef AIX
248 #if AIX >= 51
249 #define try 0
250 #endif
251 #endif
252 #if try
253 extern int accept(int, struct sockaddr *, socklen_t *);
254 #endif
255 #ifdef __cplusplus
256 }
257 #endif
258         ],,[ac_cv_check_socklen_t=socklen_t],[
259                 AC_TRY_COMPILE([
260 #include <sys/types.h>
261 #include <sys/socket.h>
262 #ifdef __cplusplus
263 extern "C" {
264 #endif
265 #define try 1
266 #ifdef AIX
267 #if AIX >= 42
268 #define try 0
269 #endif
270 #endif
271 #if try
272 extern int accept(int, struct sockaddr *, size_t t *);
273 #endif
274 #ifdef __cplusplus
275 }
276 #endif
277 ],,[ac_cv_check_socklen_t=size_t],[ac_cv_check_socklen_t=int])
278                 ])
279         ])
280 AC_MSG_RESULT([$ac_cv_check_socklen_t])
281 AC_DEFINE_UNQUOTED([YAZ_SOCKLEN_T],[$ac_cv_check_socklen_t])
282 AC_DEFINE([YAZ_USE_NEW_LOG])
283 dnl
284 dnl ------ tcpd
285 AC_ARG_ENABLE([tcpd],[  --enable-tcpd[=PREFIX]  enable TCP wrapper for server if available])
286 if test "$enable_tcpd" -a "$enable_tcpd" != "no"; then
287     oldLibs=$LIBS
288     oldCPPFLAGS=$CPPFLAGS
289     if test "$enable_tcpd" != "yes"; then
290         LIBS="$LIBS -L$enable_tcpd/lib"
291         CPPFLAGS="$CPPFLAGS -I$enable_tcpd/include"
292     fi
293     AC_MSG_CHECKING([for working tcpd.h])
294     LIBS="$LIBS -lwrap"
295     AC_TRY_LINK([#include <syslog.h>
296 #include <tcpd.h>
297             int allow_severity = LOG_INFO;
298             int deny_severity = LOG_WARNING;],
299         [struct request_info request_info; int i;
300             i = hosts_access(&request_info);],
301         tcpd_ok=1, tcpd_ok=0)
302     if test "$tcpd_ok" = "0"; then
303         AC_MSG_RESULT([no])
304         AC_MSG_ERROR([tcpd development libraries missing])
305                 LIBS=$oldLibs
306                 CPPFLAGS=$oldCPPFLAGS
307     else
308         AC_MSG_RESULT([yes])
309         AC_DEFINE([HAVE_TCPD_H])
310     fi
311 fi
312 dnl
313 AC_SUBST([YAZ_CONFIG_CFLAGS])
314 dnl
315 dnl ------ POSIX Threads
316 HAVETHREADS=0
317 AC_ARG_ENABLE([threads],[  --disable-threads       disable POSIX threads],[enable_threads=$enableval],[enable_threads=yes])
318 if test "$enable_threads" = "yes" -a "$HAVETHREADS" = "0"; then
319     ACX_PTHREAD([
320             OCFLAGS=$CFLAGS
321             CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
322             dnl unfortunately empty thread lib spec is problematic because 
323             dnl 'yaz-config --cflags' is not always passed to linker in 
324             dnl applications using YAZ (such as Zebra).
325             if test "x$PTHREAD_LIBS" = "x"; then
326                 OLIBS=$LIBS
327                 for lib in -lpthread -lpthreads -lc_r; do
328                     LIBS="$lib $OLIBS"
329                     AC_TRY_LINK([ #include <pthread.h> ],
330                             [ pthread_t id; pthread_join(id, 0); ],
331                             [ PTHREAD_LIBS=$lib; break ]
332                         )
333                 done
334                 LIBS=$OLIBS
335             fi
336             CFLAGS=$OCFLAGS
337             PTHREAD_CFLAGS="$PTHREAD_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) 
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)
354             YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_HAVE_XSLT=1"
355         ])
356     YAZ_LIBEXSLT([
357             AC_DEFINE(YAZ_HAVE_EXSLT)
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
379 dnl ------ Memory debugging
380 AC_ARG_ENABLE([memdebug],[  --enable-memdebug       enable memory debugging],[enable_memdebug=$enableval],[enable_memdebug=none])
381 if test "$enable_memdebug" = "yes"; then
382     AC_DEFINE([TRACE_XMALLOC],[2])
383 elif test "$enable_memdebug" = "no"; then
384     AC_DEFINE([TRACE_XMALLOC],[0])
385 fi
386 dnl
387 dnl ------ Using this for "in-source" yaz-config
388 AC_SUBST([YAZ_SRC_ROOT])
389 AC_SUBST([YAZ_BUILD_ROOT])
390 YAZ_SRC_ROOT=`cd ${srcdir}; pwd`
391 YAZ_BUILD_ROOT=`pwd`
392 dnl
393 dnl ------ versioning
394 dnl
395 WIN_FILEVERSION=`echo $PACKAGE_VERSION | $AWK 'BEGIN { FS = "."; } { m = $4; printf("%d,%d,%d,%d", $1, $2, $3 == "" ? "0" : $3, $4 == "" ? "1" : $4);}'`
396 AC_SUBST([WIN_FILEVERSION])
397 VERSION_HEX=`echo $PACKAGE_VERSION | $AWK 'BEGIN { FS = "."; } { printf("%x", ($1 * 256 + $2) * 256 + $3);}'`
398 AC_SUBST([VERSION_HEX])
399 if test -d ${srcdir}/.git; then
400     VERSION_SHA1=`git show --pretty=format:%H|head -1`
401 else
402     VERSION_SHA1=`head -1 ${srcdir}/ChangeLog|awk '{print $2}'`
403 fi
404 AC_SUBST([VERSION_SHA1])
405 dnl
406 dnl ------ Makefiles
407 dnl
408 AC_OUTPUT([
409 Makefile
410 yaz.spec
411 src/Makefile
412 test/Makefile
413 util/Makefile
414 include/Makefile
415 include/yaz/Makefile
416 client/Makefile
417 ztest/Makefile
418 zoom/Makefile
419 doc/Makefile
420 doc/local.ent
421 doc/common/Makefile
422 doc/common/print.dsl
423 etc/Makefile
424 yaz-config
425 yaz.pc
426 Doxyfile
427 win/version.nsi
428 include/yaz/yaz-version.h
429 ],[
430         sed s%yaz_echo_source=yes%yaz_echo_source=no%g < yaz-config > util/yaz-config && chmod +x yaz-config util/yaz-config
431     ]
432 )
433
434
435 echo \
436 "------------------------------------------------------------------------
437 Configuration:
438
439   YAZ Package:                ${PACKAGE}
440   YAZ Version:                ${VERSION}
441   Bugreport:                  ${PACKAGE_BUGREPORT}
442   Source code location:       ${srcdir}
443   C Preprocessor:             ${CPP}
444   C Preprocessor flags:       ${CPPFLAGS}
445   C Compiler:                 ${CC}
446   C Compiler flags:           ${CFLAGS}
447   Linker flags:               ${LDFLAGS}
448   Linked libs:                ${LIBS}
449   Host System Type:           ${host}
450   Install path:               ${prefix}
451   Automake:                   ${AUTOMAKE}
452   Archiver:                   ${AR}
453   Ranlib:                     ${RANLIB}
454
455 ------------------------------------------------------------------------"
456 dnl Local Variables:
457 dnl mode:shell-script
458 dnl sh-indentation: 2
459 dnl sh-basic-offset: 4
460 dnl End: