tests/test-blocksize-write-disconnect.sh: Consume input in pwrite
[nbdkit.git] / configure.ac
blob97a23b2d60ca0b8fcf7d95b861d5eef2fa172b22
1 # nbdkit
2 # Copyright (C) 2013-2022 Red Hat Inc.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # * Neither the name of Red Hat nor the names of its contributors may be
16 # used to endorse or promote products derived from this software without
17 # specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
23 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # SUCH DAMAGE.
32 m4_define([NBDKIT_VERSION_MAJOR], [1])
33 m4_define([NBDKIT_VERSION_MINOR], [33])
34 m4_define([NBDKIT_VERSION_MICRO], [2])
35 AC_INIT([nbdkit],
36         NBDKIT_VERSION_MAJOR.NBDKIT_VERSION_MINOR.NBDKIT_VERSION_MICRO)
37 AC_CONFIG_MACRO_DIR([m4])
39 dnl This must be used very early else you will get
40 dnl "warning: AC_RUN_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS"
41 m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],[],
42          [m4_define([AC_USE_SYSTEM_EXTENSIONS],[])])
43 AC_USE_SYSTEM_EXTENSIONS
45 dnl NB: Do not [quote] this parameter.
46 AM_INIT_AUTOMAKE(foreign)
47 LT_INIT([win32-dll])
49 dnl Extra string, a freeform string defined by downstream packagers.
50 dnl eg. If you are packaging nbdkit for Linux distro X 1.1, you could
51 dnl   ./configure --with-extra="X release 1.1"
52 AC_ARG_WITH([extra],
53     [AS_HELP_STRING([--with-extra=...],
54                     [extra version information (for use by packagers)])],
55     [NBDKIT_VERSION_EXTRA="$withval"],
56     [NBDKIT_VERSION_EXTRA=]
58 AC_DEFINE_UNQUOTED([NBDKIT_VERSION_EXTRA], ["$NBDKIT_VERSION_EXTRA"],
59                    [Extra version information (for use by packagers)])
61 AC_MSG_NOTICE([nbdkit version NBDKIT_VERSION_MAJOR.NBDKIT_VERSION_MINOR.NBDKIT_VERSION_MICRO ($NBDKIT_VERSION_EXTRA)])
63 dnl List of plugins and filters.
64 lang_plugins="\
65         cc \
66         golang \
67         lua \
68         ocaml \
69         perl \
70         python \
71         ruby \
72         rust \
73         sh \
74         tcl \
75         "
76 non_lang_plugins="\
77         cdi \
78         curl \
79         data \
80         eval \
81         example1 \
82         example2 \
83         example3 \
84         example4 \
85         file \
86         floppy \
87         full \
88         guestfs \
89         info \
90         iso \
91         libvirt \
92         linuxdisk \
93         memory \
94         nbd \
95         null \
96         ondemand \
97         partitioning \
98         pattern \
99         random \
100         S3 \
101         sparse-random \
102         split \
103         ssh \
104         tmpdisk \
105         torrent \
106         vddk \
107         zero \
108         "
109 plugins="$(echo $(printf %s\\n $lang_plugins $non_lang_plugins | sort -u))"
110 filters="\
111         blocksize \
112         blocksize-policy \
113         cache \
114         cacheextents \
115         checkwrite \
116         cow \
117         ddrescue \
118         delay \
119         error \
120         exitlast \
121         exitwhen \
122         exportname \
123         ext2 \
124         extentlist \
125         fua \
126         gzip \
127         ip \
128         limit \
129         log \
130         luks \
131         multi-conn \
132         nocache \
133         noextents \
134         nofilter \
135         noparallel \
136         nozero \
137         offset \
138         partition \
139         pause \
140         protect \
141         rate \
142         readahead \
143         retry \
144         retry-request \
145         scan \
146         stats \
147         swab \
148         tar \
149         tls-fallback \
150         truncate \
151         xz \
152         "
153 AC_SUBST([plugins])
154 AC_SUBST([lang_plugins])
155 AC_SUBST([non_lang_plugins])
156 AC_SUBST([filters])
158 dnl Some very basic tools.
159 AC_PROG_SED
160 AC_PROG_RANLIB
162 dnl Check for basic C environment.
163 AC_PROG_CC
164 AC_PROG_INSTALL
165 AC_PROG_CPP
166 AC_SYS_LARGEFILE
168 AC_C_PROTOTYPES
169 test "x$U" != "x" && AC_MSG_ERROR([Compiler not ANSI compliant])
171 AM_PROG_CC_C_O
173 dnl Define the host CPU architecture (defines 'host_cpu').
174 AC_CANONICAL_HOST
175 AC_DEFINE_UNQUOTED([host_cpu],["$host_cpu"],[Host architecture.])
177 dnl Define 'host_os'.
178 AC_DEFINE_UNQUOTED([host_os],["$host_os"],[Host operating system.])
180 dnl Defines WORDS_BIGENDIAN on big endian platforms.
181 AC_C_BIGENDIAN
183 dnl These are defined in <unistd.h> which is included by
184 dnl AC_DEFAULT_INCLUDES.
185 AC_CHECK_SIZEOF([pid_t])
186 AC_CHECK_SIZEOF([uid_t])
187 AC_CHECK_SIZEOF([gid_t])
189 dnl Check for C++ (optional, we just use this to test the header
190 dnl can be included from C++ code).
191 AC_PROG_CXX
193 dnl The C++ compiler test is pretty useless because even if it fails
194 dnl it sets CXX=g++.  So test the compiler actually works.
195 AC_MSG_CHECKING([if the C++ compiler really really works])
196 AS_IF([$CXX --version >&AS_MESSAGE_LOG_FD 2>&1],[have_cxx=yes],[have_cxx=no])
197 AC_MSG_RESULT([$have_cxx])
198 AM_CONDITIONAL([HAVE_CXX], [test "$have_cxx" = "yes"])
200 AC_ARG_ENABLE([gcc-warnings],
201     [AS_HELP_STRING([--enable-gcc-warnings],
202                     [turn on lots of GCC warnings (for developers)])],
203      [case $enableval in
204       yes|no) ;;
205       *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
206       esac
207       gcc_warnings=$enableval],
208       [gcc_warnings=no]
210 if test "x$gcc_warnings" = "xyes"; then
211     WARNINGS_CFLAGS="-Wall -Wshadow -Wvla -Werror"
212     AC_SUBST([WARNINGS_CFLAGS])
215 dnl Check if the compiler supports -std=c90 flag.  This is only used
216 dnl during a test.  OpenBSD GCC does not support this flag so we skip
217 dnl that test.
218 AC_MSG_CHECKING([if the compiler supports -std=c90 for ANSI C test])
219 old_CFLAGS="$CFLAGS"
220 CFLAGS="$CFLAGS -std=c90"
221 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
222     [supports_std_c90=yes],
223     [supports_std_c90=no])
224 CFLAGS="$old_CFLAGS"
225 AC_MSG_RESULT([$supports_std_c90])
226 AM_CONDITIONAL([CAN_TEST_ANSI_C], [test "x$supports_std_c90" = "xyes"])
228 dnl Check for __builtin_*_overflow.  We need the dummy parameters
229 dnl else detection doesn't work correctly for some reason.
230 AC_CHECK_DECLS([__builtin_add_overflow(int, int, int *),
231                 __builtin_mul_overflow(int, int, int *)],
232                 [], [], [])
234 dnl On Haiku we must use BSD-compatibility headers to get the endian
235 dnl macros we use.
236 AC_MSG_CHECKING(whether OS-dependent include paths are required)
237 AS_CASE([$host_os],
238   [haiku*], [CFLAGS="$CFLAGS -I`findpaths -p /system B_FIND_PATH_HEADERS_DIRECTORY`/bsd"; AC_MSG_RESULT(yes)],
239   [AC_MSG_RESULT(no)]
242 dnl On Linux /tmp is often tmpfs which is not large enough, so use /var/tmp.
243 dnl But Haiku only has /tmp.
244 AC_MSG_CHECKING([for temporary directory for large files])
245 AS_CASE([$host_os],
246   [haiku*], [LARGE_TMPDIR=/tmp],
247   [LARGE_TMPDIR=/var/tmp]
249 AC_MSG_RESULT([$LARGE_TMPDIR])
250 AC_DEFINE_UNQUOTED([LARGE_TMPDIR],["$LARGE_TMPDIR"],
251                    [Temporary directory for large files])
253 dnl Check if libc has program_invocation_short_name.
254 AC_CHECK_DECLS([program_invocation_short_name], [], [], [#include <errno.h>])
256 AX_PTHREAD
258 dnl Check if __attribute__((cleanup(...))) works.
259 dnl Set -Werror, otherwise gcc will only emit a warning for attributes
260 dnl that it doesn't understand.
261 acx_nbdkit_save_CFLAGS="${CFLAGS}"
262 CFLAGS="${CFLAGS} -Werror"
263 AC_MSG_CHECKING([if __attribute__((cleanup(...))) works with this compiler])
264 AC_COMPILE_IFELSE([
265 AC_LANG_SOURCE([[
266 #include <stdio.h>
267 #include <stdlib.h>
269 void
270 freep (void *ptr)
272   exit (EXIT_SUCCESS);
275 void
276 test (void)
278   __attribute__((cleanup(freep))) char *ptr = malloc (100);
279   (void)ptr;
283 main (int argc, char *argv[])
285   test ();
286   exit (EXIT_FAILURE);
289     ],[
290     AC_MSG_RESULT([yes])
291     ],[
292     AC_MSG_RESULT([no])
293     AC_MSG_ERROR(
294 ['__attribute__((cleanup(...)))' does not work.
296 You may not be using a sufficiently recent version of GCC or CLANG, or
297 you may be using a C compiler which does not support this attribute,
298 or the configure test may be wrong.
300 This code requires the attribute to work for proper locking between threads.])])
301 CFLAGS="${acx_nbdkit_save_CFLAGS}"
303 dnl Check for __auto_type (GCC extension).
304 AC_MSG_CHECKING([if __auto_type is available in this compiler])
305 AC_COMPILE_IFELSE([
306 AC_LANG_SOURCE([[
307 static int
308 test (int a)
310   __auto_type at = a;
311   return at;
314     ],[
315     AC_MSG_RESULT([yes])
316     AC_DEFINE([HAVE_AUTO_TYPE],[1],[__auto_type is available])
317     ],[
318     AC_MSG_RESULT([no])
319     ]
322 dnl 'environ' is not always declared in public header files:
323 dnl Linux => <unistd.h>  Haiku => <stdlib.h>
324 dnl FreeBSD & OpenBSD => not declared
325 dnl On platforms where it's not declared we must add an extern decl.
326 AC_MSG_CHECKING([if environ is declared in header files])
327 AC_COMPILE_IFELSE([
328 AC_LANG_SOURCE([[
329 #include <stdlib.h>
330 #include <unistd.h>
331 static int
332 test (void)
334   const char **env = environ;
335   return env ? 1 : 0; // this just forces env to be used
338     ],[
339     AC_MSG_RESULT([yes])
340     AC_DEFINE([HAVE_ENVIRON_DECL],[1],[environ is declared in headers])
341     ],[
342     AC_MSG_RESULT([no])
343     ]
346 dnl Check for other headers, all optional.
347 AC_CHECK_HEADERS([\
348         alloca.h \
349         afunix.h \
350         arpa/inet.h \
351         byteswap.h \
352         endian.h \
353         grp.h \
354         linux/fs.h \
355         netdb.h \
356         netinet/in.h \
357         netinet/tcp.h \
358         pwd.h \
359         termios.h \
360         stdatomic.h \
361         syslog.h \
362         sys/endian.h \
363         sys/ioctl.h \
364         sys/mman.h \
365         sys/prctl.h \
366         sys/procctl.h \
367         sys/socket.h \
368         sys/statvfs.h \
369         sys/ucred.h \
370         sys/un.h \
371         sys/vsock.h \
372         sys/wait.h \
373         winsock2.h])
375 AC_CHECK_HEADERS([linux/vm_sockets.h], [], [], [#include <sys/socket.h>])
377 dnl Check for functions in libc, all optional.
378 AC_CHECK_FUNCS([\
379         accept4 \
380         fdatasync \
381         flockfile \
382         funlockfile \
383         inet_ntop \
384         inet_pton \
385         mkostemp \
386         mlock \
387         mlockall \
388         munlock \
389         open_memstream \
390         pipe \
391         pipe2 \
392         ppoll \
393         posix_fadvise \
394         posix_memalign \
395         valloc])
397 dnl Check for structs and members.
398 AC_CHECK_MEMBERS([struct dirent.d_type], [], [], [[#include <dirent.h>]])
399 AC_CHECK_MEMBERS([struct ucred.uid], [], [],
400                  [[
401 #ifdef HAVE_SYS_SOCKET_H
402 #include <sys/socket.h>
403 #endif
404 #ifdef HAVE_SYS_UCRED_H
405 #include <sys/ucred.h>
406 #endif
408 AC_CHECK_MEMBERS([struct sockpeercred.uid], [], [],
409                  [[
410 #ifdef HAVE_SYS_SOCKET_H
411 #include <sys/socket.h>
412 #endif
415 dnl Replacement functions that we provide for some platforms.
416 AC_CONFIG_LIBOBJ_DIR([common/replacements])
417 AC_REPLACE_FUNCS([\
418         fdatasync \
419         fsync \
420         get_current_dir_name \
421         getdelim \
422         getline \
423         openlog \
424         open_memstream \
425         poll \
426         posix_memalign \
427         pread \
428         pwrite \
429         realpath \
430         strndup \
431         sysconf \
432         syslog \
433         vsyslog])
435 dnl Check whether printf("%m") works
436 AC_CACHE_CHECK([whether the printf family supports %m],
437   [nbdkit_cv_func_printf_percent_m],
438   [AC_RUN_IFELSE(
439     [AC_LANG_PROGRAM([[
440 #include <stdio.h>
441 #include <string.h>
442 #include <errno.h>
443     ]], [[
444     char buf[200] = "";
445     errno = EINVAL;
446     snprintf(buf, sizeof buf, "%m");
447     return !!strcmp (buf, strerror (EINVAL));
448     ]])],
449     [nbdkit_cv_func_printf_percent_m=yes],
450     [nbdkit_cv_func_printf_percent_m=no],
451     [[
452     case "$host_os" in
453       *-gnu* | gnu*) nbdkit_cv_func_printf_percent_m=yes;;
454       *) nbdkit_cv_func_printf_percent_m="guessing no";;
455     esac
456     ]])])
457 AS_IF([test "x$nbdkit_cv_func_printf_percent_m" = xyes],
458   [AC_DEFINE([HAVE_VFPRINTF_PERCENT_M],[1],
459     [Define to 1 if vfprintf supports %m.])])
461 old_LIBS="$LIBS"
462 AC_SEARCH_LIBS([dlsym], [dl dld], [
463         AS_IF([test "x$ac_cv_search_dlsym" != "xnone required"],
464             [DL_LIBS="$ac_cv_search_dlsym"], [DL_LIBS=])
465         AC_SUBST([DL_LIBS])
466     ], [AC_MSG_ERROR([unable to find the dlsym() function])
468 LIBS="$old_LIBS"
470 dnl Test if <iconv.h> header can build working binaries.
472 dnl On FreeBSD: iconv and libiconv both exist, both can be installed
473 dnl simultaneously, <iconv.h> can exist in two separate places, and
474 dnl if you get the wrong header/library mix everything breaks.
476 dnl On Haiku: libiconv is required to link to iconv_* functions.
477 AC_ARG_WITH([iconv],
478     [AS_HELP_STRING([--without-iconv],
479                     [don't try to link against iconv @<:@default=check@:>@])],
480     [],
481     [with_iconv=check])
482 AS_IF([test "x$with_iconv" != "xno"],[
483     AC_CHECK_HEADER([iconv.h],[
484         AC_MSG_CHECKING([if <iconv.h> can be used to link a program])
485         AC_LINK_IFELSE([
486 AC_LANG_SOURCE([[
487 #include <stdio.h>
488 #include <stdlib.h>
489 #include <iconv.h>
491 main (int argc, char *argv[])
493   iconv_t ic = iconv_open ("", "");
494   iconv_close (ic);
495   exit (0);
498             ],[
499             AC_MSG_RESULT([yes])
500             iconv_working=yes
501             ],[
502             AC_MSG_RESULT([no])
503             ])
504         ])
505     ])
506 AM_CONDITIONAL([HAVE_ICONV], [test "x$iconv_working" = "xyes"])
508 use_linker_script=yes
510 dnl Don't use linker script on FreeBSD because FreeBSD's linker is
511 dnl broken.  See eg:
512 dnl https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=190851
513 dnl Also on macOS (darwin) which fails with:
514 dnl ld: unknown option: --version-script=./nbdkit.syms
515 dnl clang: error: linker command failed with exit code 1
516 AC_MSG_CHECKING([if we should disable the linker script (FreeBSD, macOS)])
517 AS_CASE([$host_os],
518   [freebsd*|darwin*], [
519       use_linker_script=no
520       AC_MSG_RESULT([yes])
521   ],
522   [AC_MSG_RESULT([no])]
525 dnl Check if -rdynamic linker flag works.
526 acx_nbdkit_save_LDFLAGS="${LDFLAGS}"
527 LDFLAGS="${LDFLAGS} -rdynamic"
528 AC_MSG_CHECKING([if linker supports -rdynamic])
529 AC_LINK_IFELSE([
530 AC_LANG_SOURCE([[
531 #include <stdlib.h>
533 main (int argc, char *argv[])
535   exit (EXIT_SUCCESS);
538     ],[
539     AC_MSG_RESULT([yes])
540     DL_LDFLAGS=-rdynamic
541     ],[
542     AC_MSG_RESULT([no])
544 dnl restore CFLAGS
545 LDFLAGS="${acx_nbdkit_save_LDFLAGS}"
546 AC_SUBST([DL_LDFLAGS])
548 dnl Check for dladdr in -ldl, optional.  This is a glibc extension.
549 old_LIBS="$LIBS"
550 LIBS="$DL_LIBS $LIBS"
551 AC_CHECK_FUNCS([dladdr])
552 LIBS="$old_LIBS"
554 dnl Is this Windows?
555 AC_MSG_CHECKING([if the target is Windows])
556 AS_CASE([$host_os],
557     [mingw*|msys*], [
558         is_windows=yes
559         LIBS="$LIBS -lmsvcrt -lkernel32 -luser32 -lws2_32"
560         NO_UNDEFINED_ON_WINDOWS="-no-undefined"
561         IMPORT_LIBRARY_ON_WINDOWS='-Wl,-L$(top_builddir)/server -Wl,-lnbdkit'
562         SOEXT="dll"
563         DIR_SEPARATOR_STR='\\'
564     ],
565     [is_windows=no
566      SOEXT="so"
567      DIR_SEPARATOR_STR=/]
569 AC_MSG_RESULT([$is_windows])
570 AC_SUBST([NO_UNDEFINED_ON_WINDOWS])
571 AC_SUBST([IMPORT_LIBRARY_ON_WINDOWS])
572 AC_SUBST([SOEXT])
573 AC_DEFINE_UNQUOTED([SOEXT],["$SOEXT"],[Extension used for shared objects/DLLs.])
574 AC_DEFINE_UNQUOTED([EXEEXT],["$EXEEXT"],[Extension used for executables.])
575 AC_DEFINE_UNQUOTED([DIR_SEPARATOR_STR],["$DIR_SEPARATOR_STR"],
576                    [String that separates path elements.])
577 AM_CONDITIONAL([IS_WINDOWS],[test "x$is_windows" = "xyes"])
579 AS_IF([test "x$is_windows" = "xyes"],[
580     dnl For Windows, look for the mc/windmc utility.
581     dnl XXX Do we need to check for mc.exe as well?
582     AC_CHECK_TOOLS([MC],[windmc mc],[no])
583     AS_IF([test "x$MC" = "xno"],
584           [AC_MSG_ERROR([mc/windmc utility must be available when compiling for Windows])])
586     dnl On Windows look for dlltool.
587     AC_CHECK_TOOLS([DLLTOOL],[dlltool],[no])
588     AS_IF([test "x$DLLTOOL" = "xno"],
589           [AC_MSG_ERROR([dlltool utility must be available when compiling for Windows])])
592 AC_SEARCH_LIBS([getaddrinfo], [network socket])
594 dnl Does this platform require libc_malloc_debug.so.0 (glibc >= 2.34)?
595 AC_MSG_CHECKING([if this is glibc >= 2.34])
596 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
597 #include <limits.h>
598 #if !defined(__GLIBC__) || __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 34)
599 #error "not glibc 2.34"
600 #endif
601         ]])], [is_glibc_234=yes], [is_glibc_234=no]
603 AC_MSG_RESULT([$is_glibc_234])
604 AM_CONDITIONAL([HAVE_GLIBC_234], [test "x$is_glibc_234" = "xyes"])
606 dnl Check for SELinux socket labelling (optional).
607 PKG_CHECK_MODULES([LIBSELINUX], [libselinux], [
608     AC_SUBST([LIBSELINUX_CFLAGS])
609     AC_SUBST([LIBSELINUX_LIBS])
610     AC_DEFINE([HAVE_LIBSELINUX],[1],[libselinux found at compile time.])
611 ], [
612     AC_MSG_WARN([libselinux not found, SELinux socket labelling support will be disabled.])
615 dnl Check for GnuTLS (optional, for TLS support).
616 PKG_CHECK_MODULES([GNUTLS], [gnutls >= 3.3.0], [
617     AC_SUBST([GNUTLS_CFLAGS])
618     AC_SUBST([GNUTLS_LIBS])
619     AC_DEFINE([HAVE_GNUTLS],[1],[gnutls found at compile time.])
620 ], [
621     AC_MSG_WARN([gnutls not found or < 3.3.0, TLS support will be disabled.])
623 AM_CONDITIONAL([HAVE_GNUTLS], [test "x$GNUTLS_LIBS" != "x"])
625 AS_IF([test "x$GNUTLS_LIBS" != "x"],[
626     AC_MSG_CHECKING([for default TLS session priority string])
627     AC_ARG_WITH([tls-priority],
628         [AS_HELP_STRING([--with-tls-priority=...],
629                         [default TLS session priority string @<:@default=NORMAL@:>@])],
630         [tls_priority=$withval],
631         [tls_priority=NORMAL])
632     AC_MSG_RESULT([$tls_priority])
633     AC_DEFINE_UNQUOTED([TLS_PRIORITY],["$tls_priority"],
634                        [Default TLS session priority string])
636     # Check for APIs which may not be present.
637     old_LIBS="$LIBS"
638     LIBS="$GNUTLS_LIBS $LIBS"
639     AC_CHECK_FUNCS([\
640         gnutls_base64_decode2 \
641         gnutls_certificate_set_known_dh_params \
642         gnutls_group_get \
643         gnutls_group_get_name \
644         gnutls_pbkdf2 \
645         gnutls_session_set_verify_cert \
646         gnutls_srp_server_get_username \
647         gnutls_transport_is_ktls_enabled \
648     ])
649     AC_CHECK_HEADERS([gnutls/socket.h])
650     LIBS="$old_LIBS"
652     dnl macOS has its own program called certtool and packages the
653     dnl GnuTLS tool as "gnutls-certtool".
654     AC_CHECK_PROGS([CERTTOOL],[gnutls-certtool certtool],[certtool])
656 AM_CONDITIONAL([HAVE_GNUTLS_PBKDF2],
657     [test "x$GNUTLS_LIBS" != "x" && test "x$ac_cv_func_gnutls_pbkdf2" = xyes])
659 dnl Check for some commands used by the tests which should be the GNU
660 dnl coreutils variants.  On macOS these are prefixed with 'g' or 'gnu'.
661 AC_CHECK_PROGS([CUT],[gnucut cut],[cut])
662 AC_CHECK_PROGS([STAT],[gstat stat],[stat])
663 AC_CHECK_PROGS([TRUNCATE],[gtruncate truncate],[truncate])
665 AC_ARG_ENABLE([linuxdisk],
666     [AS_HELP_STRING([--disable-linuxdisk],
667                     [disable linuxdisk plugin @<:@default=check@:>@])],
668     [],
669     [enable_linuxdisk=check])
670 dnl Check for mke2fs -d (used by linuxdisk plugin).  There are two
671 dnl possible outcomes that we care about: (1) We have mke2fs and
672 dnl it supports the -d option.  (2) We either don't have mke2fs
673 dnl or it's too old to support the -d option (eg. on RHEL 7).
674 mke2fs_with_d=no
675 AS_IF([test "$enable_linuxdisk" != "no"], [
676     AC_MSG_CHECKING([for mke2fs supporting the -d option])
677     AS_IF([mke2fs -V >/dev/null 2>&1], [
678         AS_IF([LANG=C mke2fs -d 2>&1 | grep -sq "option requires an argument"], [
679             mke2fs_with_d=yes
680         ])
681     ])
682     AC_MSG_RESULT([$mke2fs_with_d])
684 AM_CONDITIONAL([HAVE_MKE2FS_WITH_D],[test "x$mke2fs_with_d" = "xyes"])
686 dnl Check for valgrind.
687 AC_CHECK_PROG([VALGRIND],[valgrind],[valgrind],[no])
689 dnl If valgrind headers are available (optional).
690 dnl Although the runtime check adds only a trivial amount of code, you can
691 dnl avoid it with explicit --disable-valgrind.
692 AC_ARG_ENABLE([valgrind],
693     [AS_HELP_STRING([--disable-valgrind],
694                     [disable Valgrind probe])],
695     [],
696     [enable_valgrind=check])
697 AS_IF([test "x$enable_valgrind" != "xno"],[
698     PKG_CHECK_MODULES([VALGRIND], [valgrind], [
699         AC_SUBST([VALGRIND_CFLAGS])
700         AC_SUBST([VALGRIND_LIBS])
701         AC_DEFINE([HAVE_VALGRIND],[1],[Valgrind headers found at compile time])
702     ],[
703         AS_IF([test "x$enable_valgrind" = "xyes"], [
704             AC_MSG_ERROR([--enable-valgrind given, but Valgrind headers are not available])
705         ])
706     ])
709 dnl Build the special libFuzzer version of nbdkit.  DO NOT USE THIS for
710 dnl normal builds.  See fuzzing/README.
711 AC_ARG_ENABLE([libfuzzer],
712     [AS_HELP_STRING([--enable-libfuzzer],
713                     [build libFuzzer test binary (developers only)])],
714     [],
715     [enable_libfuzzer=no])
716 AS_IF([test "x$enable_libfuzzer" = "xyes"],[
717     AC_DEFINE([ENABLE_LIBFUZZER],[1],[Enable special libFuzzer binary])
718     # We have to disable the linker script for libFuzzer because Clang
719     # adds loads of fuzzer and ASAN-related symbols that are required
720     # by the plugins but which our linker script tries to hide.
721     use_linker_script=no
723 AM_CONDITIONAL([ENABLE_LIBFUZZER],[test "x$enable_libfuzzer" = "xyes"])
725 dnl Should we use the linker script (ld --version-script)?  Note
726 dnl some tests above may set this variable.
727 AC_ARG_ENABLE([linker-script],
728     [AS_HELP_STRING([--disable-linker-script],
729                     [disable linker script for server (developers only)])],
730     [use_linker_script=$enableval],
731     [])
732 AM_CONDITIONAL([USE_LINKER_SCRIPT],
733                [test "x$use_linker_script" = "xyes"])
735 dnl Bash completion.
736 PKG_CHECK_MODULES([BASH_COMPLETION], [bash-completion >= 2.0], [
737     bash_completion=yes
738     AC_MSG_CHECKING([for bash-completions directory])
739     m4_ifdef([PKG_CHECK_VAR],[
740         PKG_CHECK_VAR(bashcompdir, [bash-completion], [completionsdir])
741     ])
742     AS_IF([test -z "$bashcompdir"], [
743         bashcompdir="${sysconfdir}/bash_completion.d"
744     ])
745     AC_MSG_RESULT([$bashcompdir])
746     AC_SUBST([bashcompdir])
748     bash_completion=no
749     AC_MSG_WARN([bash-completion not installed])
751 AM_CONDITIONAL([HAVE_BASH_COMPLETION],[test "x$bash_completion" = "xyes"])
753 dnl Check we have enough to run podwrapper.
754 AC_CHECK_PROG([PERL],[perl],[perl],[no])
755 AS_IF([test "x$PERL" != "xno"],[
756     AC_MSG_CHECKING([if we have perl Pod::Man and Pod::Simple])
757     AS_IF([$PERL -MPod::Man -MPod::Simple -e 1 >&AS_MESSAGE_LOG_FD 2>&1],[
758         enable_pod=yes
759     ],[
760         enable_pod=no
761     ])
762     AC_MSG_RESULT([$enable_pod])
764 AM_CONDITIONAL([HAVE_POD],
765                [test "x$PERL" != "xno" && test "x$enable_pod" = "xyes"])
767 dnl Define the path to the podwrapper program.
768 PODWRAPPER="$PERL $(pwd)/podwrapper.pl"
769 AC_SUBST([PODWRAPPER])
771 dnl Allow all plugins and filters to be disabled.
772 AC_ARG_ENABLE([plugins],
773     [AS_HELP_STRING([--disable-plugins],
774                     [disable all bundled plugins and filters])])
775 AM_CONDITIONAL([HAVE_PLUGINS], [test "x$enable_plugins" != "xno"])
777 dnl Check for Perl, for embedding in the perl plugin.
778 dnl Note that the perl binary is checked above.
779 AC_ARG_ENABLE([perl],
780     [AS_HELP_STRING([--disable-perl], [disable Perl embed plugin])],
781     [],
782     [enable_perl=yes])
783 AS_IF([test "x$PERL" != "xno" && test "x$enable_perl" != "xno"],[
784     dnl Check for Perl archlib.
785     AC_MSG_CHECKING([for Perl embed archlib])
786     PERL_ARCHLIB="$($PERL -MConfig -e 'print $Config{archlib}')"
787     AS_IF([ test -n "$PERL_ARCHLIB" ],[
788         AC_MSG_RESULT([$PERL_ARCHLIB])
789     ],[
790         AC_MSG_NOTICE([Perl embed module disabled])
791         enable_perl=no
792     ])
794     dnl Check for Perl CFLAGS.
795     AC_MSG_CHECKING([for Perl embed CFLAGS])
796     PERL_CFLAGS="$($PERL -MExtUtils::Embed -e 'ccflags')"
797     AS_IF([ test -n "$PERL_CFLAGS" ],[
798         AC_MSG_RESULT([$PERL_CFLAGS])
799     ],[
800         AC_MSG_NOTICE([Perl embed module disabled])
801         enable_perl=no
802     ])
804     dnl Check for Perl LDOPTS.
805     AC_MSG_CHECKING([for Perl embed LDOPTS])
806     PERL_LDOPTS="$($PERL -MExtUtils::Embed -e 'ldopts')"
807     AC_MSG_RESULT([$PERL_LDOPTS])
809     dnl Check these actually work.
810     AC_MSG_CHECKING([whether Perl modules will compile])
811     old_CFLAGS="$CFLAGS"
812     old_LIBS="$LIBS"
813     CFLAGS="$PERL_CFLAGS -I$PERL_ARCHLIB/CORE $CFLAGS"
814     LIBS="$PERL_LDOPTS $LIBS"
815     AC_CHECK_FUNCS([perl_alloc])
816     CFLAGS="$old_CFLAGS"
817     LIBS="$old_LIBS"
818     if test "x$ac_cv_func_perl_alloc" != xyes; then
819       enable_perl=no
820     fi
822 AM_CONDITIONAL([HAVE_PERL],[test "x$enable_perl" != "xno" && test "x$PERL" != "xno"])
823 AC_SUBST([PERL_ARCHLIB])
824 AC_SUBST([PERL_CFLAGS])
825 AC_SUBST([PERL_LDOPTS])
827 dnl Check for Python 3, for embedding in the python plugin.
828 AC_PATH_PROGS([PYTHON],[python3 python],[no])
829 AC_ARG_ENABLE([python],
830     [AS_HELP_STRING([--disable-python], [disable Python embed plugin])],
831     [],
832     [enable_python=yes])
833 AS_IF([test "x$PYTHON" != "xno" && test "x$enable_python" != "xno"],[
834     AC_MSG_CHECKING([version of $PYTHON])
835     PYTHON_VERSION_MAJOR=`$PYTHON -c "import sys; print (sys.version_info@<:@0@:>@)"`
836     PYTHON_VERSION_MINOR=`$PYTHON -c "import sys; print (sys.version_info@<:@1@:>@)"`
837     PYTHON_VERSION="$PYTHON_VERSION_MAJOR.$PYTHON_VERSION_MINOR"
838     AS_IF([test -n "$PYTHON_VERSION"],[
839         AC_MSG_RESULT([$PYTHON_VERSION])
840     ],[
841         AC_MSG_NOTICE([Python embed module disabled])
842         enable_python=no
843     ])
845     AC_MSG_CHECKING([Python major version is 3])
846     AS_IF([test "x$PYTHON_VERSION_MAJOR" = "x3"],[
847         AC_MSG_RESULT([yes])
848     ],[
849         AC_MSG_RESULT([no])
850         AC_MSG_ERROR([Python $PYTHON_VERSION_MAJOR <> 3 is no longer supported.
852 Python 2 end of life is 2020-01-01 and nbdkit >= 1.16 no longer
853 supports it.
855 If you want to use Python 2, you will need to use nbdkit 1.14.])
856     ])
858     dnl Check for Python CFLAGS, libraries.
859     dnl For Python >= 3.8 we have to use python-<VERSION>-embed.pc, see:
860     dnl https://docs.python.org/3.8/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build
861     dnl The python.pc is called python-<VERSION>.pc on Debian and
862     dnl later versions of Fedora, and python.pc on older versions
863     dnl of Fedora.
864     PKG_CHECK_MODULES([PYTHON], [python-"$PYTHON_VERSION"-embed], [
865         AC_SUBST([PYTHON_CFLAGS])
866         AC_SUBST([PYTHON_LIBS])
867         AC_SUBST([PYTHON_VERSION])
868         AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time])
869     ],[
870     PKG_CHECK_MODULES([PYTHON], [python-"$PYTHON_VERSION"], [
871         AC_SUBST([PYTHON_CFLAGS])
872         AC_SUBST([PYTHON_LIBS])
873         AC_SUBST([PYTHON_VERSION])
874         AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time])
875     ],[
876     PKG_CHECK_MODULES([PYTHON], [python], [
877         AC_SUBST([PYTHON_CFLAGS])
878         AC_SUBST([PYTHON_LIBS])
879         AC_SUBST([PYTHON_VERSION])
880         AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time])
881     ],[
882         AC_MSG_WARN([python $PYTHON_VERSION not found])
883         enable_python=no
884     ])])])
886 AM_CONDITIONAL([HAVE_PYTHON],[test "x$enable_python" != "xno" && test "x$PYTHON" != "xno"])
887 AC_SUBST([PYTHON_CFLAGS])
888 AC_SUBST([PYTHON_LIBS])
889 AC_SUBST([PYTHON_LDFLAGS])
891 dnl For the OCaml plugin, you can set OCAMLOPTFLAGS before running
892 dnl ./configure to specify any extra flags you want to pass to
893 dnl ocamlopt.  For example to enable OCaml warnings:
894 dnl OCAMLOPTFLAGS="-warn-error +A-3"
895 AC_SUBST([OCAMLOPTFLAGS])
897 dnl Check for OCaml, for embedding in the ocaml plugin.
898 AC_PROG_OCAML
899 AC_ARG_ENABLE([ocaml],
900     [AS_HELP_STRING([--disable-ocaml], [disable OCaml embed plugin])],
901     [],
902     [enable_ocaml=yes])
903 AS_IF([test "x$OCAMLOPT" != "xno" && test "x$enable_ocaml" != "xno"],[
904     dnl Check OCaml can create a shared library (see README for details).
905     AC_MSG_CHECKING([if $OCAMLOPT can create a shared library])
906     echo 'print_endline "test"' > conftest.ml
907     AS_IF([$OCAMLOPT $OCAMLOPTFLAGS -output-obj -runtime-variant _pic -o conftest.so conftest.ml >&AS_MESSAGE_LOG_FD 2>&1],[
908         AC_MSG_RESULT([yes])
909         ocaml_link_shared=yes
910     ],[
911         AC_MSG_RESULT([no])
912     ])
913     rm -f conftest.ml conftest.cmi conftest.cmx conftest.so conftest.o
915 AM_CONDITIONAL([HAVE_OCAML],[test "x$OCAMLOPT" != "xno" &&
916                              test "x$ocaml_link_shared" = "xyes"])
917 AM_CONDITIONAL([HAVE_OCAMLDOC],[test "x$OCAMLDOC" != "xno"])
919 dnl Check if OCaml has caml_alloc_initialized_string (added 2017).
920 AS_IF([test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno" && \
921        test "x$enable_ocaml" = "xyes"],[
922     AC_MSG_CHECKING([for caml_alloc_initialized_string])
923     cat >conftest.c <<'EOF'
924 #include <caml/alloc.h>
925 int main () { char *p = (void *) caml_alloc_initialized_string; return 0; }
927     AS_IF([$OCAMLC conftest.c >&AS_MESSAGE_LOG_FD 2>&1],[
928         AC_MSG_RESULT([yes])
929         AC_DEFINE([HAVE_CAML_ALLOC_INITIALIZED_STRING],[1],
930                   [caml_alloc_initialized_string found at compile time.])
931     ],[
932         AC_MSG_RESULT([no])
933     ])
934     rm -f conftest.c conftest.o
937 dnl Check if OCaml has caml_shutdown (added 2014).
938 AS_IF([test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno" && \
939        test "x$enable_ocaml" = "xyes"],[
940     AC_MSG_CHECKING([for caml_shutdown])
941     cat >conftest.c <<'EOF'
942 #include <caml/callback.h>
943 int main () { char *p = (void *) caml_shutdown; return 0; }
945     AS_IF([$OCAMLC conftest.c >&AS_MESSAGE_LOG_FD 2>&1],[
946         AC_MSG_RESULT([yes])
947         AC_DEFINE([HAVE_CAML_SHUTDOWN],[1],
948                   [caml_shutdown found at compile time.])
949     ],[
950         AC_MSG_RESULT([no])
951     ])
952     rm -f conftest.c conftest.o
955 dnl For developing plugins in Rust, optional.
956 dnl Rust does not play nicely with VPATH builds
957 AC_CHECK_PROG([CARGO],[cargo],[cargo],[no])
958 AC_ARG_ENABLE([rust],
959     [AS_HELP_STRING([--disable-rust], [disable Rust plugin])],
960     [],
961     [if test "x$(realpath $srcdir)" = "x$(realpath .)"; then
962        enable_rust=yes
963      else
964        enable_rust=no
965      fi])
966 AM_CONDITIONAL([HAVE_RUST],
967                [test "x$CARGO" != "xno" && test "x$enable_rust" != "xno"])
969 dnl Check for Ruby, for embedding in the Ruby plugin.
970 AC_CHECK_PROG([RUBY],[ruby],[ruby],[no])
971 AC_ARG_ENABLE([ruby],
972     [AS_HELP_STRING([--disable-ruby], [disable Ruby plugin])],
973     [],
974     [enable_ruby=yes])
975 AS_IF([test "x$RUBY" != "xno" && test "x$enable_ruby" != "xno"],[
976     PKG_CHECK_MODULES([RUBY], [ruby], [
977         AC_SUBST([RUBY_CFLAGS])
978         AC_SUBST([RUBY_LIBS])
979     ],[
980         AC_MSG_WARN([ruby not found])
981         enable_ruby=no
982     ])
984 AM_CONDITIONAL([HAVE_RUBY],[test "x$RUBY" != "xno" &&
985                             test "x$enable_ruby" = "xyes"])
987 dnl Check for Tcl, for embedding in the Tcl plugin.
988 AC_ARG_ENABLE([tcl],
989     [AS_HELP_STRING([--disable-tcl], [disable Tcl plugin])],
990     [],
991     [enable_tcl=yes])
992 AS_IF([test "x$enable_tcl" != "xno"],[
993     PKG_CHECK_MODULES([TCL], [tcl], [
994         AC_SUBST([TCL_CFLAGS])
995         AC_SUBST([TCL_LIBS])
996     ],[
997         AC_MSG_WARN([Tcl not found])
998         enable_tcl=no
999     ])
1001 AM_CONDITIONAL([HAVE_TCL],[test "x$enable_tcl" = "xyes"])
1003 dnl Check for Lua, for embedding in the Lua plugin.
1004 AC_ARG_ENABLE([lua],
1005     [AS_HELP_STRING([--disable-lua], [disable Lua plugin])],
1006     [],
1007     [enable_lua=yes])
1008 AS_IF([test "x$enable_lua" != "xno"],[
1009     PKG_CHECK_MODULES([LUA], [lua], [
1010         AC_SUBST([LUA_CFLAGS])
1011         AC_SUBST([LUA_LIBS])
1013         dnl Lua 5.1 used by RHEL 7 does not have lua_isinteger.
1014         old_LIBS="$LIBS"
1015         LIBS="$LUA_LIBS $LIBS"
1016         AC_CHECK_FUNCS([lua_isinteger])
1017         LIBS="$old_LIBS"
1018     ],[
1019         AC_MSG_WARN([Lua not found])
1020         enable_lua=no
1021     ])
1023 AM_CONDITIONAL([HAVE_LUA],[test "x$enable_lua" = "xyes"])
1025 dnl Check for golang.
1026 AC_ARG_ENABLE([golang],
1027     AS_HELP_STRING([--disable-golang], [disable Go language plugin]),
1028         [],
1029         [enable_golang=yes])
1030 AS_IF([test "x$enable_golang" != "xno"],[
1031     AC_CHECK_PROG([GOLANG],[go],[go],[no])
1032     AS_IF([test "x$GOLANG" != "xno"],[
1033         AC_MSG_CHECKING([if $GOLANG is usable])
1034         AS_IF([$GOLANG run $srcdir/plugins/golang/config-test.go 2>&AS_MESSAGE_LOG_FD && \
1035                $GOLANG help modules 2>&AS_MESSAGE_LOG_FD 1>&2],[
1036             AC_MSG_RESULT([yes])
1038             # Substitute some golang environment.
1039             GOOS=`$GOLANG env GOOS`
1040             GOARCH=`$GOLANG env GOARCH`
1041             GOROOT=`$GOLANG env GOROOT`
1042             AC_SUBST([GOOS])
1043             AC_SUBST([GOARCH])
1044             AC_SUBST([GOROOT])
1045         ],[
1046             AC_MSG_RESULT([no])
1047             AC_MSG_WARN([golang ($GOLANG) is installed but not usable])
1048             GOLANG=no
1049         ])
1050     ])
1051 ],[GOLANG=no])
1052 AM_CONDITIONAL([HAVE_GOLANG],[test "x$GOLANG" != "xno"])
1054 dnl Check for curl (only if you want to compile the curl plugin).
1055 AC_ARG_WITH([curl],
1056     [AS_HELP_STRING([--without-curl],
1057                     [disable curl plugin @<:@default=check@:>@])],
1058     [],
1059     [with_curl=check])
1060 AS_IF([test "$with_curl" != "no"],[
1061     PKG_CHECK_MODULES([CURL], [libcurl],[
1062         printf "libcurl version is "; $PKG_CONFIG --modversion libcurl
1063         AC_SUBST([CURL_CFLAGS])
1064         AC_SUBST([CURL_LIBS])
1065         AC_DEFINE([HAVE_CURL],[1],[curl found at compile time.])
1066         AC_CHECK_DECL([CURLOPT_UNIX_SOCKET_PATH], [
1067             AC_DEFINE([HAVE_CURLOPT_UNIX_SOCKET_PATH],[1],
1068                       [CURLOPT_UNIX_SOCKET_PATH found at compile time.])
1069             ], [], [#include <curl/curl.h>])
1070     ],
1071     [AC_MSG_WARN([curl not found, curl plugin will be disabled])])
1073 AM_CONDITIONAL([HAVE_CURL],[test "x$CURL_LIBS" != "x"])
1075 dnl Check for libssh (only if you want to compile the ssh plugin).
1076 AC_ARG_WITH([ssh],
1077     [AS_HELP_STRING([--without-ssh],
1078                     [disable ssh plugin @<:@default=check@:>@])],
1079     [],
1080     [with_ssh=check])
1081 AS_IF([test "$with_ssh" != "no"],[
1082     PKG_CHECK_MODULES([SSH], [libssh >= 0.8.0],[
1083         printf "libssh version is "; $PKG_CONFIG --modversion libssh
1084         # Ubuntu 18.04 shipped prerelease of libssh-0.8.0 without
1085         # SSH_OPTIONS_NODELAY
1086         old_CFLAGS="$CFLAGS"
1087         CFLAGS="$CFLAGS $SSH_CFLAGS"
1088         AC_CHECK_DECL([SSH_OPTIONS_NODELAY], [
1089             AC_SUBST([SSH_CFLAGS])
1090             AC_SUBST([SSH_LIBS])
1091             # We don't need this in the code, just in this configure
1092             HAVE_SSH_OPTIONS_NODELAY=1
1093             ], [], [
1094             #include <libssh/libssh.h>
1095         ])
1096         CFLAGS="$old_CFLAGS"
1097     ],
1098     [AC_MSG_WARN([libssh not found, ssh plugin will be disabled])])
1100 AM_CONDITIONAL([HAVE_SSH],[test "x$HAVE_SSH_OPTIONS_NODELAY" != "x"])
1102 dnl Check for xorriso or genisoimage or mkisofs
1103 dnl (only if you want to compile the iso plugin).
1104 ISOPROG="no"
1105 is_xorriso=0
1106 AC_ARG_WITH([iso],
1107     [AS_HELP_STRING([--without-iso],
1108                     [disable iso plugin @<:@default=check@:>@])],
1109     [],
1110     [with_iso=check])
1111 AS_IF([test "$with_iso" != "no"],[
1112     AC_CHECK_PROG([XORRISO],[xorriso],[xorriso],[no])
1113     AC_CHECK_PROG([GENISOIMAGE],[genisoimage],[genisoimage],[no])
1114     AC_CHECK_PROG([MKISOFS],[mkisofs],[mkisofs],[no])
1115     AS_IF([test "x$XORRISO" != "xno"],[
1116         ISOPROG="$XORRISO"
1117         is_xorriso=1
1118     ],[
1119         AS_IF([test "x$GENISOIMAGE" != "xno"],[
1120             ISOPROG="$GENISOIMAGE"
1121         ],[
1122             AS_IF([test "x$MKISOFS" != "xno"],[
1123                 ISOPROG="$MKISOFS"
1124             ])
1125         ])
1126     ])
1127     AS_IF([test "x$ISOPROG" != "xno"],[
1128         printf "picked %s for nbdkit-iso-plugin\n" "$ISOPROG"
1129         AC_DEFINE_UNQUOTED([ISOPROG],["$ISOPROG"],
1130                            [Program used by iso plugin to make ISOs.])
1131         AS_IF([test "x$is_xorriso" = "x1"], [
1132             AC_DEFINE([ISOPROG_IS_XORRISO],[1],
1133                       [ISO program behaves like xorriso.])
1134         ])
1135     ])
1137 AC_SUBST([ISOPROG])
1138 AM_CONDITIONAL([HAVE_ISO],[test "x$ISOPROG" != "xno"])
1140 dnl Check for libvirt (only if you want to compile the libvirt plugin).
1141 AC_ARG_WITH([libvirt],
1142     [AS_HELP_STRING([--without-libvirt],
1143                     [disable libvirt plugin @<:@default=check@:>@])],
1144     [],
1145     [with_libvirt=check])
1146 AS_IF([test "$with_libvirt" != "no"],[
1147     PKG_CHECK_MODULES([LIBVIRT], [libvirt],[
1148         AC_SUBST([LIBVIRT_CFLAGS])
1149         AC_SUBST([LIBVIRT_LIBS])
1150         AC_DEFINE([HAVE_LIBVIRT],[1],[libvirt found at compile time.])
1151     ],
1152     [AC_MSG_WARN([libvirt not found, libvirt plugin will be disabled])])
1154 AM_CONDITIONAL([HAVE_LIBVIRT],[test "x$LIBVIRT_LIBS" != "x"])
1156 dnl Check for zlib (only if you want to compile the gzip filter).
1157 AC_ARG_WITH([zlib],
1158     [AS_HELP_STRING([--without-zlib],
1159                     [disable gzip filter @<:@default=check@:>@])],
1160     [],
1161     [with_zlib=check])
1162 AS_IF([test "$with_zlib" != "no"],[
1163     PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2.3.5],[
1164         AC_SUBST([ZLIB_CFLAGS])
1165         AC_SUBST([ZLIB_LIBS])
1166         AC_DEFINE([HAVE_ZLIB],[1],[zlib found at compile time.])
1167     ],
1168     [AC_MSG_WARN([zlib >= 1.2.3.5 not found, gzip filter will be disabled])])
1170 AM_CONDITIONAL([HAVE_ZLIB],[test "x$ZLIB_LIBS" != "x"])
1172 dnl Check for libnbd (only if you want to compile the nbd plugin).
1173 AC_ARG_WITH([libnbd],
1174     [AS_HELP_STRING([--without-libnbd],
1175                     [disable nbd plugin @<:@default=check@:>@])],
1176     [],
1177     [with_libnbd=check])
1178 AS_IF([test "$with_libnbd" != "no"],[
1179     PKG_CHECK_MODULES([LIBNBD], [libnbd >= 0.9.8],[
1180         printf "libnbd version is "; $PKG_CONFIG --modversion libnbd
1181         AC_SUBST([LIBNBD_CFLAGS])
1182         AC_SUBST([LIBNBD_LIBS])
1183         AC_DEFINE([HAVE_LIBNBD],[1],[libnbd found at compile time.])
1184     ],
1185     [AC_MSG_WARN([libnbd >= 0.9.8 not found, nbd plugin will be crippled])])
1188 dnl For backwards compatibilty, we have a second way to disable the nbd plugin.
1189 AC_ARG_ENABLE([nbd-plugin],
1190     [AS_HELP_STRING([--disable-nbd-plugin], [disable nbd plugin (deprecated, use --without-libnbd)])],
1191     [],
1192     [enable_nbd_plugin=yes])
1193 AM_CONDITIONAL([HAVE_LIBNBD],
1194   [test "x$LIBNBD_LIBS" != "x" && test "x$enable_nbd_plugin" = "xyes"])
1196 dnl Check for liblzma (only if you want to compile the xz filter).
1197 AC_ARG_WITH([liblzma],
1198     [AS_HELP_STRING([--without-liblzma],
1199                     [disable xz filter @<:@default=check@:>@])],
1200     [],
1201     [with_liblzma=check])
1202 AS_IF([test "$with_liblzma" != "no"],[
1203     PKG_CHECK_MODULES([LIBLZMA], [liblzma],[
1204         AC_SUBST([LIBLZMA_CFLAGS])
1205         AC_SUBST([LIBLZMA_LIBS])
1206         AC_DEFINE([HAVE_LIBLZMA],[1],[liblzma found at compile time.])
1207     ],
1208     [AC_MSG_WARN([liblzma not found, xz filter will be disabled])])
1210 AM_CONDITIONAL([HAVE_LIBLZMA],[test "x$LIBLZMA_LIBS" != "x"])
1212 dnl Check for zstd (only if you want to compile allocator=zstd).
1213 AC_ARG_WITH([libzstd],
1214     [AS_HELP_STRING([--without-libzstd],
1215                     [disable allocator=zstd @<:@default=check@:>@])],
1216     [],
1217     [with_libzstd=check])
1218 AS_IF([test "$with_libzstd" != "no"],[
1219     PKG_CHECK_MODULES([LIBZSTD], [libzstd],[
1220         AC_SUBST([LIBZSTD_CFLAGS])
1221         AC_SUBST([LIBZSTD_LIBS])
1222         AC_DEFINE([HAVE_LIBZSTD],[1],[libzstd found at compile time.])
1223     ],
1224     [AC_MSG_WARN([libzstd not found, allocator=zstd will be disabled])])
1226 AM_CONDITIONAL([HAVE_LIBZSTD],[test "x$LIBZSTD_LIBS" != "x"])
1228 dnl Check for libguestfs (only for the guestfs plugin and parts of
1229 dnl the test suite).
1230 AC_ARG_WITH([libguestfs],
1231     [AS_HELP_STRING([--without-libguestfs],
1232                     [disable guestfs plugin and tests @<:@default=check@:>@])],
1233     [],
1234     [with_libguestfs=check])
1235 AS_IF([test "$with_libguestfs" != "no"],[
1236     PKG_CHECK_MODULES([LIBGUESTFS], [libguestfs],[
1237         # Although the library was found, we want to make sure it supports nbd
1238         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1239 #include <guestfs.h>
1240         ]], [[
1241 #ifndef GUESTFS_ADD_DRIVE_OPTS_PROTOCOL
1242 #error unsupported
1243 #endif
1244         ]])], [
1245         AC_SUBST([LIBGUESTFS_CFLAGS])
1246         AC_SUBST([LIBGUESTFS_LIBS])
1247         AC_DEFINE([HAVE_LIBGUESTFS],[1],[libguestfs found at compile time.])
1248         ],[
1249         LIBGUESTFS_LIBS=
1250         AC_MSG_WARN([libguestfs too old, guestfs plugin and tests will be disabled])])
1251     ],
1252     [AC_MSG_WARN([libguestfs not found, guestfs plugin and tests will be disabled])])
1254 AM_CONDITIONAL([HAVE_LIBGUESTFS],[test "x$LIBGUESTFS_LIBS" != "x"])
1256 dnl Disable tests which need libguestfs.
1257 AC_ARG_ENABLE([libguestfs-tests],
1258     [AS_HELP_STRING([--disable-libguestfs-tests],
1259                     [disable tests which need libguestfs])],
1260     [],
1261     [enable_libguestfs_tests=check]
1263 AM_CONDITIONAL([USE_LIBGUESTFS_FOR_TESTS],
1264                [test "x$LIBGUESTFS_LIBS" != "x" && \
1265                 test "x$enable_libguestfs_tests" != "xno"])
1267 dnl Check for ext2fs and com_err, for the ext2 filter.
1268 AC_ARG_WITH([ext2],
1269     [AS_HELP_STRING([--without-ext2],
1270                     [disable ext2 filter @<:@default=check@:>@])],
1271     [],
1272     [with_ext2=check])
1273 AS_IF([test "$with_ext2" != "no"], [
1274     PKG_CHECK_MODULES([EXT2FS], [ext2fs], [
1275         AC_SUBST([EXT2FS_CFLAGS])
1276         AC_SUBST([EXT2FS_LIBS])
1277         AC_DEFINE([HAVE_EXT2FS],[1],[ext2fs found at compile time.])
1278     ],
1279     [AC_MSG_WARN([ext2fs not found, ext2 filter will be disabled])])
1280     PKG_CHECK_MODULES([COM_ERR], [com_err], [
1281         AC_SUBST([COM_ERR_CFLAGS])
1282         AC_SUBST([COM_ERR_LIBS])
1283         AC_DEFINE([HAVE_COM_ERR],[1],[com_err found at compile time.])
1284     ],
1285     [AC_MSG_WARN([com_err not found, ext2 filter will be disabled])])
1287     AC_CHECK_MEMBERS([struct struct_io_manager.cache_readahead,
1288                       struct struct_io_manager.zeroout])
1290 AM_CONDITIONAL([HAVE_EXT2],
1291                [test "x$EXT2FS_LIBS" != "x" && test "x$COM_ERR_LIBS" != "x"])
1293 dnl libtorrent-rasterbar for the bittorrent plugin.
1294 AC_ARG_ENABLE([torrent],
1295     [AS_HELP_STRING([--disable-torrent],
1296                     [disable bittorrent plugin])],
1297     [],
1298     [enable_torrent=check]
1300 AS_IF([test "x$enable_torrent" != "xno"], [
1301     PKG_CHECK_MODULES([LIBTORRENT], [libtorrent-rasterbar], [
1302         AC_SUBST([LIBTORRENT_CFLAGS])
1303         AC_SUBST([LIBTORRENT_LIBS])
1304     ],
1305     [AC_MSG_WARN([libtorrent-rasterbar not found, bittorrent plugin will be disabled])])
1307 AM_CONDITIONAL([HAVE_TORRENT],
1308                [test "x$have_cxx" = "xyes" && test "x$LIBTORRENT_LIBS" != "x"])
1310 dnl Check if the user wants to disable VDDK support.
1311 dnl See plugins/vddk/README.VDDK.
1312 AC_ARG_ENABLE([vddk],
1313     [AS_HELP_STRING([--disable-vddk],
1314                     [disable VMware VDDK plugin])],
1315     [],
1316     [
1317      dnl While VDDK was available on i686 in 5.1.1, we only support
1318      dnl newer versions which are supported only on x86-64.  Don't
1319      dnl compile on other platforms.
1320      AC_MSG_CHECKING([if the host CPU is compatible with VDDK])
1321      AS_IF([test "$host_cpu" = "x86_64" && test "$host_os" = "linux-gnu"],[
1322         AC_MSG_RESULT([yes ($host)])
1323         enable_vddk=yes
1324      ],[
1325         AC_MSG_RESULT([no ($host)])
1326         enable_vddk=no
1327      ])
1328     ])
1329 AM_CONDITIONAL([HAVE_VDDK], [test "x$enable_vddk" = "xyes"])
1331 dnl Expose version information to the public headers
1332 [NBDKIT_]VERSION_MAJOR=NBDKIT_VERSION_MAJOR
1333 [NBDKIT_]VERSION_MINOR=NBDKIT_VERSION_MINOR
1334 [NBDKIT_]VERSION_MICRO=NBDKIT_VERSION_MICRO
1335 AC_SUBST([NBDKIT_VERSION_MAJOR])
1336 AC_SUBST([NBDKIT_VERSION_MINOR])
1337 AC_SUBST([NBDKIT_VERSION_MICRO])
1339 dnl Produce output files.
1340 AC_CONFIG_HEADERS([config.h])
1341 AC_CONFIG_FILES([podwrapper.pl],
1342                 [chmod +x,-w podwrapper.pl])
1343 AC_CONFIG_FILES([common/protocol/generate-protostrings.sh],
1344                 [chmod +x,-w common/protocol/generate-protostrings.sh])
1345 AC_CONFIG_FILES([tests/make-pki.sh],
1346                 [chmod +x,-w tests/make-pki.sh])
1347 AC_CONFIG_FILES([Makefile
1348                  bash-completion/Makefile
1349                  common/allocators/Makefile
1350                  common/bitmap/Makefile
1351                  common/gpt/Makefile
1352                  common/include/Makefile
1353                  common/protocol/Makefile
1354                  common/regions/Makefile
1355                  common/replacements/Makefile
1356                  common/replacements/win32/Makefile
1357                  common/utils/Makefile
1358                  docs/Makefile
1359                  include/Makefile
1360                  include/nbdkit-version.h
1361                  plugins/Makefile
1362                  plugins/cc/Makefile
1363                  plugins/cdi/Makefile
1364                  plugins/curl/Makefile
1365                  plugins/data/Makefile
1366                  plugins/eval/Makefile
1367                  plugins/example1/Makefile
1368                  plugins/example2/Makefile
1369                  plugins/example3/Makefile
1370                  plugins/example4/Makefile
1371                  plugins/file/Makefile
1372                  plugins/floppy/Makefile
1373                  plugins/full/Makefile
1374                  plugins/golang/Makefile
1375                  plugins/guestfs/Makefile
1376                  plugins/info/Makefile
1377                  plugins/iso/Makefile
1378                  plugins/libvirt/Makefile
1379                  plugins/linuxdisk/Makefile
1380                  plugins/lua/Makefile
1381                  plugins/memory/Makefile
1382                  plugins/nbd/Makefile
1383                  plugins/null/Makefile
1384                  plugins/ocaml/Makefile
1385                  plugins/ondemand/Makefile
1386                  plugins/partitioning/Makefile
1387                  plugins/pattern/Makefile
1388                  plugins/perl/Makefile
1389                  plugins/python/Makefile
1390                  plugins/random/Makefile
1391                  plugins/ruby/Makefile
1392                  plugins/rust/Makefile
1393                  plugins/S3/Makefile
1394                  plugins/sh/Makefile
1395                  plugins/ssh/Makefile
1396                  plugins/sparse-random/Makefile
1397                  plugins/split/Makefile
1398                  plugins/tcl/Makefile
1399                  plugins/tmpdisk/Makefile
1400                  plugins/torrent/Makefile
1401                  plugins/vddk/Makefile
1402                  plugins/zero/Makefile
1403                  filters/Makefile
1404                  filters/blocksize/Makefile
1405                  filters/blocksize-policy/Makefile
1406                  filters/cache/Makefile
1407                  filters/cacheextents/Makefile
1408                  filters/checkwrite/Makefile
1409                  filters/cow/Makefile
1410                  filters/ddrescue/Makefile
1411                  filters/delay/Makefile
1412                  filters/error/Makefile
1413                  filters/exitlast/Makefile
1414                  filters/exitwhen/Makefile
1415                  filters/exportname/Makefile
1416                  filters/ext2/Makefile
1417                  filters/extentlist/Makefile
1418                  filters/fua/Makefile
1419                  filters/gzip/Makefile
1420                  filters/ip/Makefile
1421                  filters/limit/Makefile
1422                  filters/log/Makefile
1423                  filters/luks/Makefile
1424                  filters/multi-conn/Makefile
1425                  filters/nocache/Makefile
1426                  filters/noextents/Makefile
1427                  filters/nofilter/Makefile
1428                  filters/noparallel/Makefile
1429                  filters/nozero/Makefile
1430                  filters/offset/Makefile
1431                  filters/partition/Makefile
1432                  filters/pause/Makefile
1433                  filters/protect/Makefile
1434                  filters/rate/Makefile
1435                  filters/readahead/Makefile
1436                  filters/retry/Makefile
1437                  filters/retry-request/Makefile
1438                  filters/scan/Makefile
1439                  filters/stats/Makefile
1440                  filters/swab/Makefile
1441                  filters/tar/Makefile
1442                  filters/tls-fallback/Makefile
1443                  filters/truncate/Makefile
1444                  filters/xz/Makefile
1445                  fuzzing/Makefile
1446                  server/local/nbdkit.pc
1447                  server/Makefile
1448                  server/nbdkit.pc
1449                  tests/functions.sh
1450                  tests/Makefile
1451                  valgrind/Makefile])
1453 AC_OUTPUT
1455 dnl Summary.
1456 echo
1457 echo
1458 echo "----------------------------------------------------------------------"
1459 echo "Thank you for downloading $PACKAGE_STRING"
1460 echo
1461 echo "This is how we have configured the optional components for you today:"
1462 echo
1464 print ()
1466     printf '    %.40s %s\n' \
1467         "$1 ........................................" "$2"
1470 feature ()
1472     feat="$1"
1473     shift
1474     if "$@"; then
1475         print "$feat" "yes"
1476     else
1477         print "$feat" "no"
1478     fi
1481 echo "Optional server features:"
1482 echo
1483 feature "bash-completion"     test "x$HAVE_BASH_COMPLETION_TRUE" = "x"
1484 feature "libfuzzer"           test "x$ENABLE_LIBFUZZER_TRUE" = "x"
1485 feature "linker script"       test "x$USE_LINKER_SCRIPT" = "x"
1486 feature "manual pages"        test "x$HAVE_POD_TRUE" = "x"
1487 feature "SELinux"             test "x$LIBSELINUX_LIBS" != "x"
1488 feature "TLS"                 test "x$GNUTLS_LIBS" != "x"
1490 echo
1491 echo "Optional plugins:"
1492 echo
1493 feature "curl"                test "x$HAVE_CURL_TRUE" = "x"
1494 feature "example4"            test "x$HAVE_PERL_TRUE" = "x"
1495 feature "floppy"              test "x$HAVE_ICONV_TRUE" = "x"
1496 feature "guestfs"             test "x$HAVE_LIBGUESTFS_TRUE" = "x"
1497 feature "iso"                 test "x$HAVE_ISO_TRUE" = "x"
1498 feature "libvirt"             test "x$HAVE_LIBVIRT_TRUE" = "x"
1499 feature "linuxdisk"           test "x$HAVE_MKE2FS_WITH_D_TRUE" = "x"
1500 feature "nbd"                 test "x$HAVE_LIBNBD_TRUE" = "x"
1501 feature "S3"                  test "x$HAVE_PYTHON_TRUE" = "x"
1502 feature "ssh"                 test "x$HAVE_SSH_TRUE" = "x"
1503 feature "torrent"             test "x$HAVE_TORRENT_TRUE" = "x"
1504 feature "vddk"                test "x$HAVE_VDDK_TRUE" = "x"
1506 echo
1507 echo "Languages:"
1508 echo
1509 feature "go"                  test "x$HAVE_GOLANG_TRUE" = "x"
1510 feature "lua"                 test "x$HAVE_LUA_TRUE" = "x"
1511 feature "ocaml"               test "x$HAVE_OCAML_TRUE" = "x"
1512 feature "perl"                test "x$HAVE_PERL_TRUE" = "x"
1513 feature "python"              test "x$HAVE_PYTHON_TRUE" = "x"
1514 feature "ruby"                test "x$HAVE_RUBY_TRUE" = "x"
1515 feature "rust"                test "x$HAVE_RUST_TRUE" = "x"
1516 feature "tcl"                 test "x$HAVE_TCL_TRUE" = "x"
1518 echo
1519 echo "Optional filters:"
1520 echo
1521 feature "ext2"                test "x$HAVE_EXT2_TRUE" = "x"
1522 feature "gzip"                test "x$HAVE_ZLIB_TRUE" = "x"
1523 feature "luks"                test "x$HAVE_GNUTLS_PBKDF2_TRUE" = "x"
1524 feature "stats"               test "x$HAVE_CXX_TRUE" = "x"
1525 feature "xz"                  test "x$HAVE_LIBLZMA_TRUE" = "x"
1527 echo
1528 echo "Other optional features:"
1529 echo
1530 feature "allocator=zstd"      test "x$HAVE_LIBZSTD_TRUE" = "x"
1531 feature "tests using libguestfs" \
1532                               test "x$HAVE_LIBGUESTFS_TRUE" = "x" -a \
1533                                    "x$USE_LIBGUESTFS_FOR_TESTS_TRUE" = "x"
1535 echo
1536 echo "If any optional component is configured ‘no’ when you expected ‘yes’"
1537 echo "then you should check the preceding messages and README."
1538 echo
1539 echo "Please report bugs back to the mailing list:"
1540 echo "http://www.redhat.com/mailman/listinfo/libguestfs"
1541 echo
1542 echo "Next you should type 'make' to build the package,"
1543 echo "then 'make check' to run the tests."