Towards 2.0.2
[yaz-moved-to-github.git] / configure.in
1 dnl YAZ Toolkit, Index Data 1994-2003
2 dnl See the file LICENSE for details.
3 dnl $Id: configure.in,v 1.112 2003-04-28 21:02:15 adam Exp $
4 AC_INIT(include/yaz/yaz-version.h)
5 AM_INIT_AUTOMAKE(yaz, 2.0.2)
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 dnl
19 dnl ----- DOCBOOK DTD
20 AC_SUBST(DTD_DIR)
21 AC_ARG_WITH(dtd, [  --with-dtd[=DIR]        use docbookx.dtd in DIR],
22 [
23    if test -f "$withval/docbookx.dtd"; then
24       DTD_DIR=$withval
25    fi
26 ],[
27    AC_MSG_CHECKING(for docbookx.dtd)
28    for d in /usr/share/sgml/docbook/dtd/xml/4.1.2 \
29          /usr/share/sgml/docbook/xml-dtd-4.1.2* \
30          /usr/share/sgml/docbook/xml-dtd-4.1 \
31          /usr/share/sgml/docbook/dtd/xml/4.0 \
32             /usr/lib/sgml/dtd/docbook-xml 
33    do
34      if test -f $d/docbookx.dtd; then
35        AC_MSG_RESULT($d)
36        DTD_DIR=$d
37        break
38      fi
39    done
40    if test -z "$DTD_DIR"; then
41       AC_MSG_RESULT(Not found)
42    fi
43 ])
44 AC_SUBST(DSSSL_DIR)
45 AC_ARG_WITH(dsssl,[  --with-dsssl[=DIR]      use Docbook DSSSL in DIR/{html,print}/docbook.dsl],
46 [
47    if test -f "$withval/html/docbook.dsl"; then
48       DSSSL_DIR=$withval
49    fi
50 ],[
51    AC_MSG_CHECKING(for docbook.dsl)
52    for d in /usr/share/sgml/docbook/stylesheet/dsssl/modular \
53             /usr/share/sgml/docbook/dsssl-stylesheets-1.* \
54             /usr/lib/sgml/stylesheet/dsssl/docbook/nwalsh 
55    do
56      if test -f $d/html/docbook.dsl; then
57        AC_MSG_RESULT($d)
58        DSSSL_DIR=$d
59        break
60      fi
61    done
62    if test -z "$DSSSL_DIR"; then
63       AC_MSG_RESULT(Not found)
64    fi
65 ])
66 AC_SUBST(XSL_DIR)
67 AC_ARG_WITH(xsl,[  --with-xsl[=DIR]        use Docbook XSL in DIR/{htmlhelp,xhtml}],
68 [
69    if test -f "$withval/htmlhelp/htmlhelp.xsl"; then
70       XSL_DIR=$withval
71    fi
72 ],[
73    AC_MSG_CHECKING(for htmlhelp.xsl)
74    for d in /usr/share/sgml/docbook/stylesheet/xsl/nwalsh \
75             /usr/share/sgml/docbook/xsl-stylesheets-1.* 
76    do
77      if test -f $d/htmlhelp/htmlhelp.xsl; then
78        AC_MSG_RESULT($d)
79        XSL_DIR=$d
80        break
81      fi
82    done
83    if test -z "$XSL_DIR"; then
84       AC_MSG_RESULT(Not found)
85    fi
86 ])
87 dnl 
88 dnl ----- Sockets
89 checkBoth=0
90 AC_CHECK_FUNC(connect)
91 if test "$ac_cv_func_connect" = "no"; then
92         AC_CHECK_LIB(socket, main, LIBS="$LIBS -lsocket", checkBoth=1)
93 fi
94 if test "$checkBoth" = "1"; then
95         oldLibs=$LIBS
96         LIBS="$LIBS -lsocket -lnsl"
97         AC_CHECK_FUNC(accept, , [LIBS=$oldLibs])
98 fi
99 AC_CHECK_FUNC(gethostbyname, , AC_CHECK_LIB(nsl, main, [LIBS="$LIBS -lnsl"]))
100 dnl
101 dnl ------ Open SSL
102 openssl=no
103 AC_ARG_WITH(openssl, [  --with-openssl[=PREFIX] OpenSSL library in PREFIX], [openssl=$withval])
104 AC_SUBST(SSL_CFLAGS)
105 AC_SUBST(SSL_LIBS)
106 AC_SUBST(SSL_DEFS)
107 USE_SSL=0
108 SSL_CFLAGS=""
109 SSL_LIBS=""
110 SSL_DEFS=""
111 if test "$openssl" != "no"; then
112         xLIBS="$LIBS";
113         xCFLAGS="$CFLAGS";
114         if test "$openssl" != "yes"; then
115                 SSL_CFLAGS="-I$openssl/include -I$openssl/include/openssl"
116                 SSL_LIBS="-L$openssl/lib"
117                 CFLAGS="$SSL_CFLAGS $CFLAGS"
118                 LIBS="$SSL_LIBS $LIBS"
119         fi
120         AC_CHECK_LIB(crypto, main,[SSL_LIBS="$SSL_LIBS -lcrypto"])
121         LIBS="$LIBS $SSL_LIBS"
122         AC_CHECK_LIB(ssl, SSL_new)
123         if test "$ac_cv_lib_ssl_SSL_new" = "yes"; then
124                 SSL_LIBS="$SSL_LIBS -lssl"
125                 AC_CHECK_HEADER(openssl/ssl.h,[SSL_DEFS="-DHAVE_OPENSSL_SSL_H=1"; USE_SSL=1])
126         else
127                 SSL_LIBS=""
128         fi
129         LIBS="$xLIBS"
130         CFLAGS="$xCFLAGS"
131 fi
132 AM_CONDITIONAL(ISSSL, test $USE_SSL = "1")
133 dnl
134 dnl ------ GNU Readline
135 READLINE_SHARED_LIBADD=""
136 AC_CHECK_LIB(ncurses, tgetent, [READLINE_SHARED_LIBADD="-lncurses"],
137         AC_CHECK_LIB(termcap, tgetent, [READLINE_SHARED_LIBADD="-ltermcap"])
138 )
139 READLINE_LIBS=""
140 AC_CHECK_LIB(readline, readline, [READLINE_LIBS="$READLINE_LIBS -lreadline $READLINE_SHARED_LIBADD"],,$READLINE_SHARED_LIBADD)
141 AC_CHECK_LIB(history, add_history, [READLINE_LIBS="$READLINE_LIBS -lhistory"])
142 if test "$ac_cv_lib_readline_readline" = "yes"; then
143         AC_CHECK_HEADERS(readline/readline.h readline/history.h)
144         xLIBS=$LIBS
145         LIBS="$LIBS $READLINE_LIBS"
146         AC_TRY_LINK([
147         #include <stdio.h>
148         #include <readline/readline.h>
149         ],[
150         static void f()
151         {
152                 rl_attempted_completion_over = 0;
153         }
154         ],AC_DEFINE(HAVE_READLINE_COMPLETION_OVER))
155         AC_TRY_LINK([
156         #include <stdio.h>
157         #include <readline/readline.h>
158         ],[
159         static void f()
160         {
161                 rl_completion_matches (0, 0);
162         }
163         ],AC_DEFINE(HAVE_READLINE_RL_COMPLETION_MATCHES))
164         LIBS=$xLIBS
165 fi
166 dnl ------ iconv
167 AC_ARG_WITH(iconv, [  --with-iconv[=PREFIX]   iconv library in PREFIX])
168 if test "$with_iconv" != "no"; then
169         AC_MSG_CHECKING(for iconv)
170         oldLIBS="$LIBS"
171         oldCPPFLAGS="${CPPFLAGS}"
172         if test "$with_iconv" != "yes" -a "$with_iconv" != ""; then
173                 LIBS="$LIBS -L${with_iconv}/lib"
174                 CPPFLAGS="${CPPFLAGS} -I${with_iconv}/include"
175         fi
176         AC_TRY_LINK([
177                 #include <iconv.h>
178         ],[
179                 static void f() {iconv_t t = iconv_open("", ""); }
180         ],[
181                 AC_DEFINE(HAVE_ICONV_H)
182                 AC_MSG_RESULT(yes)
183         ],[
184                 LIBS="$LIBS -liconv"
185                 AC_TRY_LINK([
186                         #include <iconv.h>
187                 ],[
188                         static void f() {iconv_t t = iconv_open("", ""); }
189                 ],[
190                         AC_DEFINE(HAVE_ICONV_H)
191                         AC_MSG_RESULT(yes)
192                 ],[
193                         LIBS="$oldLIBS"
194                         CPPFLAGS="$oldCPPFLAGS"
195                         AC_MSG_RESULT(no)
196                 ])
197         ])
198 fi
199 dnl ------ various functions
200 AC_CHECK_FUNCS(vsnprintf gettimeofday poll strerror_r)
201 if test "$ac_cv_func_poll" = "yes"; then
202         AC_CHECK_HEADERS(sys/poll.h)
203 fi
204 dnl ------ socklen_t
205 AC_MSG_CHECKING([for socklen_t])
206 AC_CACHE_VAL(ac_cv_check_socklen_t,[ac_cv_check_socklen_t=''
207         AC_TRY_COMPILE([
208         #include <sys/types.h>
209         #include <sys/socket.h>
210         #ifdef __cplusplus
211         extern "C" {
212         #endif
213         extern int accept(int, struct sockaddr *, socklen_t *);
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                 extern int accept(int, struct sockaddr *, size_t t *);
225                 #ifdef __cplusplus
226                 }
227                 #endif
228                 ],,[ac_cv_check_socklen_t=size_t],[ac_cv_check_socklen_t=int])
229         ])
230 ])
231 AC_MSG_RESULT($ac_cv_check_socklen_t)
232 AC_DEFINE_UNQUOTED(YAZ_SOCKLEN_T,$ac_cv_check_socklen_t)
233 dnl
234 dnl ------ tcpd
235 AC_ARG_ENABLE(tcpd,[  --enable-tcpd[=PREFIX]  enable TCP wrapper for server if available])
236 if test "$enable_tcpd" != ""; then
237         oldLibs=$LIBS
238         oldCPPFLAGS=$CPPFLAGS
239         if test "$enable_tcpd" != "yes"; then
240                 LIBS="$LIBS -L$enable_tcpd/lib"
241                 CPPFLAGS="$CPPFLAGS -I$enable_tcpd/include"
242         fi
243         AC_MSG_CHECKING(for working tcpd.h)
244         LIBS="$LIBS -lwrap -lnsl"
245         AC_TRY_LINK([#include <syslog.h>
246 #include <tcpd.h>
247         int allow_severity = LOG_INFO;
248         int deny_severity = LOG_WARNING;],
249         [struct request_info request_info; int i;
250         i = hosts_access(&request_info);],
251         tcpd_ok=1, tcpd_ok=0)
252         if test "$tcpd_ok" = "0"; then
253                 AC_MSG_RESULT(no)
254                 LIBS=$oldLibs
255                 CPPFLAGS=$oldCPPFLAGS
256         else
257                 AC_MSG_RESULT(yes)
258                 AC_DEFINE(HAVE_TCPD_H)
259         fi
260 fi
261 dnl
262 dnl ------ Headers
263 AC_CHECK_HEADERS(fnmatch.h wchar.h locale.h langinfo.h)
264 AC_STDC_HEADERS
265 if test "$ac_cv_header_stdc" = "no"; then
266         AC_MSG_WARN(Your system doesn't seem to support ANSI C)
267 fi
268 dnl
269 AC_SUBST(LIBTHREAD)
270 AC_SUBST(CFLAGSTHREADS)
271 HAVETHREADS=0
272 CFLAGSTHREADS=""
273 LIBTHREAD=""
274 dnl
275 dnl ------ GNU threads
276 AC_ARG_ENABLE(pth, [  --enable-pth            enable GNU threads],[enable_pth=$enableval],[enable_pth=no])
277 AC_SUBST(LIBPTH)
278 if test "$enable_pth" = "yes"; then
279         OLIBS=$LIBS
280         AC_CHECK_LIB(pth,main)
281         if test "$ac_cv_lib_pth_main" = "yes"; then
282                 AC_CHECK_HEADERS(pth.h)
283                 if test "$ac_cv_header_pth_h" = "yes"; then
284                         LIBTHREAD="-lpth"
285                         CFLAGSTHREADS="-DYAZ_GNU_THREADS=1"
286                         HAVETHREADS=1
287                 fi
288         fi      
289         LIBS=$OLIBS
290 fi
291 dnl
292 dnl ------ POSIX Threads
293 AC_ARG_ENABLE(threads, [  --disable-threads       disable POSIX threads],[enable_threads=$enableval],[enable_threads=yes])
294 if test "$enable_threads" = "yes" -a "$HAVETHREADS" = "0"; then
295         OLIBS=$LIBS
296         OCC=$CC
297         AC_CHECK_LIB(pthread,main)
298         AC_MSG_CHECKING(for working POSIX Threads)
299         AC_TRY_LINK([#include <pthread.h>
300         void *func(void *p) { return 0; }
301         ],[
302         pthread_t pthread_id;
303         pthread_create (&pthread_id, 0, func, 0);],
304                 thread_ok=yes,thread_ok=no)
305         if test "$thread_ok" = "yes"; then
306                 AC_MSG_RESULT(yes)
307                 LIBTHREAD="-lpthread"
308                 CFLAGSTHREADS="-DYAZ_POSIX_THREADS=1 -D_REENTRANT"
309                 HAVETHREADS=1
310         else
311                 CC="$CC -pthread"
312                 AC_TRY_LINK([#include <pthread.h>
313                         void *func(void *p) { return 0; }
314                         ],[
315                         pthread_t pthread_id;
316                         pthread_create (&pthread_id, 0, func, 0);],
317                         thread_ok=yes,thread_ok=no)
318                 if test "$thread_ok" = "yes"; then
319                         AC_MSG_RESULT([yes,BSD])
320                         CFLAGSTHREADS="-pthread -DYAZ_POSIX_THREADS=1 -D_REENTRANT"
321                         LIBTHREAD="-pthread"
322                         HAVETHREADS=1
323                 fi
324         fi
325         if test "$thread_ok" = "no"; then
326                 AC_MSG_RESULT(no)
327         fi
328         CC=$OCC
329         LIBS=$OLIBS
330 fi
331 AM_CONDITIONAL(ISTHR, test $HAVETHREADS = "1")
332 dnl
333 dnl ----- libXML2
334 AC_SUBST(XML2_LIBS)
335 AC_SUBST(XML2_CFLAGS)
336 xml2dir=yes
337 AC_ARG_WITH(xml2, [  --with-xml2[=PREFIX]    use libxml2 in PREFIX],[xml2dir=$withval])
338 if test "$xml2dir" = "yes"; then
339         for d in /usr /usr/local; do
340                 if test -x $d/bin/xml2-config; then
341                         xml2dir=$d
342                 fi
343         done
344 fi
345 if test "$xml2dir" != "no"; then
346         AC_MSG_CHECKING(for libXML2)
347         if test -x $xml2dir/bin/xml2-config; then
348                 XML2_LIBS=`$xml2dir/bin/xml2-config --libs`
349                 LIBS="$XML2_LIBS $LIBS"
350                 XML2_CFLAGS=`$xml2dir/bin/xml2-config --cflags`
351                 XML2_VER=`$xml2dir/bin/xml2-config --version`
352                 AC_MSG_RESULT($XML2_VER)
353                 AC_DEFINE(HAVE_XML2)
354         else
355                 AC_MSG_RESULT(Not found)
356         fi
357 fi
358 dnl
359 dnl ------ Memory debugging
360 AC_ARG_ENABLE(memdebug, [  --enable-memdebug       enable memory debugging],[enable_memdebug=$enableval],[enable_memdebug=none])
361 if test "$enable_memdebug" = "yes"; then
362         AC_DEFINE(TRACE_XMALLOC,2)
363 elif test "$enable_memdebug" = "no"; then
364         AC_DEFINE(TRACE_XMALLOC,0)
365 fi
366 dnl
367 dnl ------ Using this for "in-source" yaz-config
368 AC_SUBST(YAZ_SRC_ROOT)
369 AC_SUBST(YAZ_BUILD_ROOT)
370 YAZ_SRC_ROOT=`cd ${srcdir}; pwd`
371 YAZ_BUILD_ROOT=`pwd`
372 dnl
373 dnl ------ Makefiles
374 dnl
375 AC_OUTPUT([
376 Makefile
377 yaz.spec
378 util/Makefile
379 odr/Makefile
380 z39.50/Makefile
381 ill/Makefile
382 zutil/Makefile
383 comstack/Makefile
384 ccl/Makefile
385 cql/Makefile
386 server/Makefile
387 include/Makefile
388 include/yaz/Makefile
389 lib/Makefile
390 client/Makefile
391 ztest/Makefile
392 zoom/Makefile
393 doc/Makefile
394 doc/yaz.xml
395 doc/yazhtml.dsl
396 doc/yazphp.dsl
397 doc/yazprint.dsl
398 doc/tkl.xsl
399 doc/yazhtml.xsl
400 etc/Makefile
401 yaz-config
402 ],[sed s%yaz_echo_source=yes%yaz_echo_source=no%g < yaz-config > lib/yaz-config && chmod +x yaz-config lib/yaz-config])