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