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