tweak
[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.113 2003-05-26 20:09:01 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 ------ OpenSSL
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 dnl We check for socklen_t by making prototypes with the
206 dnl various types. First socklen_t, then size_t, finally int.
207 dnl If the prototype succeeds, we're probably safe.
208 dnl That works if accept is not preprocessor defined (such sa AIX)
209 AC_MSG_CHECKING([for socklen_t])
210 AC_CACHE_VAL(ac_cv_check_socklen_t,[ac_cv_check_socklen_t=''
211         AC_TRY_COMPILE([
212 #include <sys/types.h>
213 #include <sys/socket.h>
214 #ifdef __cplusplus
215 extern "C" {
216 #endif
217 #define try 1
218 #ifdef AIX
219 #if AIX >= 51
220 #define try 0
221 #endif
222 #endif
223 #if try
224 extern int accept(int, struct sockaddr *, socklen_t *);
225 #endif
226 #ifdef __cplusplus
227 }
228 #endif
229         ],,[ac_cv_check_socklen_t=socklen_t],[
230                 AC_TRY_COMPILE([
231 #include <sys/types.h>
232 #include <sys/socket.h>
233 #ifdef __cplusplus
234 extern "C" {
235 #endif
236 #define try 1
237 #ifdef AIX
238 #if AIX >= 42
239 #define try 0
240 #endif
241 #endif
242 #if try
243 extern int accept(int, struct sockaddr *, size_t t *);
244 #endif
245 #ifdef __cplusplus
246 }
247 #endif
248                 ],,[ac_cv_check_socklen_t=size_t],[ac_cv_check_socklen_t=int])
249         ])
250 ])
251 AC_MSG_RESULT($ac_cv_check_socklen_t)
252 AC_DEFINE_UNQUOTED(YAZ_SOCKLEN_T,$ac_cv_check_socklen_t)
253 dnl
254 dnl ------ tcpd
255 AC_ARG_ENABLE(tcpd,[  --enable-tcpd[=PREFIX]  enable TCP wrapper for server if available])
256 if test "$enable_tcpd" != ""; then
257         oldLibs=$LIBS
258         oldCPPFLAGS=$CPPFLAGS
259         if test "$enable_tcpd" != "yes"; then
260                 LIBS="$LIBS -L$enable_tcpd/lib"
261                 CPPFLAGS="$CPPFLAGS -I$enable_tcpd/include"
262         fi
263         AC_MSG_CHECKING(for working tcpd.h)
264         LIBS="$LIBS -lwrap -lnsl"
265         AC_TRY_LINK([#include <syslog.h>
266 #include <tcpd.h>
267         int allow_severity = LOG_INFO;
268         int deny_severity = LOG_WARNING;],
269         [struct request_info request_info; int i;
270         i = hosts_access(&request_info);],
271         tcpd_ok=1, tcpd_ok=0)
272         if test "$tcpd_ok" = "0"; then
273                 AC_MSG_RESULT(no)
274                 LIBS=$oldLibs
275                 CPPFLAGS=$oldCPPFLAGS
276         else
277                 AC_MSG_RESULT(yes)
278                 AC_DEFINE(HAVE_TCPD_H)
279         fi
280 fi
281 dnl
282 dnl ------ Headers
283 AC_CHECK_HEADERS(fnmatch.h wchar.h locale.h langinfo.h)
284 AC_STDC_HEADERS
285 if test "$ac_cv_header_stdc" = "no"; then
286         AC_MSG_WARN(Your system doesn't seem to support ANSI C)
287 fi
288 dnl
289 AC_SUBST(LIBTHREAD)
290 AC_SUBST(CFLAGSTHREADS)
291 HAVETHREADS=0
292 CFLAGSTHREADS=""
293 LIBTHREAD=""
294 dnl
295 dnl ------ GNU threads
296 AC_ARG_ENABLE(pth, [  --enable-pth            enable GNU threads],[enable_pth=$enableval],[enable_pth=no])
297 AC_SUBST(LIBPTH)
298 if test "$enable_pth" = "yes"; then
299         OLIBS=$LIBS
300         AC_CHECK_LIB(pth,main)
301         if test "$ac_cv_lib_pth_main" = "yes"; then
302                 AC_CHECK_HEADERS(pth.h)
303                 if test "$ac_cv_header_pth_h" = "yes"; then
304                         LIBTHREAD="-lpth"
305                         CFLAGSTHREADS="-DYAZ_GNU_THREADS=1"
306                         HAVETHREADS=1
307                 fi
308         fi      
309         LIBS=$OLIBS
310 fi
311 dnl
312 dnl ------ POSIX Threads
313 AC_ARG_ENABLE(threads, [  --disable-threads       disable POSIX threads],[enable_threads=$enableval],[enable_threads=yes])
314 if test "$enable_threads" = "yes" -a "$HAVETHREADS" = "0"; then
315         OLIBS=$LIBS
316         OCC=$CC
317         AC_CHECK_LIB(pthread,main)
318         AC_MSG_CHECKING(for working POSIX Threads)
319         AC_TRY_LINK([#include <pthread.h>
320         void *func(void *p) { return 0; }
321         ],[
322         pthread_t pthread_id;
323         pthread_create (&pthread_id, 0, func, 0);],
324                 thread_ok=yes,thread_ok=no)
325         if test "$thread_ok" = "yes"; then
326                 AC_MSG_RESULT(yes)
327                 LIBTHREAD="-lpthread"
328                 CFLAGSTHREADS="-DYAZ_POSIX_THREADS=1 -D_REENTRANT"
329                 HAVETHREADS=1
330         else
331                 CC="$CC -pthread"
332                 AC_TRY_LINK([#include <pthread.h>
333                         void *func(void *p) { return 0; }
334                         ],[
335                         pthread_t pthread_id;
336                         pthread_create (&pthread_id, 0, func, 0);],
337                         thread_ok=yes,thread_ok=no)
338                 if test "$thread_ok" = "yes"; then
339                         AC_MSG_RESULT([yes,BSD])
340                         CFLAGSTHREADS="-pthread -DYAZ_POSIX_THREADS=1 -D_REENTRANT"
341                         LIBTHREAD="-pthread"
342                         HAVETHREADS=1
343                 fi
344         fi
345         if test "$thread_ok" = "no"; then
346                 AC_MSG_RESULT(no)
347         fi
348         CC=$OCC
349         LIBS=$OLIBS
350 fi
351 AM_CONDITIONAL(ISTHR, test $HAVETHREADS = "1")
352 dnl
353 dnl ----- libXML2
354 AC_SUBST(XML2_LIBS)
355 AC_SUBST(XML2_CFLAGS)
356 xml2dir=yes
357 AC_ARG_WITH(xml2, [  --with-xml2[=PREFIX]    use libxml2 in PREFIX],[xml2dir=$withval])
358 if test "$xml2dir" = "yes"; then
359         for d in /usr /usr/local; do
360                 if test -x $d/bin/xml2-config; then
361                         xml2dir=$d
362                 fi
363         done
364 fi
365 if test "$xml2dir" != "no"; then
366         AC_MSG_CHECKING(for libXML2)
367         if test -x $xml2dir/bin/xml2-config; then
368                 XML2_LIBS=`$xml2dir/bin/xml2-config --libs`
369                 LIBS="$XML2_LIBS $LIBS"
370                 XML2_CFLAGS=`$xml2dir/bin/xml2-config --cflags`
371                 XML2_VER=`$xml2dir/bin/xml2-config --version`
372                 AC_MSG_RESULT($XML2_VER)
373                 AC_DEFINE(HAVE_XML2)
374         else
375                 AC_MSG_RESULT(Not found)
376         fi
377 fi
378 dnl
379 dnl ------ Memory debugging
380 AC_ARG_ENABLE(memdebug, [  --enable-memdebug       enable memory debugging],[enable_memdebug=$enableval],[enable_memdebug=none])
381 if test "$enable_memdebug" = "yes"; then
382         AC_DEFINE(TRACE_XMALLOC,2)
383 elif test "$enable_memdebug" = "no"; then
384         AC_DEFINE(TRACE_XMALLOC,0)
385 fi
386 dnl
387 dnl ------ Using this for "in-source" yaz-config
388 AC_SUBST(YAZ_SRC_ROOT)
389 AC_SUBST(YAZ_BUILD_ROOT)
390 YAZ_SRC_ROOT=`cd ${srcdir}; pwd`
391 YAZ_BUILD_ROOT=`pwd`
392 dnl
393 dnl ------ Makefiles
394 dnl
395 AC_OUTPUT([
396 Makefile
397 yaz.spec
398 util/Makefile
399 odr/Makefile
400 z39.50/Makefile
401 ill/Makefile
402 zutil/Makefile
403 comstack/Makefile
404 ccl/Makefile
405 cql/Makefile
406 server/Makefile
407 include/Makefile
408 include/yaz/Makefile
409 lib/Makefile
410 client/Makefile
411 ztest/Makefile
412 zoom/Makefile
413 doc/Makefile
414 doc/yaz.xml
415 doc/yazhtml.dsl
416 doc/yazphp.dsl
417 doc/yazprint.dsl
418 doc/tkl.xsl
419 doc/yazhtml.xsl
420 etc/Makefile
421 yaz-config
422 ],[sed s%yaz_echo_source=yes%yaz_echo_source=no%g < yaz-config > lib/yaz-config && chmod +x yaz-config lib/yaz-config])