rust: prevent dead_code warning
[nbdkit.git] / configure.ac
blobdc9ff94fa5e072551002cd3eeb8283f5856e1b55
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     LIBS="$old_LIBS"
651     dnl macOS has its own program called certtool and packages the
652     dnl GnuTLS tool as "gnutls-certtool".
653     AC_CHECK_PROGS([CERTTOOL],[gnutls-certtool certtool],[certtool])
655 AM_CONDITIONAL([HAVE_GNUTLS_PBKDF2],
656     [test "x$GNUTLS_LIBS" != "x" && test "x$ac_cv_func_gnutls_pbkdf2" = xyes])
658 dnl Check for some commands used by the tests which should be the GNU
659 dnl coreutils variants.  On macOS these are prefixed with 'g' or 'gnu'.
660 AC_CHECK_PROGS([CUT],[gnucut cut],[cut])
661 AC_CHECK_PROGS([STAT],[gstat stat],[stat])
662 AC_CHECK_PROGS([TRUNCATE],[gtruncate truncate],[truncate])
664 AC_ARG_ENABLE([linuxdisk],
665     [AS_HELP_STRING([--disable-linuxdisk],
666                     [disable linuxdisk plugin @<:@default=check@:>@])],
667     [],
668     [enable_linuxdisk=check])
669 dnl Check for mke2fs -d (used by linuxdisk plugin).  There are two
670 dnl possible outcomes that we care about: (1) We have mke2fs and
671 dnl it supports the -d option.  (2) We either don't have mke2fs
672 dnl or it's too old to support the -d option (eg. on RHEL 7).
673 mke2fs_with_d=no
674 AS_IF([test "$enable_linuxdisk" != "no"], [
675     AC_MSG_CHECKING([for mke2fs supporting the -d option])
676     AS_IF([mke2fs -V >/dev/null 2>&1], [
677         AS_IF([LANG=C mke2fs -d 2>&1 | grep -sq "option requires an argument"], [
678             mke2fs_with_d=yes
679         ])
680     ])
681     AC_MSG_RESULT([$mke2fs_with_d])
683 AM_CONDITIONAL([HAVE_MKE2FS_WITH_D],[test "x$mke2fs_with_d" = "xyes"])
685 dnl Check for valgrind.
686 AC_CHECK_PROG([VALGRIND],[valgrind],[valgrind],[no])
688 dnl If valgrind headers are available (optional).
689 dnl Although the runtime check adds only a trivial amount of code, you can
690 dnl avoid it with explicit --disable-valgrind.
691 AC_ARG_ENABLE([valgrind],
692     [AS_HELP_STRING([--disable-valgrind],
693                     [disable Valgrind probe])],
694     [],
695     [enable_valgrind=check])
696 AS_IF([test "x$enable_valgrind" != "xno"],[
697     PKG_CHECK_MODULES([VALGRIND], [valgrind], [
698         AC_SUBST([VALGRIND_CFLAGS])
699         AC_SUBST([VALGRIND_LIBS])
700         AC_DEFINE([HAVE_VALGRIND],[1],[Valgrind headers found at compile time])
701     ],[
702         AS_IF([test "x$enable_valgrind" = "xyes"], [
703             AC_MSG_ERROR([--enable-valgrind given, but Valgrind headers are not available])
704         ])
705     ])
708 dnl Build the special libFuzzer version of nbdkit.  DO NOT USE THIS for
709 dnl normal builds.  See fuzzing/README.
710 AC_ARG_ENABLE([libfuzzer],
711     [AS_HELP_STRING([--enable-libfuzzer],
712                     [build libFuzzer test binary (developers only)])],
713     [],
714     [enable_libfuzzer=no])
715 AS_IF([test "x$enable_libfuzzer" = "xyes"],[
716     AC_DEFINE([ENABLE_LIBFUZZER],[1],[Enable special libFuzzer binary])
717     # We have to disable the linker script for libFuzzer because Clang
718     # adds loads of fuzzer and ASAN-related symbols that are required
719     # by the plugins but which our linker script tries to hide.
720     use_linker_script=no
722 AM_CONDITIONAL([ENABLE_LIBFUZZER],[test "x$enable_libfuzzer" = "xyes"])
724 dnl Should we use the linker script (ld --version-script)?  Note
725 dnl some tests above may set this variable.
726 AC_ARG_ENABLE([linker-script],
727     [AS_HELP_STRING([--disable-linker-script],
728                     [disable linker script for server (developers only)])],
729     [use_linker_script=$enableval],
730     [])
731 AM_CONDITIONAL([USE_LINKER_SCRIPT],
732                [test "x$use_linker_script" = "xyes"])
734 dnl Bash completion.
735 PKG_CHECK_MODULES([BASH_COMPLETION], [bash-completion >= 2.0], [
736     bash_completion=yes
737     AC_MSG_CHECKING([for bash-completions directory])
738     m4_ifdef([PKG_CHECK_VAR],[
739         PKG_CHECK_VAR(bashcompdir, [bash-completion], [completionsdir])
740     ])
741     AS_IF([test -z "$bashcompdir"], [
742         bashcompdir="${sysconfdir}/bash_completion.d"
743     ])
744     AC_MSG_RESULT([$bashcompdir])
745     AC_SUBST([bashcompdir])
747     bash_completion=no
748     AC_MSG_WARN([bash-completion not installed])
750 AM_CONDITIONAL([HAVE_BASH_COMPLETION],[test "x$bash_completion" = "xyes"])
752 dnl Check we have enough to run podwrapper.
753 AC_CHECK_PROG([PERL],[perl],[perl],[no])
754 AS_IF([test "x$PERL" != "xno"],[
755     AC_MSG_CHECKING([if we have perl Pod::Man and Pod::Simple])
756     AS_IF([$PERL -MPod::Man -MPod::Simple -e 1 >&AS_MESSAGE_LOG_FD 2>&1],[
757         enable_pod=yes
758     ],[
759         enable_pod=no
760     ])
761     AC_MSG_RESULT([$enable_pod])
763 AM_CONDITIONAL([HAVE_POD],
764                [test "x$PERL" != "xno" && test "x$enable_pod" = "xyes"])
766 dnl Define the path to the podwrapper program.
767 PODWRAPPER="$PERL $(pwd)/podwrapper.pl"
768 AC_SUBST([PODWRAPPER])
770 dnl Allow all plugins and filters to be disabled.
771 AC_ARG_ENABLE([plugins],
772     [AS_HELP_STRING([--disable-plugins],
773                     [disable all bundled plugins and filters])])
774 AM_CONDITIONAL([HAVE_PLUGINS], [test "x$enable_plugins" != "xno"])
776 dnl Check for Perl, for embedding in the perl plugin.
777 dnl Note that the perl binary is checked above.
778 AC_ARG_ENABLE([perl],
779     [AS_HELP_STRING([--disable-perl], [disable Perl embed plugin])],
780     [],
781     [enable_perl=yes])
782 AS_IF([test "x$PERL" != "xno" && test "x$enable_perl" != "xno"],[
783     dnl Check for Perl archlib.
784     AC_MSG_CHECKING([for Perl embed archlib])
785     PERL_ARCHLIB="$($PERL -MConfig -e 'print $Config{archlib}')"
786     AS_IF([ test -n "$PERL_ARCHLIB" ],[
787         AC_MSG_RESULT([$PERL_ARCHLIB])
788     ],[
789         AC_MSG_NOTICE([Perl embed module disabled])
790         enable_perl=no
791     ])
793     dnl Check for Perl CFLAGS.
794     AC_MSG_CHECKING([for Perl embed CFLAGS])
795     PERL_CFLAGS="$($PERL -MExtUtils::Embed -e 'ccflags')"
796     AS_IF([ test -n "$PERL_CFLAGS" ],[
797         AC_MSG_RESULT([$PERL_CFLAGS])
798     ],[
799         AC_MSG_NOTICE([Perl embed module disabled])
800         enable_perl=no
801     ])
803     dnl Check for Perl LDOPTS.
804     AC_MSG_CHECKING([for Perl embed LDOPTS])
805     PERL_LDOPTS="$($PERL -MExtUtils::Embed -e 'ldopts')"
806     AC_MSG_RESULT([$PERL_LDOPTS])
808     dnl XXX Could check these actually work.
810 AM_CONDITIONAL([HAVE_PERL],[test "x$enable_perl" != "xno" && test "x$PERL" != "xno"])
811 AC_SUBST([PERL_ARCHLIB])
812 AC_SUBST([PERL_CFLAGS])
813 AC_SUBST([PERL_LDOPTS])
815 dnl Check for Python 3, for embedding in the python plugin.
816 AC_PATH_PROGS([PYTHON],[python3 python],[no])
817 AC_ARG_ENABLE([python],
818     [AS_HELP_STRING([--disable-python], [disable Python embed plugin])],
819     [],
820     [enable_python=yes])
821 AS_IF([test "x$PYTHON" != "xno" && test "x$enable_python" != "xno"],[
822     AC_MSG_CHECKING([version of $PYTHON])
823     PYTHON_VERSION_MAJOR=`$PYTHON -c "import sys; print (sys.version_info@<:@0@:>@)"`
824     PYTHON_VERSION_MINOR=`$PYTHON -c "import sys; print (sys.version_info@<:@1@:>@)"`
825     PYTHON_VERSION="$PYTHON_VERSION_MAJOR.$PYTHON_VERSION_MINOR"
826     AS_IF([test -n "$PYTHON_VERSION"],[
827         AC_MSG_RESULT([$PYTHON_VERSION])
828     ],[
829         AC_MSG_NOTICE([Python embed module disabled])
830         enable_python=no
831     ])
833     AC_MSG_CHECKING([Python major version is 3])
834     AS_IF([test "x$PYTHON_VERSION_MAJOR" = "x3"],[
835         AC_MSG_RESULT([yes])
836     ],[
837         AC_MSG_RESULT([no])
838         AC_MSG_ERROR([Python $PYTHON_VERSION_MAJOR <> 3 is no longer supported.
840 Python 2 end of life is 2020-01-01 and nbdkit >= 1.16 no longer
841 supports it.
843 If you want to use Python 2, you will need to use nbdkit 1.14.])
844     ])
846     dnl Check for Python CFLAGS, libraries.
847     dnl For Python >= 3.8 we have to use python-<VERSION>-embed.pc, see:
848     dnl https://docs.python.org/3.8/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build
849     dnl The python.pc is called python-<VERSION>.pc on Debian and
850     dnl later versions of Fedora, and python.pc on older versions
851     dnl of Fedora.
852     PKG_CHECK_MODULES([PYTHON], [python-"$PYTHON_VERSION"-embed], [
853         AC_SUBST([PYTHON_CFLAGS])
854         AC_SUBST([PYTHON_LIBS])
855         AC_SUBST([PYTHON_VERSION])
856         AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time])
857     ],[
858     PKG_CHECK_MODULES([PYTHON], [python-"$PYTHON_VERSION"], [
859         AC_SUBST([PYTHON_CFLAGS])
860         AC_SUBST([PYTHON_LIBS])
861         AC_SUBST([PYTHON_VERSION])
862         AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time])
863     ],[
864     PKG_CHECK_MODULES([PYTHON], [python], [
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         AC_MSG_WARN([python $PYTHON_VERSION not found])
871         enable_python=no
872     ])])])
874 AM_CONDITIONAL([HAVE_PYTHON],[test "x$enable_python" != "xno" && test "x$PYTHON" != "xno"])
875 AC_SUBST([PYTHON_CFLAGS])
876 AC_SUBST([PYTHON_LIBS])
877 AC_SUBST([PYTHON_LDFLAGS])
879 dnl For the OCaml plugin, you can set OCAMLOPTFLAGS before running
880 dnl ./configure to specify any extra flags you want to pass to
881 dnl ocamlopt.  For example to enable OCaml warnings:
882 dnl OCAMLOPTFLAGS="-warn-error +A-3"
883 AC_SUBST([OCAMLOPTFLAGS])
885 dnl Check for OCaml, for embedding in the ocaml plugin.
886 AC_PROG_OCAML
887 AC_ARG_ENABLE([ocaml],
888     [AS_HELP_STRING([--disable-ocaml], [disable OCaml embed plugin])],
889     [],
890     [enable_ocaml=yes])
891 AS_IF([test "x$OCAMLOPT" != "xno" && test "x$enable_ocaml" != "xno"],[
892     dnl Check OCaml can create a shared library (see README for details).
893     AC_MSG_CHECKING([if $OCAMLOPT can create a shared library])
894     echo 'print_endline "test"' > conftest.ml
895     AS_IF([$OCAMLOPT $OCAMLOPTFLAGS -output-obj -runtime-variant _pic -o conftest.so conftest.ml >&AS_MESSAGE_LOG_FD 2>&1],[
896         AC_MSG_RESULT([yes])
897         ocaml_link_shared=yes
898     ],[
899         AC_MSG_RESULT([no])
900     ])
901     rm -f conftest.ml conftest.cmi conftest.cmx conftest.so conftest.o
903 AM_CONDITIONAL([HAVE_OCAML],[test "x$OCAMLOPT" != "xno" &&
904                              test "x$ocaml_link_shared" = "xyes"])
905 AM_CONDITIONAL([HAVE_OCAMLDOC],[test "x$OCAMLDOC" != "xno"])
907 dnl Check if OCaml has caml_alloc_initialized_string (added 2017).
908 AS_IF([test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno" && \
909        test "x$enable_ocaml" = "xyes"],[
910     AC_MSG_CHECKING([for caml_alloc_initialized_string])
911     cat >conftest.c <<'EOF'
912 #include <caml/alloc.h>
913 int main () { char *p = (void *) caml_alloc_initialized_string; return 0; }
915     AS_IF([$OCAMLC conftest.c >&AS_MESSAGE_LOG_FD 2>&1],[
916         AC_MSG_RESULT([yes])
917         AC_DEFINE([HAVE_CAML_ALLOC_INITIALIZED_STRING],[1],
918                   [caml_alloc_initialized_string found at compile time.])
919     ],[
920         AC_MSG_RESULT([no])
921     ])
922     rm -f conftest.c conftest.o
925 dnl Check if OCaml has caml_shutdown (added 2014).
926 AS_IF([test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno" && \
927        test "x$enable_ocaml" = "xyes"],[
928     AC_MSG_CHECKING([for caml_shutdown])
929     cat >conftest.c <<'EOF'
930 #include <caml/callback.h>
931 int main () { char *p = (void *) caml_shutdown; return 0; }
933     AS_IF([$OCAMLC conftest.c >&AS_MESSAGE_LOG_FD 2>&1],[
934         AC_MSG_RESULT([yes])
935         AC_DEFINE([HAVE_CAML_SHUTDOWN],[1],
936                   [caml_shutdown found at compile time.])
937     ],[
938         AC_MSG_RESULT([no])
939     ])
940     rm -f conftest.c conftest.o
943 dnl For developing plugins in Rust, optional.
944 AC_CHECK_PROG([CARGO],[cargo],[cargo],[no])
945 AC_ARG_ENABLE([rust],
946     [AS_HELP_STRING([--disable-rust], [disable Rust plugin])],
947     [],
948     [enable_rust=yes])
949 AM_CONDITIONAL([HAVE_RUST],
950                [test "x$CARGO" != "xno" && test "x$enable_rust" != "xno"])
952 dnl Check for Ruby, for embedding in the Ruby plugin.
953 AC_CHECK_PROG([RUBY],[ruby],[ruby],[no])
954 AC_ARG_ENABLE([ruby],
955     [AS_HELP_STRING([--disable-ruby], [disable Ruby plugin])],
956     [],
957     [enable_ruby=yes])
958 AS_IF([test "x$RUBY" != "xno" && test "x$enable_ruby" != "xno"],[
959     PKG_CHECK_MODULES([RUBY], [ruby], [
960         AC_SUBST([RUBY_CFLAGS])
961         AC_SUBST([RUBY_LIBS])
962     ],[
963         AC_MSG_WARN([ruby not found])
964         enable_ruby=no
965     ])
967 AM_CONDITIONAL([HAVE_RUBY],[test "x$RUBY" != "xno" &&
968                             test "x$enable_ruby" = "xyes"])
970 dnl Check for Tcl, for embedding in the Tcl plugin.
971 AC_ARG_ENABLE([tcl],
972     [AS_HELP_STRING([--disable-tcl], [disable Tcl plugin])],
973     [],
974     [enable_tcl=yes])
975 AS_IF([test "x$enable_tcl" != "xno"],[
976     PKG_CHECK_MODULES([TCL], [tcl], [
977         AC_SUBST([TCL_CFLAGS])
978         AC_SUBST([TCL_LIBS])
979     ],[
980         AC_MSG_WARN([Tcl not found])
981         enable_tcl=no
982     ])
984 AM_CONDITIONAL([HAVE_TCL],[test "x$enable_tcl" = "xyes"])
986 dnl Check for Lua, for embedding in the Lua plugin.
987 AC_ARG_ENABLE([lua],
988     [AS_HELP_STRING([--disable-lua], [disable Lua plugin])],
989     [],
990     [enable_lua=yes])
991 AS_IF([test "x$enable_lua" != "xno"],[
992     PKG_CHECK_MODULES([LUA], [lua], [
993         AC_SUBST([LUA_CFLAGS])
994         AC_SUBST([LUA_LIBS])
996         dnl Lua 5.1 used by RHEL 7 does not have lua_isinteger.
997         old_LIBS="$LIBS"
998         LIBS="$LUA_LIBS $LIBS"
999         AC_CHECK_FUNCS([lua_isinteger])
1000         LIBS="$old_LIBS"
1001     ],[
1002         AC_MSG_WARN([Lua not found])
1003         enable_lua=no
1004     ])
1006 AM_CONDITIONAL([HAVE_LUA],[test "x$enable_lua" = "xyes"])
1008 dnl Check for golang.
1009 AC_ARG_ENABLE([golang],
1010     AS_HELP_STRING([--disable-golang], [disable Go language plugin]),
1011         [],
1012         [enable_golang=yes])
1013 AS_IF([test "x$enable_golang" != "xno"],[
1014     AC_CHECK_PROG([GOLANG],[go],[go],[no])
1015     AS_IF([test "x$GOLANG" != "xno"],[
1016         AC_MSG_CHECKING([if $GOLANG is usable])
1017         AS_IF([$GOLANG run $srcdir/plugins/golang/config-test.go 2>&AS_MESSAGE_LOG_FD && \
1018                $GOLANG help modules 2>&AS_MESSAGE_LOG_FD 1>&2],[
1019             AC_MSG_RESULT([yes])
1021             # Substitute some golang environment.
1022             GOOS=`$GOLANG env GOOS`
1023             GOARCH=`$GOLANG env GOARCH`
1024             GOROOT=`$GOLANG env GOROOT`
1025             AC_SUBST([GOOS])
1026             AC_SUBST([GOARCH])
1027             AC_SUBST([GOROOT])
1028         ],[
1029             AC_MSG_RESULT([no])
1030             AC_MSG_WARN([golang ($GOLANG) is installed but not usable])
1031             GOLANG=no
1032         ])
1033     ])
1034 ],[GOLANG=no])
1035 AM_CONDITIONAL([HAVE_GOLANG],[test "x$GOLANG" != "xno"])
1037 dnl Check for curl (only if you want to compile the curl plugin).
1038 AC_ARG_WITH([curl],
1039     [AS_HELP_STRING([--without-curl],
1040                     [disable curl plugin @<:@default=check@:>@])],
1041     [],
1042     [with_curl=check])
1043 AS_IF([test "$with_curl" != "no"],[
1044     PKG_CHECK_MODULES([CURL], [libcurl],[
1045         printf "libcurl version is "; $PKG_CONFIG --modversion libcurl
1046         AC_SUBST([CURL_CFLAGS])
1047         AC_SUBST([CURL_LIBS])
1048         AC_DEFINE([HAVE_CURL],[1],[curl found at compile time.])
1049         AC_CHECK_DECL([CURLOPT_UNIX_SOCKET_PATH], [
1050             AC_DEFINE([HAVE_CURLOPT_UNIX_SOCKET_PATH],[1],
1051                       [CURLOPT_UNIX_SOCKET_PATH found at compile time.])
1052             ], [], [#include <curl/curl.h>])
1053     ],
1054     [AC_MSG_WARN([curl not found, curl plugin will be disabled])])
1056 AM_CONDITIONAL([HAVE_CURL],[test "x$CURL_LIBS" != "x"])
1058 dnl Check for libssh (only if you want to compile the ssh plugin).
1059 AC_ARG_WITH([ssh],
1060     [AS_HELP_STRING([--without-ssh],
1061                     [disable ssh plugin @<:@default=check@:>@])],
1062     [],
1063     [with_ssh=check])
1064 AS_IF([test "$with_ssh" != "no"],[
1065     PKG_CHECK_MODULES([SSH], [libssh >= 0.8.0],[
1066         printf "libssh version is "; $PKG_CONFIG --modversion libssh
1067         # Ubuntu 18.04 shipped prerelease of libssh-0.8.0 without
1068         # SSH_OPTIONS_NODELAY
1069         old_CFLAGS="$CFLAGS"
1070         CFLAGS="$CFLAGS $SSH_CFLAGS"
1071         AC_CHECK_DECL([SSH_OPTIONS_NODELAY], [
1072             AC_SUBST([SSH_CFLAGS])
1073             AC_SUBST([SSH_LIBS])
1074             # We don't need this in the code, just in this configure
1075             HAVE_SSH_OPTIONS_NODELAY=1
1076             ], [], [
1077             #include <libssh/libssh.h>
1078         ])
1079         CFLAGS="$old_CFLAGS"
1080     ],
1081     [AC_MSG_WARN([libssh not found, ssh plugin will be disabled])])
1083 AM_CONDITIONAL([HAVE_SSH],[test "x$HAVE_SSH_OPTIONS_NODELAY" != "x"])
1085 dnl Check for xorriso or genisoimage or mkisofs
1086 dnl (only if you want to compile the iso plugin).
1087 ISOPROG="no"
1088 is_xorriso=0
1089 AC_ARG_WITH([iso],
1090     [AS_HELP_STRING([--without-iso],
1091                     [disable iso plugin @<:@default=check@:>@])],
1092     [],
1093     [with_iso=check])
1094 AS_IF([test "$with_iso" != "no"],[
1095     AC_CHECK_PROG([XORRISO],[xorriso],[xorriso],[no])
1096     AC_CHECK_PROG([GENISOIMAGE],[genisoimage],[genisoimage],[no])
1097     AC_CHECK_PROG([MKISOFS],[mkisofs],[mkisofs],[no])
1098     AS_IF([test "x$XORRISO" != "xno"],[
1099         ISOPROG="$XORRISO"
1100         is_xorriso=1
1101     ],[
1102         AS_IF([test "x$GENISOIMAGE" != "xno"],[
1103             ISOPROG="$GENISOIMAGE"
1104         ],[
1105             AS_IF([test "x$MKISOFS" != "xno"],[
1106                 ISOPROG="$MKISOFS"
1107             ])
1108         ])
1109     ])
1110     AS_IF([test "x$ISOPROG" != "xno"],[
1111         printf "picked %s for nbdkit-iso-plugin\n" "$ISOPROG"
1112         AC_DEFINE_UNQUOTED([ISOPROG],["$ISOPROG"],
1113                            [Program used by iso plugin to make ISOs.])
1114         AS_IF([test "x$is_xorriso" = "x1"], [
1115             AC_DEFINE([ISOPROG_IS_XORRISO],[1],
1116                       [ISO program behaves like xorriso.])
1117         ])
1118     ])
1120 AC_SUBST([ISOPROG])
1121 AM_CONDITIONAL([HAVE_ISO],[test "x$ISOPROG" != "xno"])
1123 dnl Check for libvirt (only if you want to compile the libvirt plugin).
1124 AC_ARG_WITH([libvirt],
1125     [AS_HELP_STRING([--without-libvirt],
1126                     [disable libvirt plugin @<:@default=check@:>@])],
1127     [],
1128     [with_libvirt=check])
1129 AS_IF([test "$with_libvirt" != "no"],[
1130     PKG_CHECK_MODULES([LIBVIRT], [libvirt],[
1131         AC_SUBST([LIBVIRT_CFLAGS])
1132         AC_SUBST([LIBVIRT_LIBS])
1133         AC_DEFINE([HAVE_LIBVIRT],[1],[libvirt found at compile time.])
1134     ],
1135     [AC_MSG_WARN([libvirt not found, libvirt plugin will be disabled])])
1137 AM_CONDITIONAL([HAVE_LIBVIRT],[test "x$LIBVIRT_LIBS" != "x"])
1139 dnl Check for zlib (only if you want to compile the gzip filter).
1140 AC_ARG_WITH([zlib],
1141     [AS_HELP_STRING([--without-zlib],
1142                     [disable gzip filter @<:@default=check@:>@])],
1143     [],
1144     [with_zlib=check])
1145 AS_IF([test "$with_zlib" != "no"],[
1146     PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2.3.5],[
1147         AC_SUBST([ZLIB_CFLAGS])
1148         AC_SUBST([ZLIB_LIBS])
1149         AC_DEFINE([HAVE_ZLIB],[1],[zlib found at compile time.])
1150     ],
1151     [AC_MSG_WARN([zlib >= 1.2.3.5 not found, gzip filter will be disabled])])
1153 AM_CONDITIONAL([HAVE_ZLIB],[test "x$ZLIB_LIBS" != "x"])
1155 dnl Check for libnbd (only if you want to compile the nbd plugin).
1156 AC_ARG_WITH([libnbd],
1157     [AS_HELP_STRING([--without-libnbd],
1158                     [disable nbd plugin @<:@default=check@:>@])],
1159     [],
1160     [with_libnbd=check])
1161 AS_IF([test "$with_libnbd" != "no"],[
1162     PKG_CHECK_MODULES([LIBNBD], [libnbd >= 0.9.8],[
1163         printf "libnbd version is "; $PKG_CONFIG --modversion libnbd
1164         AC_SUBST([LIBNBD_CFLAGS])
1165         AC_SUBST([LIBNBD_LIBS])
1166         AC_DEFINE([HAVE_LIBNBD],[1],[libnbd found at compile time.])
1167     ],
1168     [AC_MSG_WARN([libnbd >= 0.9.8 not found, nbd plugin will be crippled])])
1171 dnl For backwards compatibilty, we have a second way to disable the nbd plugin.
1172 AC_ARG_ENABLE([nbd-plugin],
1173     [AS_HELP_STRING([--disable-nbd-plugin], [disable nbd plugin (deprecated, use --without-libnbd)])],
1174     [],
1175     [enable_nbd_plugin=yes])
1176 AM_CONDITIONAL([HAVE_LIBNBD],
1177   [test "x$LIBNBD_LIBS" != "x" && test "x$enable_nbd_plugin" = "xyes"])
1179 dnl Check for liblzma (only if you want to compile the xz filter).
1180 AC_ARG_WITH([liblzma],
1181     [AS_HELP_STRING([--without-liblzma],
1182                     [disable xz filter @<:@default=check@:>@])],
1183     [],
1184     [with_liblzma=check])
1185 AS_IF([test "$with_liblzma" != "no"],[
1186     PKG_CHECK_MODULES([LIBLZMA], [liblzma],[
1187         AC_SUBST([LIBLZMA_CFLAGS])
1188         AC_SUBST([LIBLZMA_LIBS])
1189         AC_DEFINE([HAVE_LIBLZMA],[1],[liblzma found at compile time.])
1190     ],
1191     [AC_MSG_WARN([liblzma not found, xz filter will be disabled])])
1193 AM_CONDITIONAL([HAVE_LIBLZMA],[test "x$LIBLZMA_LIBS" != "x"])
1195 dnl Check for zstd (only if you want to compile allocator=zstd).
1196 AC_ARG_WITH([libzstd],
1197     [AS_HELP_STRING([--without-libzstd],
1198                     [disable allocator=zstd @<:@default=check@:>@])],
1199     [],
1200     [with_libzstd=check])
1201 AS_IF([test "$with_libzstd" != "no"],[
1202     PKG_CHECK_MODULES([LIBZSTD], [libzstd],[
1203         AC_SUBST([LIBZSTD_CFLAGS])
1204         AC_SUBST([LIBZSTD_LIBS])
1205         AC_DEFINE([HAVE_LIBZSTD],[1],[libzstd found at compile time.])
1206     ],
1207     [AC_MSG_WARN([libzstd not found, allocator=zstd will be disabled])])
1209 AM_CONDITIONAL([HAVE_LIBZSTD],[test "x$LIBZSTD_LIBS" != "x"])
1211 dnl Check for libguestfs (only for the guestfs plugin and parts of
1212 dnl the test suite).
1213 AC_ARG_WITH([libguestfs],
1214     [AS_HELP_STRING([--without-libguestfs],
1215                     [disable guestfs plugin and tests @<:@default=check@:>@])],
1216     [],
1217     [with_libguestfs=check])
1218 AS_IF([test "$with_libguestfs" != "no"],[
1219     PKG_CHECK_MODULES([LIBGUESTFS], [libguestfs],[
1220         # Although the library was found, we want to make sure it supports nbd
1221         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1222 #include <guestfs.h>
1223         ]], [[
1224 #ifndef GUESTFS_ADD_DRIVE_OPTS_PROTOCOL
1225 #error unsupported
1226 #endif
1227         ]])], [
1228         AC_SUBST([LIBGUESTFS_CFLAGS])
1229         AC_SUBST([LIBGUESTFS_LIBS])
1230         AC_DEFINE([HAVE_LIBGUESTFS],[1],[libguestfs found at compile time.])
1231         ],[
1232         LIBGUESTFS_LIBS=
1233         AC_MSG_WARN([libguestfs too old, guestfs plugin and tests will be disabled])])
1234     ],
1235     [AC_MSG_WARN([libguestfs not found, guestfs plugin and tests will be disabled])])
1237 AM_CONDITIONAL([HAVE_LIBGUESTFS],[test "x$LIBGUESTFS_LIBS" != "x"])
1239 dnl Disable tests which need libguestfs.
1240 AC_ARG_ENABLE([libguestfs-tests],
1241     [AS_HELP_STRING([--disable-libguestfs-tests],
1242                     [disable tests which need libguestfs])],
1243     [],
1244     [enable_libguestfs_tests=check]
1246 AM_CONDITIONAL([USE_LIBGUESTFS_FOR_TESTS],
1247                [test "x$LIBGUESTFS_LIBS" != "x" && \
1248                 test "x$enable_libguestfs_tests" != "xno"])
1250 dnl Check for ext2fs and com_err, for the ext2 filter.
1251 AC_ARG_WITH([ext2],
1252     [AS_HELP_STRING([--without-ext2],
1253                     [disable ext2 filter @<:@default=check@:>@])],
1254     [],
1255     [with_ext2=check])
1256 AS_IF([test "$with_ext2" != "no"], [
1257     PKG_CHECK_MODULES([EXT2FS], [ext2fs], [
1258         AC_SUBST([EXT2FS_CFLAGS])
1259         AC_SUBST([EXT2FS_LIBS])
1260         AC_DEFINE([HAVE_EXT2FS],[1],[ext2fs found at compile time.])
1261     ],
1262     [AC_MSG_WARN([ext2fs not found, ext2 filter will be disabled])])
1263     PKG_CHECK_MODULES([COM_ERR], [com_err], [
1264         AC_SUBST([COM_ERR_CFLAGS])
1265         AC_SUBST([COM_ERR_LIBS])
1266         AC_DEFINE([HAVE_COM_ERR],[1],[com_err found at compile time.])
1267     ],
1268     [AC_MSG_WARN([com_err not found, ext2 filter will be disabled])])
1270     AC_CHECK_MEMBERS([struct struct_io_manager.cache_readahead,
1271                       struct struct_io_manager.zeroout])
1273 AM_CONDITIONAL([HAVE_EXT2],
1274                [test "x$EXT2FS_LIBS" != "x" && test "x$COM_ERR_LIBS" != "x"])
1276 dnl libtorrent-rasterbar for the bittorrent plugin.
1277 AC_ARG_ENABLE([torrent],
1278     [AS_HELP_STRING([--disable-torrent],
1279                     [disable bittorrent plugin])],
1280     [],
1281     [enable_torrent=check]
1283 AS_IF([test "x$enable_torrent" != "xno"], [
1284     PKG_CHECK_MODULES([LIBTORRENT], [libtorrent-rasterbar], [
1285         AC_SUBST([LIBTORRENT_CFLAGS])
1286         AC_SUBST([LIBTORRENT_LIBS])
1287     ],
1288     [AC_MSG_WARN([libtorrent-rasterbar not found, bittorrent plugin will be disabled])])
1290 AM_CONDITIONAL([HAVE_TORRENT],
1291                [test "x$have_cxx" = "xyes" && test "x$LIBTORRENT_LIBS" != "x"])
1293 dnl Check if the user wants to disable VDDK support.
1294 dnl See plugins/vddk/README.VDDK.
1295 AC_ARG_ENABLE([vddk],
1296     [AS_HELP_STRING([--disable-vddk],
1297                     [disable VMware VDDK plugin])],
1298     [],
1299     [
1300      dnl While VDDK was available on i686 in 5.1.1, we only support
1301      dnl newer versions which are supported only on x86-64.  Don't
1302      dnl compile on other platforms.
1303      AC_MSG_CHECKING([if the host CPU is compatible with VDDK])
1304      AS_IF([test "$host_cpu" = "x86_64"],[
1305         AC_MSG_RESULT([yes ($host_cpu)])
1306         enable_vddk=yes
1307      ],[
1308         AC_MSG_RESULT([no ($host_cpu)])
1309         enable_vddk=no
1310      ])
1311     ])
1312 AM_CONDITIONAL([HAVE_VDDK], [test "x$enable_vddk" = "xyes"])
1314 dnl Expose version information to the public headers
1315 [NBDKIT_]VERSION_MAJOR=NBDKIT_VERSION_MAJOR
1316 [NBDKIT_]VERSION_MINOR=NBDKIT_VERSION_MINOR
1317 [NBDKIT_]VERSION_MICRO=NBDKIT_VERSION_MICRO
1318 AC_SUBST([NBDKIT_VERSION_MAJOR])
1319 AC_SUBST([NBDKIT_VERSION_MINOR])
1320 AC_SUBST([NBDKIT_VERSION_MICRO])
1322 dnl Produce output files.
1323 AC_CONFIG_HEADERS([config.h])
1324 AC_CONFIG_FILES([podwrapper.pl],
1325                 [chmod +x,-w podwrapper.pl])
1326 AC_CONFIG_FILES([common/protocol/generate-protostrings.sh],
1327                 [chmod +x,-w common/protocol/generate-protostrings.sh])
1328 AC_CONFIG_FILES([tests/make-pki.sh],
1329                 [chmod +x,-w tests/make-pki.sh])
1330 AC_CONFIG_FILES([Makefile
1331                  bash-completion/Makefile
1332                  common/allocators/Makefile
1333                  common/bitmap/Makefile
1334                  common/gpt/Makefile
1335                  common/include/Makefile
1336                  common/protocol/Makefile
1337                  common/regions/Makefile
1338                  common/replacements/Makefile
1339                  common/replacements/win32/Makefile
1340                  common/utils/Makefile
1341                  docs/Makefile
1342                  include/Makefile
1343                  include/nbdkit-version.h
1344                  plugins/Makefile
1345                  plugins/cc/Makefile
1346                  plugins/cdi/Makefile
1347                  plugins/curl/Makefile
1348                  plugins/data/Makefile
1349                  plugins/eval/Makefile
1350                  plugins/example1/Makefile
1351                  plugins/example2/Makefile
1352                  plugins/example3/Makefile
1353                  plugins/example4/Makefile
1354                  plugins/file/Makefile
1355                  plugins/floppy/Makefile
1356                  plugins/full/Makefile
1357                  plugins/golang/Makefile
1358                  plugins/guestfs/Makefile
1359                  plugins/info/Makefile
1360                  plugins/iso/Makefile
1361                  plugins/libvirt/Makefile
1362                  plugins/linuxdisk/Makefile
1363                  plugins/lua/Makefile
1364                  plugins/memory/Makefile
1365                  plugins/nbd/Makefile
1366                  plugins/null/Makefile
1367                  plugins/ocaml/Makefile
1368                  plugins/ondemand/Makefile
1369                  plugins/partitioning/Makefile
1370                  plugins/pattern/Makefile
1371                  plugins/perl/Makefile
1372                  plugins/python/Makefile
1373                  plugins/random/Makefile
1374                  plugins/ruby/Makefile
1375                  plugins/rust/Makefile
1376                  plugins/S3/Makefile
1377                  plugins/sh/Makefile
1378                  plugins/ssh/Makefile
1379                  plugins/sparse-random/Makefile
1380                  plugins/split/Makefile
1381                  plugins/tcl/Makefile
1382                  plugins/tmpdisk/Makefile
1383                  plugins/torrent/Makefile
1384                  plugins/vddk/Makefile
1385                  plugins/zero/Makefile
1386                  filters/Makefile
1387                  filters/blocksize/Makefile
1388                  filters/blocksize-policy/Makefile
1389                  filters/cache/Makefile
1390                  filters/cacheextents/Makefile
1391                  filters/checkwrite/Makefile
1392                  filters/cow/Makefile
1393                  filters/ddrescue/Makefile
1394                  filters/delay/Makefile
1395                  filters/error/Makefile
1396                  filters/exitlast/Makefile
1397                  filters/exitwhen/Makefile
1398                  filters/exportname/Makefile
1399                  filters/ext2/Makefile
1400                  filters/extentlist/Makefile
1401                  filters/fua/Makefile
1402                  filters/gzip/Makefile
1403                  filters/ip/Makefile
1404                  filters/limit/Makefile
1405                  filters/log/Makefile
1406                  filters/luks/Makefile
1407                  filters/multi-conn/Makefile
1408                  filters/nocache/Makefile
1409                  filters/noextents/Makefile
1410                  filters/nofilter/Makefile
1411                  filters/noparallel/Makefile
1412                  filters/nozero/Makefile
1413                  filters/offset/Makefile
1414                  filters/partition/Makefile
1415                  filters/pause/Makefile
1416                  filters/protect/Makefile
1417                  filters/rate/Makefile
1418                  filters/readahead/Makefile
1419                  filters/retry/Makefile
1420                  filters/retry-request/Makefile
1421                  filters/scan/Makefile
1422                  filters/stats/Makefile
1423                  filters/swab/Makefile
1424                  filters/tar/Makefile
1425                  filters/tls-fallback/Makefile
1426                  filters/truncate/Makefile
1427                  filters/xz/Makefile
1428                  fuzzing/Makefile
1429                  server/local/nbdkit.pc
1430                  server/Makefile
1431                  server/nbdkit.pc
1432                  tests/functions.sh
1433                  tests/Makefile
1434                  valgrind/Makefile])
1436 AC_OUTPUT
1438 dnl Summary.
1439 echo
1440 echo
1441 echo "----------------------------------------------------------------------"
1442 echo "Thank you for downloading $PACKAGE_STRING"
1443 echo
1444 echo "This is how we have configured the optional components for you today:"
1445 echo
1447 print ()
1449     printf '    %.40s %s\n' \
1450         "$1 ........................................" "$2"
1453 feature ()
1455     feat="$1"
1456     shift
1457     if "$@"; then
1458         print "$feat" "yes"
1459     else
1460         print "$feat" "no"
1461     fi
1464 echo "Optional server features:"
1465 echo
1466 feature "bash-completion"     test "x$HAVE_BASH_COMPLETION_TRUE" = "x"
1467 feature "libfuzzer"           test "x$ENABLE_LIBFUZZER_TRUE" = "x"
1468 feature "linker script"       test "x$USE_LINKER_SCRIPT" = "x"
1469 feature "manual pages"        test "x$HAVE_POD_TRUE" = "x"
1470 feature "SELinux"             test "x$LIBSELINUX_LIBS" != "x"
1471 feature "TLS"                 test "x$GNUTLS_LIBS" != "x"
1473 echo
1474 echo "Optional plugins:"
1475 echo
1476 feature "curl"                test "x$HAVE_CURL_TRUE" = "x"
1477 feature "example4"            test "x$HAVE_PERL_TRUE" = "x"
1478 feature "floppy"              test "x$HAVE_ICONV_TRUE" = "x"
1479 feature "guestfs"             test "x$HAVE_LIBGUESTFS_TRUE" = "x"
1480 feature "iso"                 test "x$HAVE_ISO_TRUE" = "x"
1481 feature "libvirt"             test "x$HAVE_LIBVIRT_TRUE" = "x"
1482 feature "linuxdisk"           test "x$HAVE_MKE2FS_WITH_D_TRUE" = "x"
1483 feature "nbd"                 test "x$HAVE_LIBNBD_TRUE" = "x"
1484 feature "S3"                  test "x$HAVE_PYTHON_TRUE" = "x"
1485 feature "ssh"                 test "x$HAVE_SSH_TRUE" = "x"
1486 feature "torrent"             test "x$HAVE_TORRENT_TRUE" = "x"
1487 feature "vddk"                test "x$HAVE_VDDK_TRUE" = "x"
1489 echo
1490 echo "Languages:"
1491 echo
1492 feature "go"                  test "x$HAVE_GOLANG_TRUE" = "x"
1493 feature "lua"                 test "x$HAVE_LUA_TRUE" = "x"
1494 feature "ocaml"               test "x$HAVE_OCAML_TRUE" = "x"
1495 feature "perl"                test "x$HAVE_PERL_TRUE" = "x"
1496 feature "python"              test "x$HAVE_PYTHON_TRUE" = "x"
1497 feature "ruby"                test "x$HAVE_RUBY_TRUE" = "x"
1498 feature "rust"                test "x$HAVE_RUST_TRUE" = "x"
1499 feature "tcl"                 test "x$HAVE_TCL_TRUE" = "x"
1501 echo
1502 echo "Optional filters:"
1503 echo
1504 feature "ext2"                test "x$HAVE_EXT2_TRUE" = "x"
1505 feature "gzip"                test "x$HAVE_ZLIB_TRUE" = "x"
1506 feature "luks"                test "x$HAVE_GNUTLS_PBKDF2_TRUE" = "x"
1507 feature "stats"               test "x$HAVE_CXX_TRUE" = "x"
1508 feature "xz"                  test "x$HAVE_LIBLZMA_TRUE" = "x"
1510 echo
1511 echo "Other optional features:"
1512 echo
1513 feature "allocator=zstd"      test "x$HAVE_LIBZSTD_TRUE" = "x"
1514 feature "tests using libguestfs" \
1515                               test "x$HAVE_LIBGUESTFS_TRUE" = "x" -a \
1516                                    "x$USE_LIBGUESTFS_FOR_TESTS_TRUE" = "x"
1518 echo
1519 echo "If any optional component is configured ‘no’ when you expected ‘yes’"
1520 echo "then you should check the preceding messages and README."
1521 echo
1522 echo "Please report bugs back to the mailing list:"
1523 echo "http://www.redhat.com/mailman/listinfo/libguestfs"
1524 echo
1525 echo "Next you should type 'make' to build the package,"
1526 echo "then 'make check' to run the tests."