Recognise yet ANOTHER location where docbookx.dtd may be found -- this
[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.164 2005-01-04 09:41:34 adam Exp $
4 AC_INIT(include/yaz/yaz-version.h)
5 AM_INIT_AUTOMAKE(yaz, 2.0.31)
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 AC_SUBST(SSL_CFLAGS)
37 openssl=no
38 AC_ARG_WITH(openssl, [  --with-openssl[=PREFIX]   OpenSSL library in PREFIX], [openssl=$withval])
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         AC_MSG_CHECKING([for SSL])
83         if test "$sslver" != "no"; then
84                 SSL_CFLAGS="-DHAVE_OPENSSL_SSL_H=1 $SSL_CFLAGS"
85                 AC_MSG_RESULT([$sslver])
86         else
87                 SSL_CFLAGS=""
88                 AC_MSG_RESULT([None])
89                 AC_MSG_ERROR([OpenSSL development libraries missing])
90         fi
91 fi
92 dnl
93 dnl ------ GNU Readline
94 READLINE_SHARED_LIBADD=""
95 AC_CHECK_LIB(ncurses, tgetent, [READLINE_SHARED_LIBADD="-lncurses"],
96         AC_CHECK_LIB(termcap, tgetent, [READLINE_SHARED_LIBADD="-ltermcap"])
97 )
98 READLINE_LIBS=""
99 AC_CHECK_LIB(readline, readline, [READLINE_LIBS="$READLINE_LIBS -lreadline $READLINE_SHARED_LIBADD"],,$READLINE_SHARED_LIBADD)
100 AC_CHECK_LIB(history, add_history, [READLINE_LIBS="$READLINE_LIBS -lhistory"])
101 if test "$ac_cv_lib_readline_readline" = "yes"; then
102         AC_CHECK_HEADERS(readline/readline.h readline/history.h)
103         xLIBS=$LIBS
104         LIBS="$LIBS $READLINE_LIBS"
105         AC_TRY_LINK([
106         #include <stdio.h>
107         #include <readline/readline.h>
108         ],[
109                 rl_attempted_completion_over = 0;
110         ],AC_DEFINE(HAVE_READLINE_COMPLETION_OVER))
111         AC_TRY_LINK([
112         #include <stdio.h>
113         #include <readline/readline.h>
114         ],[
115                 rl_completion_matches (0, 0);
116         ],[AC_DEFINE(HAVE_READLINE_RL_COMPLETION_MATCHES)])
117         LIBS=$xLIBS
118 fi
119 dnl ------ iconv
120 AC_ARG_WITH(iconv, [  --with-iconv[=PREFIX]     iconv library in PREFIX])
121 if test "$with_iconv" != "no"; then
122         AC_MSG_CHECKING(for iconv)
123         oldLIBS="$LIBS"
124         oldCPPFLAGS="${CPPFLAGS}"
125         if test "$with_iconv" != "yes" -a "$with_iconv" != ""; then
126                 LIBS="$LIBS -L${with_iconv}/lib"
127                 CPPFLAGS="${CPPFLAGS} -I${with_iconv}/include"
128         fi
129         AC_TRY_LINK([
130                 #include <iconv.h>
131         ],[
132                 iconv_t t = iconv_open("", "");
133         ],[
134                 AC_DEFINE(HAVE_ICONV_H)
135                 AC_MSG_RESULT(yes)
136         ],[
137                 LIBS="$LIBS -liconv"
138                 AC_TRY_LINK([
139                         #include <iconv.h>
140                 ],[
141                         iconv_t t = iconv_open("", "");
142                 ],[
143                         AC_DEFINE(HAVE_ICONV_H)
144                         AC_MSG_RESULT(yes)
145                 ],[
146                         LIBS="$oldLIBS"
147                         CPPFLAGS="$oldCPPFLAGS"
148                         AC_MSG_RESULT(no)
149                 ])
150         ])
151 fi
152 dnl ------ various functions
153 AC_CHECK_FUNCS(vsnprintf gettimeofday poll strerror_r)
154 if test "$ac_cv_func_poll" = "yes"; then
155         AC_CHECK_HEADERS(sys/poll.h)
156 fi
157 dnl ------ socklen_t
158 dnl We check for socklen_t by making prototypes with the
159 dnl various types. First socklen_t, then size_t, finally int.
160 dnl If the prototype succeeds, we're probably safe.
161 dnl That works if accept is not preprocessor defined (such sa AIX)
162 AC_MSG_CHECKING([for socklen_t])
163 AC_CACHE_VAL(ac_cv_check_socklen_t,[ac_cv_check_socklen_t=''
164         AC_TRY_COMPILE([
165 #include <sys/types.h>
166 #include <sys/socket.h>
167 #ifdef __cplusplus
168 extern "C" {
169 #endif
170 #define try 1
171 #ifdef AIX
172 #if AIX >= 51
173 #define try 0
174 #endif
175 #endif
176 #if try
177 extern int accept(int, struct sockaddr *, socklen_t *);
178 #endif
179 #ifdef __cplusplus
180 }
181 #endif
182         ],,[ac_cv_check_socklen_t=socklen_t],[
183                 AC_TRY_COMPILE([
184 #include <sys/types.h>
185 #include <sys/socket.h>
186 #ifdef __cplusplus
187 extern "C" {
188 #endif
189 #define try 1
190 #ifdef AIX
191 #if AIX >= 42
192 #define try 0
193 #endif
194 #endif
195 #if try
196 extern int accept(int, struct sockaddr *, size_t t *);
197 #endif
198 #ifdef __cplusplus
199 }
200 #endif
201                 ],,[ac_cv_check_socklen_t=size_t],[ac_cv_check_socklen_t=int])
202         ])
203 ])
204 AC_MSG_RESULT($ac_cv_check_socklen_t)
205 AC_DEFINE_UNQUOTED(YAZ_SOCKLEN_T,$ac_cv_check_socklen_t)
206 AC_DEFINE(YAZ_USE_NEW_LOG)
207 dnl
208 dnl ------ tcpd
209 AC_ARG_ENABLE(tcpd,[  --enable-tcpd[=PREFIX]  enable TCP wrapper for server if available])
210 if test "$enable_tcpd" -a "$enable_tcpd" != "no"; then
211         oldLibs=$LIBS
212         oldCPPFLAGS=$CPPFLAGS
213         if test "$enable_tcpd" != "yes"; then
214                 LIBS="$LIBS -L$enable_tcpd/lib"
215                 CPPFLAGS="$CPPFLAGS -I$enable_tcpd/include"
216         fi
217         AC_MSG_CHECKING(for working tcpd.h)
218         LIBS="$LIBS -lwrap -lnsl"
219         AC_TRY_LINK([#include <syslog.h>
220 #include <tcpd.h>
221         int allow_severity = LOG_INFO;
222         int deny_severity = LOG_WARNING;],
223         [struct request_info request_info; int i;
224         i = hosts_access(&request_info);],
225         tcpd_ok=1, tcpd_ok=0)
226         if test "$tcpd_ok" = "0"; then
227                 AC_MSG_RESULT(no)
228                 AC_MSG_ERROR([tcpd development libraries missing])
229                 LIBS=$oldLibs
230                 CPPFLAGS=$oldCPPFLAGS
231         else
232                 AC_MSG_RESULT(yes)
233                 AC_DEFINE(HAVE_TCPD_H)
234         fi
235 fi
236 dnl
237 dnl ------ Headers
238 AC_CHECK_HEADERS(fnmatch.h wchar.h locale.h langinfo.h)
239 AC_STDC_HEADERS
240 if test "$ac_cv_header_stdc" = "no"; then
241         AC_MSG_WARN(Your system doesn't seem to support ANSI C)
242 fi
243 dnl
244 AC_SUBST(LIBTHREAD)
245 AC_SUBST(CFLAGSTHREADS)
246 HAVETHREADS=0
247 CFLAGSTHREADS=""
248 LIBTHREAD=""
249 dnl
250 dnl ------ GNU threads
251 AC_ARG_ENABLE(pth, [  --enable-pth            enable GNU threads],[enable_pth=$enableval],[enable_pth=no])
252 AC_SUBST(LIBPTH)
253 if test "$enable_pth" = "yes"; then
254         OLIBS=$LIBS
255         AC_CHECK_LIB(pth,main)
256         if test "$ac_cv_lib_pth_main" = "yes"; then
257                 AC_CHECK_HEADERS(pth.h)
258                 if test "$ac_cv_header_pth_h" = "yes"; then
259                         LIBTHREAD="-lpth"
260                         CFLAGSTHREADS="-DYAZ_GNU_THREADS=1"
261                         HAVETHREADS=1
262                 fi
263         fi      
264         LIBS=$OLIBS
265 fi
266 dnl
267 dnl ------ POSIX Threads
268 AC_ARG_ENABLE(threads, [  --disable-threads       disable POSIX threads],[enable_threads=$enableval],[enable_threads=yes])
269 if test "$enable_threads" = "yes" -a "$HAVETHREADS" = "0"; then
270         OLIBS=$LIBS
271         OCC=$CC
272         AC_CHECK_LIB(pthread,main)
273         AC_MSG_CHECKING(for working POSIX Threads)
274         AC_TRY_LINK([#include <pthread.h>
275         void *func(void *p) { return 0; }
276         ],[
277         pthread_t pthread_id;
278         pthread_create (&pthread_id, 0, func, 0);],
279                 thread_ok=yes,thread_ok=no)
280         if test "$thread_ok" = "yes"; then
281                 AC_MSG_RESULT(yes)
282                 LIBTHREAD="-lpthread"
283                 CFLAGSTHREADS="-DYAZ_POSIX_THREADS=1 -D_REENTRANT"
284                 HAVETHREADS=1
285         else
286                 CC="$CC -pthread"
287                 AC_TRY_LINK([#include <pthread.h>
288                         void *func(void *p) { return 0; }
289                         ],[
290                         pthread_t pthread_id;
291                         pthread_create (&pthread_id, 0, func, 0);],
292                         thread_ok=yes,thread_ok=no)
293                 if test "$thread_ok" = "yes"; then
294                         AC_MSG_RESULT([yes,BSD])
295                         CFLAGSTHREADS="-pthread -DYAZ_POSIX_THREADS=1 -D_REENTRANT"
296                         LIBTHREAD="-pthread"
297                         HAVETHREADS=1
298                 fi
299         fi
300         if test "$thread_ok" = "no"; then
301                 AC_MSG_RESULT(no)
302         fi
303         CC=$OCC
304         LIBS=$OLIBS
305 fi
306 AM_CONDITIONAL(ISTHR, test $HAVETHREADS = "1")
307 dnl
308 dnl ----- libXML2
309 AC_SUBST(XML2_LIBS)
310 AC_SUBST(XML2_CFLAGS)
311 xml2dir=default
312 AC_ARG_WITH(xml2, [  --with-xml2[=PREFIX]      use libxml2 in PREFIX],[xml2dir=$withval])
313 if test "$xml2dir" = "yes" -o "$xml2dir" = "default"; then
314         for d in /usr /usr/local; do
315                 if test -x $d/bin/xml2-config; then
316                         xml2dir=$d
317                 fi
318         done
319 fi
320 if test "$xml2dir" != "no"; then
321         AC_MSG_CHECKING(for libXML2)
322         if test -x $xml2dir/bin/xml2-config; then
323                 XML2_LIBS=`$xml2dir/bin/xml2-config --libs`
324                 LIBS="$XML2_LIBS $LIBS"
325                 XML2_CFLAGS=`$xml2dir/bin/xml2-config --cflags`
326                 XML2_VER=`$xml2dir/bin/xml2-config --version`
327                 AC_MSG_RESULT($XML2_VER)
328                 AC_DEFINE(HAVE_XML2)
329         else
330                 AC_MSG_RESULT([Not found])
331                 if test "$xml2dir" != "default"; then
332                         AC_MSG_ERROR([libXML2 development libraries missing])
333                 fi
334         fi
335 fi
336 dnl
337 dnl ------ Memory debugging
338 AC_ARG_ENABLE(memdebug, [  --enable-memdebug       enable memory debugging],[enable_memdebug=$enableval],[enable_memdebug=none])
339 if test "$enable_memdebug" = "yes"; then
340         AC_DEFINE(TRACE_XMALLOC,2)
341 elif test "$enable_memdebug" = "no"; then
342         AC_DEFINE(TRACE_XMALLOC,0)
343 fi
344 dnl
345 dnl ------ Using this for "in-source" yaz-config
346 AC_SUBST(YAZ_SRC_ROOT)
347 AC_SUBST(YAZ_BUILD_ROOT)
348 YAZ_SRC_ROOT=`cd ${srcdir}; pwd`
349 YAZ_BUILD_ROOT=`pwd`
350 dnl
351 dnl ------ Makefiles
352 dnl
353 AC_OUTPUT([
354 Makefile
355 yaz.spec
356 src/Makefile
357 test/Makefile
358 util/Makefile
359 include/Makefile
360 include/yaz/Makefile
361 client/Makefile
362 ztest/Makefile
363 zoom/Makefile
364 doc/Makefile
365 doc/yaz.xml
366 doc/yazhtml.dsl
367 doc/yazphp.dsl
368 doc/yazprint.dsl
369 doc/tkl.xsl
370 doc/yazhtml.xsl
371 etc/Makefile
372 yaz-config
373 Doxyfile
374 ],[sed s%yaz_echo_source=yes%yaz_echo_source=no%g < yaz-config > util/yaz-config && chmod +x yaz-config util/yaz-config])