Update doc/common
[yaz-moved-to-github.git] / configure.ac
1 dnl This file is part of the YAZ toolkit.
2 dnl Copyright (C) 1995-2010 Index Data
3 AC_PREREQ([2.60])
4 AC_INIT([yaz],[4.0.13],[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 sys/prctl.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     LIBS=$oldLibs
303     if test "$tcpd_ok" = "0"; then
304         AC_MSG_RESULT([no])
305         AC_MSG_ERROR([tcpd development libraries missing])
306         CPPFLAGS=$oldCPPFLAGS
307     else
308         TCPD_LIBS="-lwrap"
309         AC_MSG_RESULT([yes])
310         AC_DEFINE([HAVE_TCPD_H])
311     fi
312 fi
313 AC_SUBST([TCPD_LIBS])
314 dnl
315 AC_SUBST([YAZ_CONFIG_CFLAGS])
316 dnl
317 dnl ------ POSIX Threads
318 HAVETHREADS=0
319 AC_ARG_ENABLE([threads],[  --disable-threads       disable POSIX threads],[enable_threads=$enableval],[enable_threads=yes])
320 if test "$enable_threads" = "yes" -a "$HAVETHREADS" = "0"; then
321     ACX_PTHREAD([
322             OCFLAGS=$CFLAGS
323             CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
324             dnl unfortunately empty thread lib spec is problematic because 
325             dnl 'yaz-config --cflags' is not always passed to linker in 
326             dnl applications using YAZ (such as Zebra).
327             if test "x$PTHREAD_LIBS" = "x"; then
328                 OLIBS=$LIBS
329                 for lib in -lpthread -lpthreads -lc_r; do
330                     LIBS="$lib $OLIBS"
331                     AC_TRY_LINK([ #include <pthread.h> ],
332                             [ pthread_t id; pthread_join(id, 0); ],
333                             [ PTHREAD_LIBS=$lib; break ]
334                         )
335                 done
336                 LIBS=$OLIBS
337             fi
338             LIBS="$LIBS $PTHREAD_LIBS"
339             CFLAGS="$CFLAGS -DYAZ_POSIX_THREADS=1"
340             YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_POSIX_THREADS=1"
341             ])
342 fi
343
344 dnl ----- libXSLT/libEXLT/libXML2
345 AC_SUBST([XML2_CFLAGS])
346
347 xml_enabled=false
348 YAZ_LIBXML2([
349         AC_DEFINE(YAZ_HAVE_XML2) 
350         YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_HAVE_XML2=1"
351         xml_enabled=true
352     ])
353
354 if test "$xml_enabled" = "true"; then
355     YAZ_LIBXSLT([
356             AC_DEFINE(YAZ_HAVE_XSLT)
357             YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_HAVE_XSLT=1"
358         ])
359     YAZ_LIBEXSLT([
360             AC_DEFINE(YAZ_HAVE_EXSLT)
361             YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_HAVE_EXSLT=1"
362         ])
363     
364 fi
365 YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS $XML2_CFLAGS"
366
367 if test "$XML2_LIBS"; then
368     LIBS="$XML2_LIBS $LIBS"
369 fi
370
371 dnl
372 dnl 
373 AC_CHECK_ICU([3.4],[
374         if test "$xml_enabled" = "true"; then
375             ICU_CPPFLAGS="$ICU_CPPFLAGS -D YAZ_HAVE_ICU=1"
376         else
377             ICU_CPPFLAGS=""
378             AC_MSG_WARN([ICU support disabled because XML support is unavailable])
379         fi
380 ])
381 dnl
382 dnl ------ Memory debugging
383 AC_ARG_ENABLE([memdebug],[  --enable-memdebug       enable memory debugging],[enable_memdebug=$enableval],[enable_memdebug=none])
384 if test "$enable_memdebug" = "yes"; then
385     AC_DEFINE([TRACE_XMALLOC],[2])
386 elif test "$enable_memdebug" = "no"; then
387     AC_DEFINE([TRACE_XMALLOC],[0])
388 fi
389 dnl
390 dnl ------ versioning
391 dnl
392 WIN_FILEVERSION=`echo $PACKAGE_VERSION | $AWK 'BEGIN { FS = "."; } { m = $4; printf("%d,%d,%d,%d", $1, $2, $3 == "" ? "0" : $3, $4 == "" ? "1" : $4);}'`
393 AC_SUBST([WIN_FILEVERSION])
394 VERSION_HEX=`echo $PACKAGE_VERSION | $AWK 'BEGIN { FS = "."; } { printf("%x", ($1 * 256 + $2) * 256 + $3);}'`
395 AC_SUBST([VERSION_HEX])
396 if test -d ${srcdir}/.git; then
397     VERSION_SHA1=`git show --pretty=format:%H|head -1`
398 else
399     VERSION_SHA1=`head -1 ${srcdir}/ChangeLog|awk '{print $2}'`
400 fi
401 AC_SUBST([VERSION_SHA1])
402 dnl
403 dnl ------ Makefiles
404 dnl
405 AC_OUTPUT([
406 Makefile
407 yaz.spec
408 src/Makefile
409 test/Makefile
410 util/Makefile
411 include/Makefile
412 include/yaz/Makefile
413 client/Makefile
414 ztest/Makefile
415 zoom/Makefile
416 doc/Makefile
417 doc/local.ent
418 doc/common/Makefile
419 doc/common/print.dsl
420 etc/Makefile
421 yaz-config
422 yaz.pc
423 Doxyfile
424 win/version.nsi
425 include/yaz/yaz-version.h
426 ],[
427         sed s%yaz_echo_source=yes%yaz_echo_source=no%g < yaz-config > util/yaz-config && chmod +x yaz-config util/yaz-config
428     ]
429 )
430
431
432 echo \
433 "------------------------------------------------------------------------
434 Configuration:
435
436   YAZ Package:                ${PACKAGE}
437   YAZ Version:                ${VERSION}
438   Bugreport:                  ${PACKAGE_BUGREPORT}
439   Source code location:       ${srcdir}
440   C Preprocessor:             ${CPP}
441   C Preprocessor flags:       ${CPPFLAGS}
442   C Compiler:                 ${CC}
443   C Compiler flags:           ${CFLAGS}
444   Linker flags:               ${LDFLAGS}
445   Linked libs:                ${LIBS}
446   Host System Type:           ${host}
447   Install path:               ${prefix}
448   Automake:                   ${AUTOMAKE}
449   Archiver:                   ${AR}
450   Ranlib:                     ${RANLIB}
451
452 ------------------------------------------------------------------------"
453 dnl Local Variables:
454 dnl mode:shell-script
455 dnl sh-indentation: 2
456 dnl sh-basic-offset: 4
457 dnl End: