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