Towards 2.0.25
[yaz-moved-to-github.git] / configure.in
1 dnl YAZ Toolkit, Index Data 1994-2004
2 dnl See the file LICENSE for details.
3 dnl $Id: configure.in,v 1.153 2004-09-30 11:23:25 adam Exp $
4 AC_INIT(include/yaz/yaz-version.h)
5 AM_INIT_AUTOMAKE(yaz, 2.0.25)
6 AM_MAINTAINER_MODE
7 dnl
8 AC_SUBST(READLINE_LIBS)
9 AC_SUBST(YAZ_CONF_CFLAGS)
10 dnl ------ Checking programs
11 AC_PROG_CC
12 AC_PROG_CPP
13 AC_CHECK_PROGS(YACC, 'bison -y')
14 test -z "$YACC" && AC_MSG_WARN([GNU bison not found])
15 AC_PROG_INSTALL
16 AM_DISABLE_SHARED
17 AM_PROG_LIBTOOL
18 AC_PATH_PROG(pkgconfigpath, pkg-config, NONE)
19 dnl
20 YAZ_DOC
21 dnl 
22 dnl ----- Sockets
23 checkBoth=0
24 AC_CHECK_FUNC(connect)
25 if test "$ac_cv_func_connect" = "no"; then
26         AC_CHECK_LIB(socket, main, LIBS="$LIBS -lsocket", checkBoth=1)
27 fi
28 if test "$checkBoth" = "1"; then
29         oldLibs=$LIBS
30         LIBS="$LIBS -lsocket -lnsl"
31         AC_CHECK_FUNC(accept, , [LIBS=$oldLibs])
32 fi
33 AC_CHECK_FUNC(gethostbyname, , AC_CHECK_LIB(nsl, main, [LIBS="$LIBS -lnsl"]))
34 dnl
35 dnl ------ OpenSSL
36 openssl=no
37 AC_ARG_WITH(openssl, [  --with-openssl[=PREFIX]   OpenSSL library in PREFIX], [openssl=$withval])
38 USE_SSL=0
39 SSL_CFLAGS=""
40 SSL_LIBPATH=""
41 if test "$openssl" != "no"; then
42         sslver=no
43         if test "$openssl" != "yes"; then
44                 if test -x $openssl/bin/pkg-config; then
45                         if $openssl/bin/pkg-config --exists openssl; then
46                                 SSL_CFLAGS=`$openssl/bin/pkg-config --cflags openssl`
47                                 LIBS="$LIBS `$openssl/bin/pkg-config --libs openssl`"
48                                 sslver=`$openssl/bin/pkg-config --modversion openssl`
49                         fi
50                 fi
51                 if test "$sslver" = "no"; then
52                         SSL_CFLAGS="-I$openssl/include -I$openssl/include/openssl"
53                         SSL_LIBPATH="-L$openssl/lib"
54                 fi
55         else
56                 if test "$pkgconfigpath" != "NONE"; then
57                         if $pkgconfigpath --exists openssl; then
58                                 SSL_CFLAGS=`$pkgconfigpath --cflags openssl`
59                                 LIBS="$LIBS `$pkgconfigpath --libs openssl`"
60                                 sslver=`$pkgconfigpath --modversion openssl`
61                         fi
62                 fi
63                 if test "$sslver" = "no"; then
64                         SSL_CFLAGS="-I/usr/include/openssl"
65                 fi
66         fi
67         if test "$sslver" = "no"; then
68                 xLIBS="$LIBS";
69                 xCPPFLAGS="$CPPFLAGS";
70                 CPPFLAGS="$CPPFLAGS $SSL_CFLAGS $SSL_LIBPATH"
71                 AC_CHECK_LIB(crypto, main)
72                 AC_CHECK_LIB(ssl, SSL_new)
73                 if test "$ac_cv_lib_ssl_SSL_new" = "yes"; then
74                         AC_CHECK_HEADER(openssl/ssl.h,[sslver=yes])
75                         LIBS="$SSL_LIBPATH $LIBS"
76                 fi
77                 if test "$sslver" != "yes"; then
78                         LIBS="$xLIBS"
79                 fi
80                 CPPFLAGS="$xCPPFLAGS"
81         fi
82         if test "$sslver" != "no"; then
83                 CFLAGS="$CFLAGS -DHAVE_OPENSSL_SSL_H=1 $SSL_CFLAGS"
84                 USE_SSL=1
85         fi
86         AC_MSG_CHECKING([for SSL])
87         AC_MSG_RESULT($sslver)
88 fi
89 dnl
90 dnl ------ GNU Readline
91 READLINE_SHARED_LIBADD=""
92 AC_CHECK_LIB(ncurses, tgetent, [READLINE_SHARED_LIBADD="-lncurses"],
93         AC_CHECK_LIB(termcap, tgetent, [READLINE_SHARED_LIBADD="-ltermcap"])
94 )
95 READLINE_LIBS=""
96 AC_CHECK_LIB(readline, readline, [READLINE_LIBS="$READLINE_LIBS -lreadline $READLINE_SHARED_LIBADD"],,$READLINE_SHARED_LIBADD)
97 AC_CHECK_LIB(history, add_history, [READLINE_LIBS="$READLINE_LIBS -lhistory"])
98 if test "$ac_cv_lib_readline_readline" = "yes"; then
99         AC_CHECK_HEADERS(readline/readline.h readline/history.h)
100         xLIBS=$LIBS
101         LIBS="$LIBS $READLINE_LIBS"
102         AC_TRY_LINK([
103         #include <stdio.h>
104         #include <readline/readline.h>
105         ],[
106                 rl_attempted_completion_over = 0;
107         ],AC_DEFINE(HAVE_READLINE_COMPLETION_OVER))
108         AC_TRY_LINK([
109         #include <stdio.h>
110         #include <readline/readline.h>
111         ],[
112                 rl_completion_matches (0, 0);
113         ],[AC_DEFINE(HAVE_READLINE_RL_COMPLETION_MATCHES)])
114         LIBS=$xLIBS
115 fi
116 dnl ------ iconv
117 AC_ARG_WITH(iconv, [  --with-iconv[=PREFIX]     iconv library in PREFIX])
118 if test "$with_iconv" != "no"; then
119         AC_MSG_CHECKING(for iconv)
120         oldLIBS="$LIBS"
121         oldCPPFLAGS="${CPPFLAGS}"
122         if test "$with_iconv" != "yes" -a "$with_iconv" != ""; then
123                 LIBS="$LIBS -L${with_iconv}/lib"
124                 CPPFLAGS="${CPPFLAGS} -I${with_iconv}/include"
125         fi
126         AC_TRY_LINK([
127                 #include <iconv.h>
128         ],[
129                 iconv_t t = iconv_open("", "");
130         ],[
131                 AC_DEFINE(HAVE_ICONV_H)
132                 AC_MSG_RESULT(yes)
133         ],[
134                 LIBS="$LIBS -liconv"
135                 AC_TRY_LINK([
136                         #include <iconv.h>
137                 ],[
138                         iconv_t t = iconv_open("", "");
139                 ],[
140                         AC_DEFINE(HAVE_ICONV_H)
141                         AC_MSG_RESULT(yes)
142                 ],[
143                         LIBS="$oldLIBS"
144                         CPPFLAGS="$oldCPPFLAGS"
145                         AC_MSG_RESULT(no)
146                 ])
147         ])
148 fi
149 dnl ------ various functions
150 AC_CHECK_FUNCS(vsnprintf gettimeofday poll strerror_r)
151 if test "$ac_cv_func_poll" = "yes"; then
152         AC_CHECK_HEADERS(sys/poll.h)
153 fi
154 dnl ------ socklen_t
155 dnl We check for socklen_t by making prototypes with the
156 dnl various types. First socklen_t, then size_t, finally int.
157 dnl If the prototype succeeds, we're probably safe.
158 dnl That works if accept is not preprocessor defined (such sa AIX)
159 AC_MSG_CHECKING([for socklen_t])
160 AC_CACHE_VAL(ac_cv_check_socklen_t,[ac_cv_check_socklen_t=''
161         AC_TRY_COMPILE([
162 #include <sys/types.h>
163 #include <sys/socket.h>
164 #ifdef __cplusplus
165 extern "C" {
166 #endif
167 #define try 1
168 #ifdef AIX
169 #if AIX >= 51
170 #define try 0
171 #endif
172 #endif
173 #if try
174 extern int accept(int, struct sockaddr *, socklen_t *);
175 #endif
176 #ifdef __cplusplus
177 }
178 #endif
179         ],,[ac_cv_check_socklen_t=socklen_t],[
180                 AC_TRY_COMPILE([
181 #include <sys/types.h>
182 #include <sys/socket.h>
183 #ifdef __cplusplus
184 extern "C" {
185 #endif
186 #define try 1
187 #ifdef AIX
188 #if AIX >= 42
189 #define try 0
190 #endif
191 #endif
192 #if try
193 extern int accept(int, struct sockaddr *, size_t t *);
194 #endif
195 #ifdef __cplusplus
196 }
197 #endif
198                 ],,[ac_cv_check_socklen_t=size_t],[ac_cv_check_socklen_t=int])
199         ])
200 ])
201 AC_MSG_RESULT($ac_cv_check_socklen_t)
202 AC_DEFINE_UNQUOTED(YAZ_SOCKLEN_T,$ac_cv_check_socklen_t)
203 dnl
204 dnl ------ tcpd
205 AC_ARG_ENABLE(tcpd,[  --enable-tcpd[=PREFIX]  enable TCP wrapper for server if available])
206 if test "$enable_tcpd" != "" && test "$enable_tcpd" != "no"; then
207         oldLibs=$LIBS
208         oldCPPFLAGS=$CPPFLAGS
209         if test "$enable_tcpd" != "yes"; then
210                 LIBS="$LIBS -L$enable_tcpd/lib"
211                 CPPFLAGS="$CPPFLAGS -I$enable_tcpd/include"
212         fi
213         AC_MSG_CHECKING(for working tcpd.h)
214         LIBS="$LIBS -lwrap -lnsl"
215         AC_TRY_LINK([#include <syslog.h>
216 #include <tcpd.h>
217         int allow_severity = LOG_INFO;
218         int deny_severity = LOG_WARNING;],
219         [struct request_info request_info; int i;
220         i = hosts_access(&request_info);],
221         tcpd_ok=1, tcpd_ok=0)
222         if test "$tcpd_ok" = "0"; then
223                 AC_MSG_RESULT(no)
224                 LIBS=$oldLibs
225                 CPPFLAGS=$oldCPPFLAGS
226         else
227                 AC_MSG_RESULT(yes)
228                 AC_DEFINE(HAVE_TCPD_H)
229         fi
230 fi
231 dnl
232 dnl ------ Headers
233 AC_CHECK_HEADERS(fnmatch.h wchar.h locale.h langinfo.h)
234 AC_STDC_HEADERS
235 if test "$ac_cv_header_stdc" = "no"; then
236         AC_MSG_WARN(Your system doesn't seem to support ANSI C)
237 fi
238 dnl
239 AC_SUBST(LIBTHREAD)
240 AC_SUBST(CFLAGSTHREADS)
241 HAVETHREADS=0
242 CFLAGSTHREADS=""
243 LIBTHREAD=""
244 dnl
245 dnl ------ GNU threads
246 AC_ARG_ENABLE(pth, [  --enable-pth            enable GNU threads],[enable_pth=$enableval],[enable_pth=no])
247 AC_SUBST(LIBPTH)
248 if test "$enable_pth" = "yes"; then
249         OLIBS=$LIBS
250         AC_CHECK_LIB(pth,main)
251         if test "$ac_cv_lib_pth_main" = "yes"; then
252                 AC_CHECK_HEADERS(pth.h)
253                 if test "$ac_cv_header_pth_h" = "yes"; then
254                         LIBTHREAD="-lpth"
255                         CFLAGSTHREADS="-DYAZ_GNU_THREADS=1"
256                         HAVETHREADS=1
257                 fi
258         fi      
259         LIBS=$OLIBS
260 fi
261 dnl
262 dnl ------ POSIX Threads
263 AC_ARG_ENABLE(threads, [  --disable-threads       disable POSIX threads],[enable_threads=$enableval],[enable_threads=yes])
264 if test "$enable_threads" = "yes" -a "$HAVETHREADS" = "0"; then
265         OLIBS=$LIBS
266         OCC=$CC
267         AC_CHECK_LIB(pthread,main)
268         AC_MSG_CHECKING(for working POSIX Threads)
269         AC_TRY_LINK([#include <pthread.h>
270         void *func(void *p) { return 0; }
271         ],[
272         pthread_t pthread_id;
273         pthread_create (&pthread_id, 0, func, 0);],
274                 thread_ok=yes,thread_ok=no)
275         if test "$thread_ok" = "yes"; then
276                 AC_MSG_RESULT(yes)
277                 LIBTHREAD="-lpthread"
278                 CFLAGSTHREADS="-DYAZ_POSIX_THREADS=1 -D_REENTRANT"
279                 HAVETHREADS=1
280         else
281                 CC="$CC -pthread"
282                 AC_TRY_LINK([#include <pthread.h>
283                         void *func(void *p) { return 0; }
284                         ],[
285                         pthread_t pthread_id;
286                         pthread_create (&pthread_id, 0, func, 0);],
287                         thread_ok=yes,thread_ok=no)
288                 if test "$thread_ok" = "yes"; then
289                         AC_MSG_RESULT([yes,BSD])
290                         CFLAGSTHREADS="-pthread -DYAZ_POSIX_THREADS=1 -D_REENTRANT"
291                         LIBTHREAD="-pthread"
292                         HAVETHREADS=1
293                 fi
294         fi
295         if test "$thread_ok" = "no"; then
296                 AC_MSG_RESULT(no)
297         fi
298         CC=$OCC
299         LIBS=$OLIBS
300 fi
301 AM_CONDITIONAL(ISTHR, test $HAVETHREADS = "1")
302 dnl
303 dnl ----- libXML2
304 AC_SUBST(XML2_LIBS)
305 AC_SUBST(XML2_CFLAGS)
306 xml2dir=yes
307 AC_ARG_WITH(xml2, [  --with-xml2[=PREFIX]      use libxml2 in PREFIX],[xml2dir=$withval])
308 if test "$xml2dir" = "yes"; then
309         for d in /usr /usr/local; do
310                 if test -x $d/bin/xml2-config; then
311                         xml2dir=$d
312                 fi
313         done
314 fi
315 if test "$xml2dir" != "no"; then
316         AC_MSG_CHECKING(for libXML2)
317         if test -x $xml2dir/bin/xml2-config; then
318                 XML2_LIBS=`$xml2dir/bin/xml2-config --libs`
319                 LIBS="$XML2_LIBS $LIBS"
320                 XML2_CFLAGS=`$xml2dir/bin/xml2-config --cflags`
321                 XML2_VER=`$xml2dir/bin/xml2-config --version`
322                 AC_MSG_RESULT($XML2_VER)
323                 AC_DEFINE(HAVE_XML2)
324         else
325                 AC_MSG_RESULT(Not found)
326         fi
327 fi
328 dnl
329 dnl ------ Memory debugging
330 AC_ARG_ENABLE(memdebug, [  --enable-memdebug       enable memory debugging],[enable_memdebug=$enableval],[enable_memdebug=none])
331 if test "$enable_memdebug" = "yes"; then
332         AC_DEFINE(TRACE_XMALLOC,2)
333 elif test "$enable_memdebug" = "no"; then
334         AC_DEFINE(TRACE_XMALLOC,0)
335 fi
336 dnl
337 dnl ------ Using this for "in-source" yaz-config
338 AC_SUBST(YAZ_SRC_ROOT)
339 AC_SUBST(YAZ_BUILD_ROOT)
340 YAZ_SRC_ROOT=`cd ${srcdir}; pwd`
341 YAZ_BUILD_ROOT=`pwd`
342 dnl
343 dnl ------ Makefiles
344 dnl
345 AC_OUTPUT([
346 Makefile
347 yaz.spec
348 src/Makefile
349 test/Makefile
350 util/Makefile
351 include/Makefile
352 include/yaz/Makefile
353 client/Makefile
354 ztest/Makefile
355 zoom/Makefile
356 doc/Makefile
357 doc/yaz.xml
358 doc/yazhtml.dsl
359 doc/yazphp.dsl
360 doc/yazprint.dsl
361 doc/tkl.xsl
362 doc/yazhtml.xsl
363 etc/Makefile
364 yaz-config
365 ],[sed s%yaz_echo_source=yes%yaz_echo_source=no%g < yaz-config > util/yaz-config && chmod +x yaz-config util/yaz-config])