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