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