Version 1.33.6.
[nbdkit.git] / configure.ac
blobb087ec5162688b3fc3fadf776048aa50b220a4d1
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], [6])
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         blkio \
78         cdi \
79         curl \
80         data \
81         eval \
82         example1 \
83         example2 \
84         example3 \
85         example4 \
86         file \
87         floppy \
88         full \
89         guestfs \
90         info \
91         iso \
92         libvirt \
93         linuxdisk \
94         memory \
95         nbd \
96         null \
97         ondemand \
98         partitioning \
99         pattern \
100         random \
101         S3 \
102         sparse-random \
103         split \
104         ssh \
105         tmpdisk \
106         torrent \
107         vddk \
108         zero \
109         "
110 plugins="$(echo $(printf %s\\n $lang_plugins $non_lang_plugins | sort -u))"
111 filters="\
112         blocksize \
113         blocksize-policy \
114         cache \
115         cacheextents \
116         checkwrite \
117         cow \
118         ddrescue \
119         delay \
120         error \
121         exitlast \
122         exitwhen \
123         exportname \
124         ext2 \
125         extentlist \
126         fua \
127         gzip \
128         ip \
129         limit \
130         log \
131         luks \
132         multi-conn \
133         nocache \
134         noextents \
135         nofilter \
136         noparallel \
137         nozero \
138         offset \
139         partition \
140         pause \
141         protect \
142         rate \
143         readahead \
144         retry \
145         retry-request \
146         scan \
147         stats \
148         swab \
149         tar \
150         tls-fallback \
151         truncate \
152         xz \
153         "
154 AC_SUBST([plugins])
155 AC_SUBST([lang_plugins])
156 AC_SUBST([non_lang_plugins])
157 AC_SUBST([filters])
159 dnl Some very basic tools.
160 AC_PROG_SED
161 AC_PROG_RANLIB
163 dnl Check for basic C environment.
164 AC_PROG_CC
165 AC_PROG_INSTALL
166 AC_PROG_CPP
167 AC_SYS_LARGEFILE
169 AC_C_PROTOTYPES
170 test "x$U" != "x" && AC_MSG_ERROR([Compiler not ANSI compliant])
172 AM_PROG_CC_C_O
174 dnl Define the host CPU architecture (defines 'host_cpu').
175 AC_CANONICAL_HOST
176 AC_DEFINE_UNQUOTED([host_cpu],["$host_cpu"],[Host architecture.])
178 dnl Define 'host_os'.
179 AC_DEFINE_UNQUOTED([host_os],["$host_os"],[Host operating system.])
181 dnl Defines WORDS_BIGENDIAN on big endian platforms.
182 AC_C_BIGENDIAN
184 dnl These are defined in <unistd.h> which is included by
185 dnl AC_DEFAULT_INCLUDES.
186 AC_CHECK_SIZEOF([pid_t])
187 AC_CHECK_SIZEOF([uid_t])
188 AC_CHECK_SIZEOF([gid_t])
190 dnl Check for C++ (optional, we just use this to test the header
191 dnl can be included from C++ code).
192 AC_PROG_CXX
194 dnl The C++ compiler test is pretty useless because even if it fails
195 dnl it sets CXX=g++.  So test the compiler actually works.
196 AC_MSG_CHECKING([if the C++ compiler really really works])
197 AS_IF([$CXX --version >&AS_MESSAGE_LOG_FD 2>&1],[have_cxx=yes],[have_cxx=no])
198 AC_MSG_RESULT([$have_cxx])
199 AM_CONDITIONAL([HAVE_CXX], [test "$have_cxx" = "yes"])
201 AC_ARG_ENABLE([gcc-warnings],
202     [AS_HELP_STRING([--enable-gcc-warnings],
203                     [turn on lots of GCC warnings (for developers)])],
204      [case $enableval in
205       yes|no) ;;
206       *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
207       esac
208       gcc_warnings=$enableval],
209       [gcc_warnings=no]
211 if test "x$gcc_warnings" = "xyes"; then
212     WARNINGS_CFLAGS="-Wall -Wshadow -Wvla -Werror"
213     AC_SUBST([WARNINGS_CFLAGS])
216 dnl Check if the compiler supports -std=c90 flag.  This is only used
217 dnl during a test.  OpenBSD GCC does not support this flag so we skip
218 dnl that test.
219 AC_MSG_CHECKING([if the compiler supports -std=c90 for ANSI C test])
220 old_CFLAGS="$CFLAGS"
221 CFLAGS="$CFLAGS -std=c90"
222 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
223     [supports_std_c90=yes],
224     [supports_std_c90=no])
225 CFLAGS="$old_CFLAGS"
226 AC_MSG_RESULT([$supports_std_c90])
227 AM_CONDITIONAL([CAN_TEST_ANSI_C], [test "x$supports_std_c90" = "xyes"])
229 dnl Check for __builtin_*_overflow.  We need the dummy parameters
230 dnl else detection doesn't work correctly for some reason.
231 AC_CHECK_DECLS([__builtin_add_overflow(int, int, int *),
232                 __builtin_mul_overflow(int, int, int *)],
233                 [], [], [])
235 dnl On Haiku we must use BSD-compatibility headers to get the endian
236 dnl macros we use.
237 AC_MSG_CHECKING(whether OS-dependent include paths are required)
238 AS_CASE([$host_os],
239   [haiku*], [CFLAGS="$CFLAGS -I`findpaths -p /system B_FIND_PATH_HEADERS_DIRECTORY`/bsd"; AC_MSG_RESULT(yes)],
240   [AC_MSG_RESULT(no)]
243 dnl On Linux /tmp is often tmpfs which is not large enough, so use /var/tmp.
244 dnl But Haiku only has /tmp.
245 AC_MSG_CHECKING([for temporary directory for large files])
246 AS_CASE([$host_os],
247   [haiku*], [LARGE_TMPDIR=/tmp],
248   [LARGE_TMPDIR=/var/tmp]
250 AC_MSG_RESULT([$LARGE_TMPDIR])
251 AC_DEFINE_UNQUOTED([LARGE_TMPDIR],["$LARGE_TMPDIR"],
252                    [Temporary directory for large files])
254 dnl Check if libc has program_invocation_short_name.
255 AC_CHECK_DECLS([program_invocation_short_name], [], [], [#include <errno.h>])
257 AX_PTHREAD
259 dnl Check if __attribute__((cleanup(...))) works.
260 dnl Set -Werror, otherwise gcc will only emit a warning for attributes
261 dnl that it doesn't understand.
262 acx_nbdkit_save_CFLAGS="${CFLAGS}"
263 CFLAGS="${CFLAGS} -Werror"
264 AC_MSG_CHECKING([if __attribute__((cleanup(...))) works with this compiler])
265 AC_COMPILE_IFELSE([
266 AC_LANG_SOURCE([[
267 #include <stdio.h>
268 #include <stdlib.h>
270 void
271 freep (void *ptr)
273   exit (EXIT_SUCCESS);
276 void
277 test (void)
279   __attribute__((cleanup(freep))) char *ptr = malloc (100);
280   (void)ptr;
284 main (int argc, char *argv[])
286   test ();
287   exit (EXIT_FAILURE);
290     ],[
291     AC_MSG_RESULT([yes])
292     ],[
293     AC_MSG_RESULT([no])
294     AC_MSG_ERROR(
295 ['__attribute__((cleanup(...)))' does not work.
297 You may not be using a sufficiently recent version of GCC or CLANG, or
298 you may be using a C compiler which does not support this attribute,
299 or the configure test may be wrong.
301 This code requires the attribute to work for proper locking between threads.])])
302 CFLAGS="${acx_nbdkit_save_CFLAGS}"
304 dnl Check for __auto_type (GCC extension).
305 AC_MSG_CHECKING([if __auto_type is available in this compiler])
306 AC_COMPILE_IFELSE([
307 AC_LANG_SOURCE([[
308 static int
309 test (int a)
311   __auto_type at = a;
312   return at;
315     ],[
316     AC_MSG_RESULT([yes])
317     AC_DEFINE([HAVE_AUTO_TYPE],[1],[__auto_type is available])
318     ],[
319     AC_MSG_RESULT([no])
320     ]
323 dnl 'environ' is not always declared in public header files:
324 dnl Linux => <unistd.h>  Haiku => <stdlib.h>
325 dnl FreeBSD & OpenBSD => not declared
326 dnl On platforms where it's not declared we must add an extern decl.
327 AC_MSG_CHECKING([if environ is declared in header files])
328 AC_COMPILE_IFELSE([
329 AC_LANG_SOURCE([[
330 #include <stdlib.h>
331 #include <unistd.h>
332 static int
333 test (void)
335   const char **env = environ;
336   return env ? 1 : 0; // this just forces env to be used
339     ],[
340     AC_MSG_RESULT([yes])
341     AC_DEFINE([HAVE_ENVIRON_DECL],[1],[environ is declared in headers])
342     ],[
343     AC_MSG_RESULT([no])
344     ]
347 dnl Check for other headers, all optional.
348 AC_CHECK_HEADERS([\
349         alloca.h \
350         afunix.h \
351         arpa/inet.h \
352         byteswap.h \
353         endian.h \
354         grp.h \
355         linux/fs.h \
356         netdb.h \
357         netinet/in.h \
358         netinet/tcp.h \
359         pwd.h \
360         termios.h \
361         stdatomic.h \
362         syslog.h \
363         sys/endian.h \
364         sys/ioctl.h \
365         sys/mman.h \
366         sys/prctl.h \
367         sys/procctl.h \
368         sys/socket.h \
369         sys/statvfs.h \
370         sys/ucred.h \
371         sys/un.h \
372         sys/vsock.h \
373         sys/wait.h \
374         winsock2.h])
376 AC_CHECK_HEADERS([linux/vm_sockets.h], [], [], [#include <sys/socket.h>])
378 dnl Check for functions in libc, all optional.
379 AC_CHECK_FUNCS([\
380         accept4 \
381         fdatasync \
382         flockfile \
383         funlockfile \
384         inet_ntop \
385         inet_pton \
386         mkostemp \
387         mlock \
388         mlockall \
389         munlock \
390         open_memstream \
391         pipe \
392         pipe2 \
393         ppoll \
394         posix_fadvise \
395         posix_memalign \
396         valloc])
398 dnl Check for structs and members.
399 AC_CHECK_MEMBERS([struct dirent.d_type], [], [], [[#include <dirent.h>]])
400 AC_CHECK_MEMBERS([struct ucred.uid], [], [],
401                  [[
402 #ifdef HAVE_SYS_SOCKET_H
403 #include <sys/socket.h>
404 #endif
405 #ifdef HAVE_SYS_UCRED_H
406 #include <sys/ucred.h>
407 #endif
409 AC_CHECK_MEMBERS([struct sockpeercred.uid], [], [],
410                  [[
411 #ifdef HAVE_SYS_SOCKET_H
412 #include <sys/socket.h>
413 #endif
416 dnl Replacement functions that we provide for some platforms.
417 AC_CONFIG_LIBOBJ_DIR([common/replacements])
418 AC_REPLACE_FUNCS([\
419         fdatasync \
420         fsync \
421         get_current_dir_name \
422         getdelim \
423         getline \
424         openlog \
425         open_memstream \
426         poll \
427         posix_memalign \
428         pread \
429         pwrite \
430         realpath \
431         strndup \
432         sysconf \
433         syslog \
434         vsyslog])
436 dnl Check whether printf("%m") works
437 AC_CACHE_CHECK([whether the printf family supports %m],
438   [nbdkit_cv_func_printf_percent_m],
439   [AC_RUN_IFELSE(
440     [AC_LANG_PROGRAM([[
441 #include <stdio.h>
442 #include <string.h>
443 #include <errno.h>
444     ]], [[
445     char buf[200] = "";
446     errno = EINVAL;
447     snprintf(buf, sizeof buf, "%m");
448     return !!strcmp (buf, strerror (EINVAL));
449     ]])],
450     [nbdkit_cv_func_printf_percent_m=yes],
451     [nbdkit_cv_func_printf_percent_m=no],
452     [[
453     case "$host_os" in
454       *-gnu* | gnu*) nbdkit_cv_func_printf_percent_m=yes;;
455       *) nbdkit_cv_func_printf_percent_m="guessing no";;
456     esac
457     ]])])
458 AS_IF([test "x$nbdkit_cv_func_printf_percent_m" = xyes],
459   [AC_DEFINE([HAVE_VFPRINTF_PERCENT_M],[1],
460     [Define to 1 if vfprintf supports %m.])])
462 old_LIBS="$LIBS"
463 AC_SEARCH_LIBS([dlsym], [dl dld], [
464         AS_IF([test "x$ac_cv_search_dlsym" != "xnone required"],
465             [DL_LIBS="$ac_cv_search_dlsym"], [DL_LIBS=])
466         AC_SUBST([DL_LIBS])
467     ], [AC_MSG_ERROR([unable to find the dlsym() function])
469 LIBS="$old_LIBS"
471 dnl Test if <iconv.h> header can build working binaries.
473 dnl On FreeBSD: iconv and libiconv both exist, both can be installed
474 dnl simultaneously, <iconv.h> can exist in two separate places, and
475 dnl if you get the wrong header/library mix everything breaks.
477 dnl On Haiku: libiconv is required to link to iconv_* functions.
478 AC_ARG_WITH([iconv],
479     [AS_HELP_STRING([--without-iconv],
480                     [don't try to link against iconv @<:@default=check@:>@])],
481     [],
482     [with_iconv=check])
483 AS_IF([test "x$with_iconv" != "xno"],[
484     AC_CHECK_HEADER([iconv.h],[
485         AC_MSG_CHECKING([if <iconv.h> can be used to link a program])
486         AC_LINK_IFELSE([
487 AC_LANG_SOURCE([[
488 #include <stdio.h>
489 #include <stdlib.h>
490 #include <iconv.h>
492 main (int argc, char *argv[])
494   iconv_t ic = iconv_open ("", "");
495   iconv_close (ic);
496   exit (0);
499             ],[
500             AC_MSG_RESULT([yes])
501             iconv_working=yes
502             ],[
503             AC_MSG_RESULT([no])
504             ])
505         ])
506     ])
507 AM_CONDITIONAL([HAVE_ICONV], [test "x$iconv_working" = "xyes"])
509 use_linker_script=yes
511 dnl Don't use linker script on FreeBSD because FreeBSD's linker is
512 dnl broken.  See eg:
513 dnl https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=190851
514 dnl Also on macOS (darwin) which fails with:
515 dnl ld: unknown option: --version-script=./nbdkit.syms
516 dnl clang: error: linker command failed with exit code 1
517 AC_MSG_CHECKING([if we should disable the linker script (FreeBSD, macOS)])
518 AS_CASE([$host_os],
519   [freebsd*|darwin*], [
520       use_linker_script=no
521       AC_MSG_RESULT([yes])
522   ],
523   [AC_MSG_RESULT([no])]
526 dnl Check if -rdynamic linker flag works.
527 acx_nbdkit_save_LDFLAGS="${LDFLAGS}"
528 LDFLAGS="${LDFLAGS} -rdynamic"
529 AC_MSG_CHECKING([if linker supports -rdynamic])
530 AC_LINK_IFELSE([
531 AC_LANG_SOURCE([[
532 #include <stdlib.h>
534 main (int argc, char *argv[])
536   exit (EXIT_SUCCESS);
539     ],[
540     AC_MSG_RESULT([yes])
541     DL_LDFLAGS=-rdynamic
542     ],[
543     AC_MSG_RESULT([no])
545 dnl restore CFLAGS
546 LDFLAGS="${acx_nbdkit_save_LDFLAGS}"
547 AC_SUBST([DL_LDFLAGS])
549 dnl Check for dladdr in -ldl, optional.  This is a glibc extension.
550 old_LIBS="$LIBS"
551 LIBS="$DL_LIBS $LIBS"
552 AC_CHECK_FUNCS([dladdr])
553 LIBS="$old_LIBS"
555 dnl Is this Windows?
556 AC_MSG_CHECKING([if the target is Windows])
557 AS_CASE([$host_os],
558     [mingw*|msys*], [
559         is_windows=yes
560         LIBS="$LIBS -lmsvcrt -lkernel32 -luser32 -lws2_32"
561         NO_UNDEFINED_ON_WINDOWS="-no-undefined"
562         IMPORT_LIBRARY_ON_WINDOWS='-Wl,-L$(top_builddir)/server -Wl,-lnbdkit'
563         SOEXT="dll"
564         DIR_SEPARATOR_STR='\\'
565     ],
566     [is_windows=no
567      SOEXT="so"
568      DIR_SEPARATOR_STR=/]
570 AC_MSG_RESULT([$is_windows])
571 AC_SUBST([NO_UNDEFINED_ON_WINDOWS])
572 AC_SUBST([IMPORT_LIBRARY_ON_WINDOWS])
573 AC_SUBST([SOEXT])
574 AC_DEFINE_UNQUOTED([SOEXT],["$SOEXT"],[Extension used for shared objects/DLLs.])
575 AC_DEFINE_UNQUOTED([EXEEXT],["$EXEEXT"],[Extension used for executables.])
576 AC_DEFINE_UNQUOTED([DIR_SEPARATOR_STR],["$DIR_SEPARATOR_STR"],
577                    [String that separates path elements.])
578 AM_CONDITIONAL([IS_WINDOWS],[test "x$is_windows" = "xyes"])
580 AS_IF([test "x$is_windows" = "xyes"],[
581     dnl For Windows, look for the mc/windmc utility.
582     dnl XXX Do we need to check for mc.exe as well?
583     AC_CHECK_TOOLS([MC],[windmc mc],[no])
584     AS_IF([test "x$MC" = "xno"],
585           [AC_MSG_ERROR([mc/windmc utility must be available when compiling for Windows])])
587     dnl On Windows look for dlltool.
588     AC_CHECK_TOOLS([DLLTOOL],[dlltool],[no])
589     AS_IF([test "x$DLLTOOL" = "xno"],
590           [AC_MSG_ERROR([dlltool utility must be available when compiling for Windows])])
593 AC_SEARCH_LIBS([getaddrinfo], [network socket])
595 dnl Does this platform require libc_malloc_debug.so.0 (glibc >= 2.34)?
596 AC_MSG_CHECKING([if this is glibc >= 2.34])
597 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
598 #include <limits.h>
599 #if !defined(__GLIBC__) || __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 34)
600 #error "not glibc 2.34"
601 #endif
602         ]])], [is_glibc_234=yes], [is_glibc_234=no]
604 AC_MSG_RESULT([$is_glibc_234])
605 AM_CONDITIONAL([HAVE_GLIBC_234], [test "x$is_glibc_234" = "xyes"])
607 dnl Check for SELinux socket labelling (optional).
608 AC_ARG_WITH([selinux],
609     AS_HELP_STRING([--without-selinux], [disable SELinux support, used for socket labelling @<:@default=check@:>@]))
610 AS_IF([test "x$with_selinux" != xno], [
611     PKG_CHECK_MODULES([LIBSELINUX], [libselinux], [
612         AC_SUBST([LIBSELINUX_CFLAGS])
613         AC_SUBST([LIBSELINUX_LIBS])
614         AC_DEFINE([HAVE_LIBSELINUX],[1],[libselinux found at compile time.])
615     ], [AC_MSG_WARN([libselinux not found, sockets will not be labeled.])])
618 AS_IF([test "x$with_selinux" = xyes && test "x$LIBSELINUX_LIBS" = x], [
619     AC_MSG_ERROR([selinux requested but not found])
622 dnl Check for GnuTLS (optional, for TLS support).
623 AC_ARG_WITH([gnutls],
624     [AS_HELP_STRING([--without-gnutls], [disable TLS support via GnuTLS @<:@default=check@:>@])],
625     [],
626     [: m4_divert_text([DEFAULTS], [with_manpages=check])])
628 AS_IF([test "x$with_gnutls" != xno], [
629     PKG_CHECK_MODULES([GNUTLS], [gnutls >= 3.3.0], [
630         AC_SUBST([GNUTLS_CFLAGS])
631         AC_SUBST([GNUTLS_LIBS])
632         AC_DEFINE([HAVE_GNUTLS],[1],[gnutls found at compile time.])
633     ], [
634         AC_MSG_WARN([gnutls not found or < 3.3.0, TLS support will be disabled.])
635     ])
638 AS_IF([test "x$with_gnutls" = xyes && test x"$GNUTLS_LIBS" = x], [
639     AC_MSG_ERROR([gnutls requested but not found])
642 AM_CONDITIONAL([HAVE_GNUTLS], [test "x$GNUTLS_LIBS" != "x"])
644 AS_IF([test "x$GNUTLS_LIBS" != "x"],[
645     AC_MSG_CHECKING([for default TLS session priority string])
646     AC_ARG_WITH([tls-priority],
647         [AS_HELP_STRING([--with-tls-priority=...],
648                         [default TLS session priority string @<:@default=NORMAL@:>@])],
649         [tls_priority=$withval],
650         [tls_priority=NORMAL])
651     AC_MSG_RESULT([$tls_priority])
652     AC_DEFINE_UNQUOTED([TLS_PRIORITY],["$tls_priority"],
653                        [Default TLS session priority string])
655     # Check for APIs which may not be present.
656     old_LIBS="$LIBS"
657     LIBS="$GNUTLS_LIBS $LIBS"
658     AC_CHECK_FUNCS([\
659         gnutls_base64_decode2 \
660         gnutls_certificate_set_known_dh_params \
661         gnutls_group_get \
662         gnutls_group_get_name \
663         gnutls_pbkdf2 \
664         gnutls_session_set_verify_cert \
665         gnutls_srp_server_get_username \
666         gnutls_transport_is_ktls_enabled \
667     ])
668     AC_CHECK_HEADERS([gnutls/socket.h])
669     LIBS="$old_LIBS"
671     dnl macOS has its own program called certtool and packages the
672     dnl GnuTLS tool as "gnutls-certtool".
673     AC_CHECK_PROGS([CERTTOOL],[gnutls-certtool certtool],[certtool])
675 AM_CONDITIONAL([HAVE_GNUTLS_PBKDF2],
676     [test "x$GNUTLS_LIBS" != "x" && test "x$ac_cv_func_gnutls_pbkdf2" = xyes])
678 dnl Check for some commands used by the tests which should be the GNU
679 dnl coreutils variants.  On macOS these are prefixed with 'g' or 'gnu'.
680 AC_CHECK_PROGS([CUT],[gnucut cut],[cut])
681 AC_CHECK_PROGS([STAT],[gstat stat],[stat])
682 AC_CHECK_PROGS([TRUNCATE],[gtruncate truncate],[truncate])
684 AC_ARG_ENABLE([linuxdisk],
685     [AS_HELP_STRING([--disable-linuxdisk],
686                     [disable linuxdisk plugin @<:@default=check@:>@])],
687     [],
688     [enable_linuxdisk=check])
689 dnl Check for mke2fs -d (used by linuxdisk plugin).  There are two
690 dnl possible outcomes that we care about: (1) We have mke2fs and
691 dnl it supports the -d option.  (2) We either don't have mke2fs
692 dnl or it's too old to support the -d option (eg. on RHEL 7).
693 mke2fs_with_d=no
694 AS_IF([test "$enable_linuxdisk" != "no"], [
695     AC_MSG_CHECKING([for mke2fs supporting the -d option])
696     AS_IF([mke2fs -V >/dev/null 2>&1], [
697         AS_IF([LANG=C mke2fs -d 2>&1 | grep -sq "option requires an argument"], [
698             mke2fs_with_d=yes
699         ])
700     ])
701     AC_MSG_RESULT([$mke2fs_with_d])
703 AM_CONDITIONAL([HAVE_MKE2FS_WITH_D],[test "x$mke2fs_with_d" = "xyes"])
705 dnl Check for valgrind.
706 AC_CHECK_PROG([VALGRIND],[valgrind],[valgrind],[no])
708 dnl If valgrind headers are available (optional).
709 dnl Although the runtime check adds only a trivial amount of code, you can
710 dnl avoid it with explicit --disable-valgrind.
711 AC_ARG_ENABLE([valgrind],
712     [AS_HELP_STRING([--disable-valgrind],
713                     [disable Valgrind probe])],
714     [],
715     [enable_valgrind=check])
716 AS_IF([test "x$enable_valgrind" != "xno"],[
717     PKG_CHECK_MODULES([VALGRIND], [valgrind], [
718         AC_SUBST([VALGRIND_CFLAGS])
719         AC_SUBST([VALGRIND_LIBS])
720         AC_DEFINE([HAVE_VALGRIND],[1],[Valgrind headers found at compile time])
721     ],[
722         AS_IF([test "x$enable_valgrind" = "xyes"], [
723             AC_MSG_ERROR([--enable-valgrind given, but Valgrind headers are not available])
724         ])
725     ])
728 dnl Build the special libFuzzer version of nbdkit.  DO NOT USE THIS for
729 dnl normal builds.  See fuzzing/README.
730 AC_ARG_ENABLE([libfuzzer],
731     [AS_HELP_STRING([--enable-libfuzzer],
732                     [build libFuzzer test binary (developers only)])],
733     [],
734     [enable_libfuzzer=no])
735 AS_IF([test "x$enable_libfuzzer" = "xyes"],[
736     AC_DEFINE([ENABLE_LIBFUZZER],[1],[Enable special libFuzzer binary])
737     # We have to disable the linker script for libFuzzer because Clang
738     # adds loads of fuzzer and ASAN-related symbols that are required
739     # by the plugins but which our linker script tries to hide.
740     use_linker_script=no
742 AM_CONDITIONAL([ENABLE_LIBFUZZER],[test "x$enable_libfuzzer" = "xyes"])
744 dnl Should we use the linker script (ld --version-script)?  Note
745 dnl some tests above may set this variable.
746 AC_ARG_ENABLE([linker-script],
747     [AS_HELP_STRING([--disable-linker-script],
748                     [disable linker script for server (developers only)])],
749     [use_linker_script=$enableval],
750     [])
751 AM_CONDITIONAL([USE_LINKER_SCRIPT],
752                [test "x$use_linker_script" = "xyes"])
754 dnl Bash completion.
755 AC_ARG_WITH([bash-completions],
756     [AS_HELP_STRING([--without-bash-completions], [disable installing bash completions @<:@default=check@:>@])],
757     [],
758     [: m4_divert_text([DEFAULTS], [with_readline=check])])
760 AS_IF([test "x$with_bash_completions" != xno], [
761     PKG_CHECK_MODULES([BASH_COMPLETION], [bash-completion >= 2.0], [
762         bash_completion=yes
763         AC_MSG_CHECKING([for bash-completions directory])
764         m4_ifdef([PKG_CHECK_VAR],[
765             PKG_CHECK_VAR(bashcompdir, [bash-completion], [completionsdir])
766         ])
767         AS_IF([test -z "$bashcompdir"], [
768             bashcompdir="${sysconfdir}/bash_completion.d"
769         ])
770         AC_MSG_RESULT([$bashcompdir])
771         AC_SUBST([bashcompdir])
772     ],[
773         bash_completion=no
774         AC_MSG_WARN([bash-completion not installed])
775     ])
778 AS_IF([test "x$bash_completion" = xno && test "x$with_bash_completions" = xyes], [
779     AC_MSG_ERROR([bash-completions requested but required packages not found])
782 AM_CONDITIONAL([HAVE_BASH_COMPLETION],[test "x$bash_completion" = "xyes"])
784 dnl Check we have enough to run podwrapper.
786 AC_ARG_WITH([manpages],
787     [AS_HELP_STRING([--without-manpages], [Do not build man pages @<:@default=check@:>@])],
788     [],
789     [: m4_divert_text([DEFAULTS], [with_manpages=check])])
791 enable_pod=no
792 AC_CHECK_PROGS([PERL], [perl], [])
794 AS_IF([test "x$enable_manpages" != xno], [
795     AS_IF([test "x$PERL" != "x"],[
796         AC_MSG_CHECKING([if we have perl Pod::Man and Pod::Simple])
797         AS_IF([$PERL -MPod::Man -MPod::Simple -e 1 >&AS_MESSAGE_LOG_FD 2>&1],[
798             enable_pod=yes
799         ])
800         AC_MSG_RESULT([$enable_pod])
801     ])
804 AS_IF([test "x$enable_pod" = xno && test "x$enable_manpages" = xyes], [
805     AC_MSG_ERROR([man-pages requested but required packages not found])
808 AM_CONDITIONAL([HAVE_POD],
809                [test "x$PERL" != "xno" && test "x$enable_pod" = "xyes"])
811 dnl Define the path to the podwrapper program.
812 PODWRAPPER="$PERL $(pwd)/podwrapper.pl"
813 AC_SUBST([PODWRAPPER])
815 dnl Allow all plugins and filters to be disabled.
816 AC_ARG_ENABLE([plugins],
817     [AS_HELP_STRING([--disable-plugins],
818                     [disable all bundled plugins and filters])])
819 AM_CONDITIONAL([HAVE_PLUGINS], [test "x$enable_plugins" != "xno"])
821 dnl Check for Perl, for embedding in the perl plugin.
822 dnl Note that the perl binary is checked above.
823 AC_ARG_ENABLE([perl],
824     [AS_HELP_STRING([--disable-perl], [disable Perl embed plugin])],
825     [],
826     [enable_perl=yes])
827 AS_IF([test "x$PERL" != "xno" && test "x$enable_perl" != "xno"],[
828     dnl Check for Perl archlib.
829     AC_MSG_CHECKING([for Perl embed archlib])
830     PERL_ARCHLIB="$($PERL -MConfig -e 'print $Config{archlib}')"
831     AS_IF([ test -n "$PERL_ARCHLIB" ],[
832         AC_MSG_RESULT([$PERL_ARCHLIB])
833     ],[
834         AC_MSG_NOTICE([Perl embed module disabled])
835         enable_perl=no
836     ])
838     dnl Check for Perl CFLAGS.
839     AC_MSG_CHECKING([for Perl embed CFLAGS])
840     PERL_CFLAGS="$($PERL -MExtUtils::Embed -e 'ccflags')"
841     AS_IF([ test -n "$PERL_CFLAGS" ],[
842         AC_MSG_RESULT([$PERL_CFLAGS])
843     ],[
844         AC_MSG_NOTICE([Perl embed module disabled])
845         enable_perl=no
846     ])
848     dnl Check for Perl LDOPTS.
849     AC_MSG_CHECKING([for Perl embed LDOPTS])
850     PERL_LDOPTS="$($PERL -MExtUtils::Embed -e 'ldopts')"
851     AC_MSG_RESULT([$PERL_LDOPTS])
853     dnl Check these actually work.
854     AC_MSG_CHECKING([whether Perl modules will compile])
855     old_CFLAGS="$CFLAGS"
856     old_LIBS="$LIBS"
857     CFLAGS="$PERL_CFLAGS -I$PERL_ARCHLIB/CORE $CFLAGS"
858     LIBS="$PERL_LDOPTS $LIBS"
859     AC_CHECK_FUNCS([perl_alloc])
860     CFLAGS="$old_CFLAGS"
861     LIBS="$old_LIBS"
862     if test "x$ac_cv_func_perl_alloc" != xyes; then
863       enable_perl=no
864     fi
866 AM_CONDITIONAL([HAVE_PERL],[test "x$enable_perl" != "xno" && test "x$PERL" != "xno"])
867 AC_SUBST([PERL_ARCHLIB])
868 AC_SUBST([PERL_CFLAGS])
869 AC_SUBST([PERL_LDOPTS])
871 dnl Check for Python 3, for embedding in the python plugin.
872 AC_PATH_PROGS([PYTHON],[python3 python],[no])
873 AC_ARG_ENABLE([python],
874     [AS_HELP_STRING([--disable-python], [disable Python embed plugin])],
875     [],
876     [enable_python=yes])
877 AS_IF([test "x$PYTHON" != "xno" && test "x$enable_python" != "xno"],[
878     AC_MSG_CHECKING([version of $PYTHON])
879     PYTHON_VERSION_MAJOR=`$PYTHON -c "import sys; print (sys.version_info@<:@0@:>@)"`
880     PYTHON_VERSION_MINOR=`$PYTHON -c "import sys; print (sys.version_info@<:@1@:>@)"`
881     PYTHON_VERSION="$PYTHON_VERSION_MAJOR.$PYTHON_VERSION_MINOR"
882     AS_IF([test -n "$PYTHON_VERSION"],[
883         AC_MSG_RESULT([$PYTHON_VERSION])
884     ],[
885         AC_MSG_NOTICE([Python embed module disabled])
886         enable_python=no
887     ])
889     AC_MSG_CHECKING([Python major version is 3])
890     AS_IF([test "x$PYTHON_VERSION_MAJOR" = "x3"],[
891         AC_MSG_RESULT([yes])
892     ],[
893         AC_MSG_RESULT([no])
894         AC_MSG_ERROR([Python $PYTHON_VERSION_MAJOR <> 3 is no longer supported.
896 Python 2 end of life is 2020-01-01 and nbdkit >= 1.16 no longer
897 supports it.
899 If you want to use Python 2, you will need to use nbdkit 1.14.])
900     ])
902     dnl Check for Python CFLAGS, libraries.
903     dnl For Python >= 3.8 we have to use python-<VERSION>-embed.pc, see:
904     dnl https://docs.python.org/3.8/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build
905     dnl The python.pc is called python-<VERSION>.pc on Debian and
906     dnl later versions of Fedora, and python.pc on older versions
907     dnl of Fedora.
908     PKG_CHECK_MODULES([PYTHON], [python-"$PYTHON_VERSION"-embed], [
909         AC_SUBST([PYTHON_CFLAGS])
910         AC_SUBST([PYTHON_LIBS])
911         AC_SUBST([PYTHON_VERSION])
912         AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time])
913     ],[
914     PKG_CHECK_MODULES([PYTHON], [python-"$PYTHON_VERSION"], [
915         AC_SUBST([PYTHON_CFLAGS])
916         AC_SUBST([PYTHON_LIBS])
917         AC_SUBST([PYTHON_VERSION])
918         AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time])
919     ],[
920     PKG_CHECK_MODULES([PYTHON], [python], [
921         AC_SUBST([PYTHON_CFLAGS])
922         AC_SUBST([PYTHON_LIBS])
923         AC_SUBST([PYTHON_VERSION])
924         AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time])
925     ],[
926         AC_MSG_WARN([python $PYTHON_VERSION not found])
927         enable_python=no
928     ])])])
930 AM_CONDITIONAL([HAVE_PYTHON],[test "x$enable_python" != "xno" && test "x$PYTHON" != "xno"])
931 AC_SUBST([PYTHON_CFLAGS])
932 AC_SUBST([PYTHON_LIBS])
933 AC_SUBST([PYTHON_LDFLAGS])
935 dnl For the OCaml plugin, you can set OCAMLOPTFLAGS before running
936 dnl ./configure to specify any extra flags you want to pass to
937 dnl ocamlopt.  For example to enable OCaml warnings:
938 dnl OCAMLOPTFLAGS="-warn-error +A-3"
939 AC_SUBST([OCAMLOPTFLAGS])
941 dnl Check for OCaml, for embedding in the ocaml plugin.
942 AC_PROG_OCAML
943 AC_ARG_ENABLE([ocaml],
944     [AS_HELP_STRING([--disable-ocaml], [disable OCaml embed plugin])],
945     [],
946     [enable_ocaml=yes])
947 AS_IF([test "x$OCAMLOPT" != "xno" && test "x$enable_ocaml" != "xno"],[
948     dnl Check OCaml can create a shared library (see README for details).
949     AC_MSG_CHECKING([if $OCAMLOPT can create a shared library])
950     echo 'print_endline "test"' > conftest.ml
951     AS_IF([$OCAMLOPT $OCAMLOPTFLAGS -output-obj -runtime-variant _pic -o conftest.so conftest.ml >&AS_MESSAGE_LOG_FD 2>&1],[
952         AC_MSG_RESULT([yes])
953         ocaml_link_shared=yes
954     ],[
955         AC_MSG_RESULT([no])
956     ])
957     rm -f conftest.ml conftest.cmi conftest.cmx conftest.so conftest.o
959 AM_CONDITIONAL([HAVE_OCAML],[test "x$OCAMLOPT" != "xno" &&
960                              test "x$ocaml_link_shared" = "xyes"])
961 AM_CONDITIONAL([HAVE_OCAMLDOC],[test "x$OCAMLDOC" != "xno"])
963 dnl Check if OCaml has caml_alloc_initialized_string (added 2017).
964 AS_IF([test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno" && \
965        test "x$enable_ocaml" = "xyes"],[
966     AC_MSG_CHECKING([for caml_alloc_initialized_string])
967     cat >conftest.c <<'EOF'
968 #include <caml/alloc.h>
969 int main () { char *p = (void *) caml_alloc_initialized_string; return 0; }
971     AS_IF([$OCAMLC conftest.c >&AS_MESSAGE_LOG_FD 2>&1],[
972         AC_MSG_RESULT([yes])
973         AC_DEFINE([HAVE_CAML_ALLOC_INITIALIZED_STRING],[1],
974                   [caml_alloc_initialized_string found at compile time.])
975     ],[
976         AC_MSG_RESULT([no])
977     ])
978     rm -f conftest.c conftest.o
981 dnl Check if OCaml has caml_shutdown (added 2014).
982 AS_IF([test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno" && \
983        test "x$enable_ocaml" = "xyes"],[
984     AC_MSG_CHECKING([for caml_shutdown])
985     cat >conftest.c <<'EOF'
986 #include <caml/callback.h>
987 int main () { char *p = (void *) caml_shutdown; return 0; }
989     AS_IF([$OCAMLC conftest.c >&AS_MESSAGE_LOG_FD 2>&1],[
990         AC_MSG_RESULT([yes])
991         AC_DEFINE([HAVE_CAML_SHUTDOWN],[1],
992                   [caml_shutdown found at compile time.])
993     ],[
994         AC_MSG_RESULT([no])
995     ])
996     rm -f conftest.c conftest.o
999 dnl For developing plugins in Rust, optional.
1000 dnl Rust does not play nicely with VPATH builds
1001 AC_CHECK_PROG([CARGO],[cargo],[cargo],[no])
1002 AC_ARG_ENABLE([rust],
1003     [AS_HELP_STRING([--disable-rust], [disable Rust plugin])],
1004     [],
1005     [if test "x$(realpath $srcdir)" = "x$(realpath .)"; then
1006        enable_rust=yes
1007      else
1008        enable_rust=no
1009      fi])
1010 AM_CONDITIONAL([HAVE_RUST],
1011                [test "x$CARGO" != "xno" && test "x$enable_rust" != "xno"])
1013 dnl Check for Ruby, for embedding in the Ruby plugin.
1014 AC_CHECK_PROG([RUBY],[ruby],[ruby],[no])
1015 AC_ARG_ENABLE([ruby],
1016     [AS_HELP_STRING([--disable-ruby], [disable Ruby plugin])],
1017     [],
1018     [enable_ruby=yes])
1019 AS_IF([test "x$RUBY" != "xno" && test "x$enable_ruby" != "xno"],[
1020     PKG_CHECK_MODULES([RUBY], [ruby], [
1021         AC_SUBST([RUBY_CFLAGS])
1022         AC_SUBST([RUBY_LIBS])
1023     ],[
1024         AC_MSG_WARN([ruby not found])
1025         enable_ruby=no
1026     ])
1028 AM_CONDITIONAL([HAVE_RUBY],[test "x$RUBY" != "xno" &&
1029                             test "x$enable_ruby" = "xyes"])
1031 dnl Check for Tcl, for embedding in the Tcl plugin.
1032 AC_ARG_ENABLE([tcl],
1033     [AS_HELP_STRING([--disable-tcl], [disable Tcl plugin])],
1034     [],
1035     [enable_tcl=yes])
1036 AS_IF([test "x$enable_tcl" != "xno"],[
1037     PKG_CHECK_MODULES([TCL], [tcl], [
1038         AC_SUBST([TCL_CFLAGS])
1039         AC_SUBST([TCL_LIBS])
1040     ],[
1041         AC_MSG_WARN([Tcl not found])
1042         enable_tcl=no
1043     ])
1045 AM_CONDITIONAL([HAVE_TCL],[test "x$enable_tcl" = "xyes"])
1047 dnl Check for Lua, for embedding in the Lua plugin.
1048 AC_ARG_ENABLE([lua],
1049     [AS_HELP_STRING([--disable-lua], [disable Lua plugin])],
1050     [],
1051     [enable_lua=yes])
1052 AS_IF([test "x$enable_lua" != "xno"],[
1053     PKG_CHECK_MODULES([LUA], [lua], [
1054         AC_SUBST([LUA_CFLAGS])
1055         AC_SUBST([LUA_LIBS])
1057         dnl Lua 5.1 used by RHEL 7 does not have lua_isinteger.
1058         old_LIBS="$LIBS"
1059         LIBS="$LUA_LIBS $LIBS"
1060         AC_CHECK_FUNCS([lua_isinteger])
1061         LIBS="$old_LIBS"
1062     ],[
1063         AC_MSG_WARN([Lua not found])
1064         enable_lua=no
1065     ])
1067 AM_CONDITIONAL([HAVE_LUA],[test "x$enable_lua" = "xyes"])
1069 dnl Check for golang.
1070 AC_ARG_ENABLE([golang],
1071     AS_HELP_STRING([--disable-golang], [disable Go language plugin]),
1072         [],
1073         [enable_golang=yes])
1074 AS_IF([test "x$enable_golang" != "xno"],[
1075     AC_CHECK_PROG([GOLANG],[go],[go],[no])
1076     AS_IF([test "x$GOLANG" != "xno"],[
1077         AC_MSG_CHECKING([if $GOLANG is usable])
1078         AS_IF([$GOLANG run $srcdir/plugins/golang/config-test.go 2>&AS_MESSAGE_LOG_FD && \
1079                $GOLANG help modules 2>&AS_MESSAGE_LOG_FD 1>&2],[
1080             AC_MSG_RESULT([yes])
1082             # Substitute some golang environment.
1083             GOOS=`$GOLANG env GOOS`
1084             GOARCH=`$GOLANG env GOARCH`
1085             GOROOT=`$GOLANG env GOROOT`
1086             AC_SUBST([GOOS])
1087             AC_SUBST([GOARCH])
1088             AC_SUBST([GOROOT])
1089         ],[
1090             AC_MSG_RESULT([no])
1091             AC_MSG_WARN([golang ($GOLANG) is installed but not usable])
1092             GOLANG=no
1093         ])
1094     ])
1095 ],[GOLANG=no])
1096 AM_CONDITIONAL([HAVE_GOLANG],[test "x$GOLANG" != "xno"])
1098 dnl Check for libblkio (only if you want to compile the blkio plugin).
1099 AC_ARG_WITH([libblkio],
1100     [AS_HELP_STRING([--without-libblkio],
1101                     [disable blkio plugin @<:@default=check@:>@])],
1102     [],
1103     [with_libblkio=check])
1104 AS_IF([test "$with_libblkio" != "no"],[
1105     PKG_CHECK_MODULES([LIBBLKIO], [blkio],[
1106         printf "libblkio version is "; $PKG_CONFIG --modversion blkio
1107         AC_SUBST([LIBBLKIO_CFLAGS])
1108         AC_SUBST([LIBBLKIO_LIBS])
1109         AC_DEFINE([HAVE_LIBBLKIO],[1],[libblkio found at compile time.])
1110     ],
1111     [AC_MSG_WARN([libblkio not found, blkio plugin will be disabled])])
1113 AM_CONDITIONAL([HAVE_LIBBLKIO],[test "x$LIBBLKIO_LIBS" != "x"])
1115 dnl Check for curl (only if you want to compile the curl plugin).
1116 AC_ARG_WITH([curl],
1117     [AS_HELP_STRING([--without-curl],
1118                     [disable curl plugin @<:@default=check@:>@])],
1119     [],
1120     [with_curl=check])
1121 AS_IF([test "$with_curl" != "no"],[
1122     PKG_CHECK_MODULES([CURL], [libcurl],[
1123         printf "libcurl version is "; $PKG_CONFIG --modversion libcurl
1124         AC_SUBST([CURL_CFLAGS])
1125         AC_SUBST([CURL_LIBS])
1126         AC_DEFINE([HAVE_CURL],[1],[curl found at compile time.])
1127         AC_CHECK_DECL([CURLOPT_UNIX_SOCKET_PATH], [
1128             AC_DEFINE([HAVE_CURLOPT_UNIX_SOCKET_PATH],[1],
1129                       [CURLOPT_UNIX_SOCKET_PATH found at compile time.])
1130             ], [], [#include <curl/curl.h>])
1131     ],
1132     [AC_MSG_WARN([curl not found, curl plugin will be disabled])])
1134 AM_CONDITIONAL([HAVE_CURL],[test "x$CURL_LIBS" != "x"])
1136 dnl Check for libssh (only if you want to compile the ssh plugin).
1137 AC_ARG_WITH([ssh],
1138     [AS_HELP_STRING([--without-ssh],
1139                     [disable ssh plugin @<:@default=check@:>@])],
1140     [],
1141     [with_ssh=check])
1142 AS_IF([test "$with_ssh" != "no"],[
1143     PKG_CHECK_MODULES([SSH], [libssh >= 0.8.0],[
1144         printf "libssh version is "; $PKG_CONFIG --modversion libssh
1145         # Ubuntu 18.04 shipped prerelease of libssh-0.8.0 without
1146         # SSH_OPTIONS_NODELAY
1147         old_CFLAGS="$CFLAGS"
1148         CFLAGS="$CFLAGS $SSH_CFLAGS"
1149         AC_CHECK_DECL([SSH_OPTIONS_NODELAY], [
1150             AC_SUBST([SSH_CFLAGS])
1151             AC_SUBST([SSH_LIBS])
1152             # We don't need this in the code, just in this configure
1153             HAVE_SSH_OPTIONS_NODELAY=1
1154             ], [], [
1155             #include <libssh/libssh.h>
1156         ])
1157         CFLAGS="$old_CFLAGS"
1158     ],
1159     [AC_MSG_WARN([libssh not found, ssh plugin will be disabled])])
1161 AM_CONDITIONAL([HAVE_SSH],[test "x$HAVE_SSH_OPTIONS_NODELAY" != "x"])
1163 dnl Check for xorriso or genisoimage or mkisofs
1164 dnl (only if you want to compile the iso plugin).
1165 ISOPROG="no"
1166 is_xorriso=0
1167 AC_ARG_WITH([iso],
1168     [AS_HELP_STRING([--without-iso],
1169                     [disable iso plugin @<:@default=check@:>@])],
1170     [],
1171     [with_iso=check])
1172 AS_IF([test "$with_iso" != "no"],[
1173     AC_CHECK_PROG([XORRISO],[xorriso],[xorriso],[no])
1174     AC_CHECK_PROG([GENISOIMAGE],[genisoimage],[genisoimage],[no])
1175     AC_CHECK_PROG([MKISOFS],[mkisofs],[mkisofs],[no])
1176     AS_IF([test "x$XORRISO" != "xno"],[
1177         ISOPROG="$XORRISO"
1178         is_xorriso=1
1179     ],[
1180         AS_IF([test "x$GENISOIMAGE" != "xno"],[
1181             ISOPROG="$GENISOIMAGE"
1182         ],[
1183             AS_IF([test "x$MKISOFS" != "xno"],[
1184                 ISOPROG="$MKISOFS"
1185             ])
1186         ])
1187     ])
1188     AS_IF([test "x$ISOPROG" != "xno"],[
1189         printf "picked %s for nbdkit-iso-plugin\n" "$ISOPROG"
1190         AC_DEFINE_UNQUOTED([ISOPROG],["$ISOPROG"],
1191                            [Program used by iso plugin to make ISOs.])
1192         AS_IF([test "x$is_xorriso" = "x1"], [
1193             AC_DEFINE([ISOPROG_IS_XORRISO],[1],
1194                       [ISO program behaves like xorriso.])
1195         ])
1196     ])
1198 AC_SUBST([ISOPROG])
1199 AM_CONDITIONAL([HAVE_ISO],[test "x$ISOPROG" != "xno"])
1201 dnl Check for libvirt (only if you want to compile the libvirt plugin).
1202 AC_ARG_WITH([libvirt],
1203     [AS_HELP_STRING([--without-libvirt],
1204                     [disable libvirt plugin @<:@default=check@:>@])],
1205     [],
1206     [with_libvirt=check])
1207 AS_IF([test "$with_libvirt" != "no"],[
1208     PKG_CHECK_MODULES([LIBVIRT], [libvirt],[
1209         AC_SUBST([LIBVIRT_CFLAGS])
1210         AC_SUBST([LIBVIRT_LIBS])
1211         AC_DEFINE([HAVE_LIBVIRT],[1],[libvirt found at compile time.])
1212     ],
1213     [AC_MSG_WARN([libvirt not found, libvirt plugin will be disabled])])
1215 AM_CONDITIONAL([HAVE_LIBVIRT],[test "x$LIBVIRT_LIBS" != "x"])
1217 dnl Check for zlib (only if you want to compile the gzip filter).
1218 AC_ARG_WITH([zlib],
1219     [AS_HELP_STRING([--without-zlib],
1220                     [disable gzip filter @<:@default=check@:>@])],
1221     [],
1222     [with_zlib=check])
1223 AS_IF([test "$with_zlib" != "no"],[
1224     PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2.3.5],[
1225         AC_SUBST([ZLIB_CFLAGS])
1226         AC_SUBST([ZLIB_LIBS])
1227         AC_DEFINE([HAVE_ZLIB],[1],[zlib found at compile time.])
1228     ],
1229     [AC_MSG_WARN([zlib >= 1.2.3.5 not found, gzip filter will be disabled])])
1231 AM_CONDITIONAL([HAVE_ZLIB],[test "x$ZLIB_LIBS" != "x"])
1233 dnl Check for libnbd (only if you want to compile the nbd plugin).
1234 AC_ARG_WITH([libnbd],
1235     [AS_HELP_STRING([--without-libnbd],
1236                     [disable nbd plugin @<:@default=check@:>@])],
1237     [],
1238     [with_libnbd=check])
1239 AS_IF([test "$with_libnbd" != "no"],[
1240     PKG_CHECK_MODULES([LIBNBD], [libnbd >= 0.9.8],[
1241         printf "libnbd version is "; $PKG_CONFIG --modversion libnbd
1242         AC_SUBST([LIBNBD_CFLAGS])
1243         AC_SUBST([LIBNBD_LIBS])
1244         AC_DEFINE([HAVE_LIBNBD],[1],[libnbd found at compile time.])
1245     ],
1246     [AC_MSG_WARN([libnbd >= 0.9.8 not found, nbd plugin will be crippled])])
1249 dnl For backwards compatibilty, we have a second way to disable the nbd plugin.
1250 AC_ARG_ENABLE([nbd-plugin],
1251     [AS_HELP_STRING([--disable-nbd-plugin], [disable nbd plugin (deprecated, use --without-libnbd)])],
1252     [],
1253     [enable_nbd_plugin=yes])
1254 AM_CONDITIONAL([HAVE_LIBNBD],
1255   [test "x$LIBNBD_LIBS" != "x" && test "x$enable_nbd_plugin" = "xyes"])
1257 dnl Check for liblzma (only if you want to compile the xz filter).
1258 AC_ARG_WITH([liblzma],
1259     [AS_HELP_STRING([--without-liblzma],
1260                     [disable xz filter @<:@default=check@:>@])],
1261     [],
1262     [with_liblzma=check])
1263 AS_IF([test "$with_liblzma" != "no"],[
1264     PKG_CHECK_MODULES([LIBLZMA], [liblzma],[
1265         AC_SUBST([LIBLZMA_CFLAGS])
1266         AC_SUBST([LIBLZMA_LIBS])
1267         AC_DEFINE([HAVE_LIBLZMA],[1],[liblzma found at compile time.])
1268     ],
1269     [AC_MSG_WARN([liblzma not found, xz filter will be disabled])])
1271 AM_CONDITIONAL([HAVE_LIBLZMA],[test "x$LIBLZMA_LIBS" != "x"])
1273 dnl Check for zstd (only if you want to compile allocator=zstd).
1274 AC_ARG_WITH([libzstd],
1275     [AS_HELP_STRING([--without-libzstd],
1276                     [disable allocator=zstd @<:@default=check@:>@])],
1277     [],
1278     [with_libzstd=check])
1279 AS_IF([test "$with_libzstd" != "no"],[
1280     PKG_CHECK_MODULES([LIBZSTD], [libzstd],[
1281         AC_SUBST([LIBZSTD_CFLAGS])
1282         AC_SUBST([LIBZSTD_LIBS])
1283         AC_DEFINE([HAVE_LIBZSTD],[1],[libzstd found at compile time.])
1284     ],
1285     [AC_MSG_WARN([libzstd not found, allocator=zstd will be disabled])])
1287 AM_CONDITIONAL([HAVE_LIBZSTD],[test "x$LIBZSTD_LIBS" != "x"])
1289 dnl Check for libguestfs (only for the guestfs plugin and parts of
1290 dnl the test suite).
1291 AC_ARG_WITH([libguestfs],
1292     [AS_HELP_STRING([--without-libguestfs],
1293                     [disable guestfs plugin and tests @<:@default=check@:>@])],
1294     [],
1295     [with_libguestfs=check])
1296 AS_IF([test "$with_libguestfs" != "no"],[
1297     PKG_CHECK_MODULES([LIBGUESTFS], [libguestfs],[
1298         # Although the library was found, we want to make sure it supports nbd
1299         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1300 #include <guestfs.h>
1301         ]], [[
1302 #ifndef GUESTFS_ADD_DRIVE_OPTS_PROTOCOL
1303 #error unsupported
1304 #endif
1305         ]])], [
1306         AC_SUBST([LIBGUESTFS_CFLAGS])
1307         AC_SUBST([LIBGUESTFS_LIBS])
1308         AC_DEFINE([HAVE_LIBGUESTFS],[1],[libguestfs found at compile time.])
1309         ],[
1310         LIBGUESTFS_LIBS=
1311         AC_MSG_WARN([libguestfs too old, guestfs plugin and tests will be disabled])])
1312     ],
1313     [AC_MSG_WARN([libguestfs not found, guestfs plugin and tests will be disabled])])
1315 AM_CONDITIONAL([HAVE_LIBGUESTFS],[test "x$LIBGUESTFS_LIBS" != "x"])
1317 dnl Disable tests which need libguestfs.
1318 AC_ARG_ENABLE([libguestfs-tests],
1319     [AS_HELP_STRING([--disable-libguestfs-tests],
1320                     [disable tests which need libguestfs])],
1321     [],
1322     [enable_libguestfs_tests=check]
1324 AM_CONDITIONAL([USE_LIBGUESTFS_FOR_TESTS],
1325                [test "x$LIBGUESTFS_LIBS" != "x" && \
1326                 test "x$enable_libguestfs_tests" != "xno"])
1328 dnl Check for ext2fs and com_err, for the ext2 filter.
1329 AC_ARG_WITH([ext2],
1330     [AS_HELP_STRING([--without-ext2],
1331                     [disable ext2 filter @<:@default=check@:>@])],
1332     [],
1333     [with_ext2=check])
1334 AS_IF([test "$with_ext2" != "no"], [
1335     PKG_CHECK_MODULES([EXT2FS], [ext2fs], [
1336         AC_SUBST([EXT2FS_CFLAGS])
1337         AC_SUBST([EXT2FS_LIBS])
1338         AC_DEFINE([HAVE_EXT2FS],[1],[ext2fs found at compile time.])
1339     ],
1340     [AC_MSG_WARN([ext2fs not found, ext2 filter will be disabled])])
1341     PKG_CHECK_MODULES([COM_ERR], [com_err], [
1342         AC_SUBST([COM_ERR_CFLAGS])
1343         AC_SUBST([COM_ERR_LIBS])
1344         AC_DEFINE([HAVE_COM_ERR],[1],[com_err found at compile time.])
1345     ],
1346     [AC_MSG_WARN([com_err not found, ext2 filter will be disabled])])
1348     AC_CHECK_MEMBERS([struct struct_io_manager.cache_readahead,
1349                       struct struct_io_manager.zeroout])
1351 AM_CONDITIONAL([HAVE_EXT2],
1352                [test "x$EXT2FS_LIBS" != "x" && test "x$COM_ERR_LIBS" != "x"])
1354 dnl libtorrent-rasterbar for the bittorrent plugin.
1355 AC_ARG_ENABLE([torrent],
1356     [AS_HELP_STRING([--disable-torrent],
1357                     [disable bittorrent plugin])],
1358     [],
1359     [enable_torrent=check]
1361 AS_IF([test "x$enable_torrent" != "xno"], [
1362     PKG_CHECK_MODULES([LIBTORRENT], [libtorrent-rasterbar], [
1363         AC_SUBST([LIBTORRENT_CFLAGS])
1364         AC_SUBST([LIBTORRENT_LIBS])
1365     ],
1366     [AC_MSG_WARN([libtorrent-rasterbar not found, bittorrent plugin will be disabled])])
1368 AM_CONDITIONAL([HAVE_TORRENT],
1369                [test "x$have_cxx" = "xyes" && test "x$LIBTORRENT_LIBS" != "x"])
1371 dnl Check if the user wants to disable VDDK support.
1372 dnl See plugins/vddk/README.VDDK.
1373 AC_ARG_ENABLE([vddk],
1374     [AS_HELP_STRING([--disable-vddk],
1375                     [disable VMware VDDK plugin])],
1376     [],
1377     [
1378      dnl While VDDK was available on i686 in 5.1.1, we only support
1379      dnl newer versions which are supported only on x86-64.  Don't
1380      dnl compile on other platforms.
1381      AC_MSG_CHECKING([if the host CPU is compatible with VDDK])
1382      AS_IF([test "$host_cpu" = "x86_64" && test "$host_os" = "linux-gnu"],[
1383         AC_MSG_RESULT([yes ($host)])
1384         enable_vddk=yes
1385      ],[
1386         AC_MSG_RESULT([no ($host)])
1387         enable_vddk=no
1388      ])
1389     ])
1390 AM_CONDITIONAL([HAVE_VDDK], [test "x$enable_vddk" = "xyes"])
1392 dnl Expose version information to the public headers
1393 [NBDKIT_]VERSION_MAJOR=NBDKIT_VERSION_MAJOR
1394 [NBDKIT_]VERSION_MINOR=NBDKIT_VERSION_MINOR
1395 [NBDKIT_]VERSION_MICRO=NBDKIT_VERSION_MICRO
1396 AC_SUBST([NBDKIT_VERSION_MAJOR])
1397 AC_SUBST([NBDKIT_VERSION_MINOR])
1398 AC_SUBST([NBDKIT_VERSION_MICRO])
1400 dnl Produce output files.
1401 AC_CONFIG_HEADERS([config.h])
1402 AC_CONFIG_FILES([podwrapper.pl],
1403                 [chmod +x,-w podwrapper.pl])
1404 AC_CONFIG_FILES([common/protocol/generate-protostrings.sh],
1405                 [chmod +x,-w common/protocol/generate-protostrings.sh])
1406 AC_CONFIG_FILES([tests/make-pki.sh],
1407                 [chmod +x,-w tests/make-pki.sh])
1408 AC_CONFIG_FILES([Makefile
1409                  bash-completion/Makefile
1410                  common/allocators/Makefile
1411                  common/bitmap/Makefile
1412                  common/gpt/Makefile
1413                  common/include/Makefile
1414                  common/protocol/Makefile
1415                  common/regions/Makefile
1416                  common/replacements/Makefile
1417                  common/replacements/win32/Makefile
1418                  common/utils/Makefile
1419                  docs/Makefile
1420                  include/Makefile
1421                  include/nbdkit-version.h
1422                  plugins/Makefile
1423                  plugins/blkio/Makefile
1424                  plugins/cc/Makefile
1425                  plugins/cdi/Makefile
1426                  plugins/curl/Makefile
1427                  plugins/data/Makefile
1428                  plugins/eval/Makefile
1429                  plugins/example1/Makefile
1430                  plugins/example2/Makefile
1431                  plugins/example3/Makefile
1432                  plugins/example4/Makefile
1433                  plugins/file/Makefile
1434                  plugins/floppy/Makefile
1435                  plugins/full/Makefile
1436                  plugins/golang/Makefile
1437                  plugins/guestfs/Makefile
1438                  plugins/info/Makefile
1439                  plugins/iso/Makefile
1440                  plugins/libvirt/Makefile
1441                  plugins/linuxdisk/Makefile
1442                  plugins/lua/Makefile
1443                  plugins/memory/Makefile
1444                  plugins/nbd/Makefile
1445                  plugins/null/Makefile
1446                  plugins/ocaml/Makefile
1447                  plugins/ondemand/Makefile
1448                  plugins/partitioning/Makefile
1449                  plugins/pattern/Makefile
1450                  plugins/perl/Makefile
1451                  plugins/python/Makefile
1452                  plugins/random/Makefile
1453                  plugins/ruby/Makefile
1454                  plugins/rust/Makefile
1455                  plugins/S3/Makefile
1456                  plugins/sh/Makefile
1457                  plugins/ssh/Makefile
1458                  plugins/sparse-random/Makefile
1459                  plugins/split/Makefile
1460                  plugins/tcl/Makefile
1461                  plugins/tmpdisk/Makefile
1462                  plugins/torrent/Makefile
1463                  plugins/vddk/Makefile
1464                  plugins/zero/Makefile
1465                  filters/Makefile
1466                  filters/blocksize/Makefile
1467                  filters/blocksize-policy/Makefile
1468                  filters/cache/Makefile
1469                  filters/cacheextents/Makefile
1470                  filters/checkwrite/Makefile
1471                  filters/cow/Makefile
1472                  filters/ddrescue/Makefile
1473                  filters/delay/Makefile
1474                  filters/error/Makefile
1475                  filters/exitlast/Makefile
1476                  filters/exitwhen/Makefile
1477                  filters/exportname/Makefile
1478                  filters/ext2/Makefile
1479                  filters/extentlist/Makefile
1480                  filters/fua/Makefile
1481                  filters/gzip/Makefile
1482                  filters/ip/Makefile
1483                  filters/limit/Makefile
1484                  filters/log/Makefile
1485                  filters/luks/Makefile
1486                  filters/multi-conn/Makefile
1487                  filters/nocache/Makefile
1488                  filters/noextents/Makefile
1489                  filters/nofilter/Makefile
1490                  filters/noparallel/Makefile
1491                  filters/nozero/Makefile
1492                  filters/offset/Makefile
1493                  filters/partition/Makefile
1494                  filters/pause/Makefile
1495                  filters/protect/Makefile
1496                  filters/rate/Makefile
1497                  filters/readahead/Makefile
1498                  filters/retry/Makefile
1499                  filters/retry-request/Makefile
1500                  filters/scan/Makefile
1501                  filters/stats/Makefile
1502                  filters/swab/Makefile
1503                  filters/tar/Makefile
1504                  filters/tls-fallback/Makefile
1505                  filters/truncate/Makefile
1506                  filters/xz/Makefile
1507                  fuzzing/Makefile
1508                  server/local/nbdkit.pc
1509                  server/Makefile
1510                  server/nbdkit.pc
1511                  tests/functions.sh
1512                  tests/Makefile
1513                  valgrind/Makefile])
1515 AC_OUTPUT
1517 dnl Summary.
1518 echo
1519 echo
1520 echo "----------------------------------------------------------------------"
1521 echo "Thank you for downloading $PACKAGE_STRING"
1522 echo
1523 echo "This is how we have configured the optional components for you today:"
1524 echo
1526 print ()
1528     printf '    %.40s %s\n' \
1529         "$1 ........................................" "$2"
1532 feature ()
1534     feat="$1"
1535     shift
1536     if "$@"; then
1537         print "$feat" "yes"
1538     else
1539         print "$feat" "no"
1540     fi
1543 echo "Optional server features:"
1544 echo
1545 feature "bash-completion"     test "x$HAVE_BASH_COMPLETION_TRUE" = "x"
1546 feature "libfuzzer"           test "x$ENABLE_LIBFUZZER_TRUE" = "x"
1547 feature "linker script"       test "x$USE_LINKER_SCRIPT" = "x"
1548 feature "manual pages"        test "x$HAVE_POD_TRUE" = "x"
1549 feature "SELinux"             test "x$LIBSELINUX_LIBS" != "x"
1550 feature "TLS"                 test "x$GNUTLS_LIBS" != "x"
1552 echo
1553 echo "Optional plugins:"
1554 echo
1555 feature "blkio"               test "x$HAVE_LIBBLKIO_TRUE" = "x"
1556 feature "curl"                test "x$HAVE_CURL_TRUE" = "x"
1557 feature "example4"            test "x$HAVE_PERL_TRUE" = "x"
1558 feature "floppy"              test "x$HAVE_ICONV_TRUE" = "x"
1559 feature "guestfs"             test "x$HAVE_LIBGUESTFS_TRUE" = "x"
1560 feature "iso"                 test "x$HAVE_ISO_TRUE" = "x"
1561 feature "libvirt"             test "x$HAVE_LIBVIRT_TRUE" = "x"
1562 feature "linuxdisk"           test "x$HAVE_MKE2FS_WITH_D_TRUE" = "x"
1563 feature "nbd"                 test "x$HAVE_LIBNBD_TRUE" = "x"
1564 feature "S3"                  test "x$HAVE_PYTHON_TRUE" = "x"
1565 feature "ssh"                 test "x$HAVE_SSH_TRUE" = "x"
1566 feature "torrent"             test "x$HAVE_TORRENT_TRUE" = "x"
1567 feature "vddk"                test "x$HAVE_VDDK_TRUE" = "x"
1569 echo
1570 echo "Languages:"
1571 echo
1572 feature "go"                  test "x$HAVE_GOLANG_TRUE" = "x"
1573 feature "lua"                 test "x$HAVE_LUA_TRUE" = "x"
1574 feature "ocaml"               test "x$HAVE_OCAML_TRUE" = "x"
1575 feature "perl"                test "x$HAVE_PERL_TRUE" = "x"
1576 feature "python"              test "x$HAVE_PYTHON_TRUE" = "x"
1577 feature "ruby"                test "x$HAVE_RUBY_TRUE" = "x"
1578 feature "rust"                test "x$HAVE_RUST_TRUE" = "x"
1579 feature "tcl"                 test "x$HAVE_TCL_TRUE" = "x"
1581 echo
1582 echo "Optional filters:"
1583 echo
1584 feature "ext2"                test "x$HAVE_EXT2_TRUE" = "x"
1585 feature "gzip"                test "x$HAVE_ZLIB_TRUE" = "x"
1586 feature "luks"                test "x$HAVE_GNUTLS_PBKDF2_TRUE" = "x"
1587 feature "stats"               test "x$HAVE_CXX_TRUE" = "x"
1588 feature "xz"                  test "x$HAVE_LIBLZMA_TRUE" = "x"
1590 echo
1591 echo "Other optional features:"
1592 echo
1593 feature "allocator=zstd"      test "x$HAVE_LIBZSTD_TRUE" = "x"
1594 feature "tests using libguestfs" \
1595                               test "x$HAVE_LIBGUESTFS_TRUE" = "x" -a \
1596                                    "x$USE_LIBGUESTFS_FOR_TESTS_TRUE" = "x"
1598 echo
1599 echo "If any optional component is configured ‘no’ when you expected ‘yes’"
1600 echo "then you should check the preceding messages and README."
1601 echo
1602 echo "Please report bugs back to the mailing list:"
1603 echo "http://www.redhat.com/mailman/listinfo/libguestfs"
1604 echo
1605 echo "Next you should type 'make' to build the package,"
1606 echo "then 'make check' to run the tests."