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