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