No longer require GNU make. Update list of dependency ports
[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.16 2006-05-23 10:05:28 marc 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_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't 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=no
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"; 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                 AC_MSG_ERROR([OpenSSL development libraries missing])
103         fi
104 fi
105 dnl
106 dnl ------ GNU Readline
107 READLINE_SHARED_LIBADD=""
108 AC_CHECK_LIB(ncurses, tgetent, [READLINE_SHARED_LIBADD="-lncurses"],
109         AC_CHECK_LIB(termcap, tgetent, [READLINE_SHARED_LIBADD="-ltermcap"])
110 )
111 READLINE_LIBS=""
112 AC_CHECK_LIB(readline, readline, [READLINE_LIBS="$READLINE_LIBS -lreadline $READLINE_SHARED_LIBADD"],,$READLINE_SHARED_LIBADD)
113 AC_CHECK_LIB(history, add_history, [READLINE_LIBS="$READLINE_LIBS -lhistory"])
114 if test "$ac_cv_lib_readline_readline" = "yes"; then
115         AC_CHECK_HEADERS(readline/readline.h readline/history.h)
116         xLIBS=$LIBS
117         LIBS="$LIBS $READLINE_LIBS"
118         AC_TRY_LINK([
119         #include <stdio.h>
120         #include <readline/readline.h>
121         ],[
122                 rl_attempted_completion_over = 0;
123         ],AC_DEFINE(HAVE_READLINE_COMPLETION_OVER))
124         AC_TRY_LINK([
125         #include <stdio.h>
126         #include <readline/readline.h>
127         ],[
128                 rl_completion_matches (0, 0);
129         ],[AC_DEFINE(HAVE_READLINE_RL_COMPLETION_MATCHES)])
130         LIBS=$xLIBS
131 fi
132 dnl ------ iconv
133 AC_ARG_WITH(iconv, [  --with-iconv[=PREFIX]     iconv library in PREFIX])
134 if test "$with_iconv" != "no"; then
135         AC_MSG_CHECKING(for iconv)
136         oldLIBS="$LIBS"
137         oldCPPFLAGS="${CPPFLAGS}"
138         if test "$with_iconv" != "yes" -a "$with_iconv" != ""; then
139                 LIBS="$LIBS -L${with_iconv}/lib"
140                 CPPFLAGS="${CPPFLAGS} -I${with_iconv}/include"
141         fi
142         AC_TRY_LINK([
143                 #include <iconv.h>
144         ],[
145                 iconv_t t = iconv_open("", "");
146         ],[
147                 AC_DEFINE(HAVE_ICONV_H)
148                 AC_MSG_RESULT(yes)
149         ],[
150                 LIBS="$LIBS -liconv"
151                 AC_TRY_LINK([
152                         #include <iconv.h>
153                 ],[
154                         iconv_t t = iconv_open("", "");
155                 ],[
156                         AC_DEFINE(HAVE_ICONV_H)
157                         AC_MSG_RESULT(yes)
158                 ],[
159                         LIBS="$oldLIBS"
160                         CPPFLAGS="$oldCPPFLAGS"
161                         AC_MSG_RESULT(no)
162                 ])
163         ])
164 fi
165 dnl ------ various functions
166 AC_CHECK_FUNCS(vsnprintf gettimeofday poll strerror_r localtime_r usleep fopen64)
167 case $host in
168 *-*-darwin*)
169         trypoll="no";
170                 ;;
171 *)
172         trypoll="yes";
173         ;;
174 esac
175
176 if test "$ac_cv_func_poll" = "yes" -a "$trypoll" = "yes"; then
177         AC_CHECK_HEADERS(sys/poll.h)
178 fi
179 dnl ------ socklen_t
180 dnl We check for socklen_t by making prototypes with the
181 dnl various types. First socklen_t, then size_t, finally int.
182 dnl If the prototype succeeds, we're probably safe.
183 dnl That works if accept is not preprocessor defined (such sa AIX)
184 AC_MSG_CHECKING([for socklen_t])
185 AC_CACHE_VAL(ac_cv_check_socklen_t,[ac_cv_check_socklen_t=''
186         AC_TRY_COMPILE([
187 #include <sys/types.h>
188 #include <sys/socket.h>
189 #ifdef __cplusplus
190 extern "C" {
191 #endif
192 #define try 1
193 #ifdef AIX
194 #if AIX >= 51
195 #define try 0
196 #endif
197 #endif
198 #if try
199 extern int accept(int, struct sockaddr *, socklen_t *);
200 #endif
201 #ifdef __cplusplus
202 }
203 #endif
204         ],,[ac_cv_check_socklen_t=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 >= 42
214 #define try 0
215 #endif
216 #endif
217 #if try
218 extern int accept(int, struct sockaddr *, size_t t *);
219 #endif
220 #ifdef __cplusplus
221 }
222 #endif
223                 ],,[ac_cv_check_socklen_t=size_t],[ac_cv_check_socklen_t=int])
224         ])
225 ])
226 AC_MSG_RESULT($ac_cv_check_socklen_t)
227 AC_DEFINE_UNQUOTED(YAZ_SOCKLEN_T,$ac_cv_check_socklen_t)
228 AC_DEFINE(YAZ_USE_NEW_LOG)
229 dnl
230 dnl ------ tcpd
231 AC_ARG_ENABLE(tcpd,[  --enable-tcpd[=PREFIX]  enable TCP wrapper for server if available])
232 if test "$enable_tcpd" -a "$enable_tcpd" != "no"; then
233         oldLibs=$LIBS
234         oldCPPFLAGS=$CPPFLAGS
235         if test "$enable_tcpd" != "yes"; then
236                 LIBS="$LIBS -L$enable_tcpd/lib"
237                 CPPFLAGS="$CPPFLAGS -I$enable_tcpd/include"
238         fi
239         AC_MSG_CHECKING(for working tcpd.h)
240         LIBS="$LIBS -lwrap -lnsl"
241         AC_TRY_LINK([#include <syslog.h>
242 #include <tcpd.h>
243         int allow_severity = LOG_INFO;
244         int deny_severity = LOG_WARNING;],
245         [struct request_info request_info; int i;
246         i = hosts_access(&request_info);],
247         tcpd_ok=1, tcpd_ok=0)
248         if test "$tcpd_ok" = "0"; then
249                 AC_MSG_RESULT(no)
250                 AC_MSG_ERROR([tcpd development libraries missing])
251                 LIBS=$oldLibs
252                 CPPFLAGS=$oldCPPFLAGS
253         else
254                 AC_MSG_RESULT(yes)
255                 AC_DEFINE(HAVE_TCPD_H)
256         fi
257 fi
258 dnl
259 AC_SUBST(THREAD_CFLAGS)
260 HAVETHREADS=0
261 THREAD_CFLAGS=""
262 LIBTHREAD=""
263 dnl
264 dnl ------ GNU threads
265 AC_ARG_ENABLE(pth, [  --enable-pth            enable GNU threads],[enable_pth=$enableval],[enable_pth=no])
266 AC_SUBST(LIBPTH)
267 if test "$enable_pth" = "yes"; then
268         OLIBS=$LIBS
269         AC_CHECK_LIB(pth,main)
270         if test "$ac_cv_lib_pth_main" = "yes"; then
271                 AC_CHECK_HEADERS(pth.h)
272                 if test "$ac_cv_header_pth_h" = "yes"; then
273                         LIBTHREAD="-lpth"
274                         THREAD_CFLAGS="-DYAZ_GNU_THREADS=1"
275                         HAVETHREADS=1
276                 fi
277         fi      
278         LIBS="$OLIBS $LIBTHREAD"
279 fi
280 dnl
281 dnl ------ POSIX Threads
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         OLIBS=$LIBS
285         OCC=$CC
286         AC_CHECK_LIB(pthread,main)
287         AC_MSG_CHECKING(for working POSIX Threads)
288         AC_TRY_LINK([#include <pthread.h>
289         void *func(void *p) { return 0; }
290         ],[
291         pthread_t pthread_id;
292         pthread_create (&pthread_id, 0, func, 0);],
293                 thread_ok=yes,thread_ok=no)
294         if test "$thread_ok" = "yes"; then
295                 AC_MSG_RESULT(yes)
296                 LIBTHREAD="-lpthread"
297                 THREAD_CFLAGS="-DYAZ_POSIX_THREADS=1 -D_REENTRANT"
298                 HAVETHREADS=1
299         else
300                 CC="$CC -pthread"
301                 AC_TRY_LINK([#include <pthread.h>
302                         void *func(void *p) { return 0; }
303                         ],[
304                         pthread_t pthread_id;
305                         pthread_create (&pthread_id, 0, func, 0);],
306                         thread_ok=yes,thread_ok=no)
307                 if test "$thread_ok" = "yes"; then
308                         AC_MSG_RESULT([yes,BSD])
309                         THREAD_CFLAGS="-pthread -DYAZ_POSIX_THREADS=1 -D_REENTRANT"
310                         LIBTHREAD="-pthread"
311                         HAVETHREADS=1
312                 fi
313         fi
314         if test "$thread_ok" = "no"; then
315                 AC_MSG_RESULT(no)
316         fi
317         CC=$OCC
318         LIBS="$OLIBS $LIBTHREAD"
319 fi
320
321 dnl ----- libXSLT/libEXLT/libXML2
322 AC_SUBST(XML2_CFLAGS)
323
324 YAZ_LIBXML2
325 YAZ_LIBXSLT
326 YAZ_LIBEXSLT
327
328 if test "$XML2_LIBS"; then
329         LIBS="$XML2_LIBS $LIBS"
330 fi
331
332 dnl
333 dnl ------ Memory debugging
334 AC_ARG_ENABLE(memdebug, [  --enable-memdebug       enable memory debugging],[enable_memdebug=$enableval],[enable_memdebug=none])
335 if test "$enable_memdebug" = "yes"; then
336         AC_DEFINE(TRACE_XMALLOC,2)
337 elif test "$enable_memdebug" = "no"; then
338         AC_DEFINE(TRACE_XMALLOC,0)
339 fi
340 dnl
341 dnl ------ Using this for "in-source" yaz-config
342 AC_SUBST(YAZ_SRC_ROOT)
343 AC_SUBST(YAZ_BUILD_ROOT)
344 YAZ_SRC_ROOT=`cd ${srcdir}; pwd`
345 YAZ_BUILD_ROOT=`pwd`
346 dnl
347 dnl ------ Makefiles
348 dnl
349 AC_OUTPUT([
350 Makefile
351 yaz.spec
352 src/Makefile
353 test/Makefile
354 util/Makefile
355 include/Makefile
356 include/yaz/Makefile
357 client/Makefile
358 ztest/Makefile
359 zoom/Makefile
360 doc/Makefile
361 doc/yaz.xml
362 doc/common/Makefile
363 doc/common/html.dsl
364 doc/common/html.xsl
365 doc/common/print.dsl
366 doc/common/tkl.xsl
367 etc/Makefile
368 yaz-config
369 Doxyfile
370 ],[sed s%yaz_echo_source=yes%yaz_echo_source=no%g < yaz-config > util/yaz-config && chmod +x yaz-config util/yaz-config])
371
372
373 echo \ '
374 Build and install binaries with the usual
375   make
376   make check
377   make install
378
379 Build distribution tarball with
380   make dist
381
382 Verify distribution tarball with
383   make distcheck
384
385 Or just build the Debian packages without configuring
386   dpkg-buildpackage -rfakeroot
387 '
388
389 echo \
390 "------------------------------------------------------------------------
391 Configuration:
392
393   YAZ Package:                ${PACKAGE}
394   YAZ Version:                ${VERSION}
395   Bugreport:                  ${PACKAGE_BUGREPORT}
396   Source code location:       ${srcdir}
397   C Preprocessor:             ${CPP}
398   C Preprocessor flags:       ${CPPFLAGS}
399   C Compiler:                 ${CC}
400   C Compiler flags:           ${CFLAGS}
401   Linker flags:               ${LDFLAGS}
402   Linked libs:                ${LIBS}
403   Host System Type:           ${host}
404   Install path:               ${prefix}
405   Automake:                   ${AUTOMAKE}
406   Archiver:                   ${AR}
407   Ranlib:                     ${RANLIB}
408
409 ------------------------------------------------------------------------"