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