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