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