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