Version 0.9.7.
[libnbd.git] / configure.ac
blob5e0c4c5033f7387bbedde0d4ae956a0f42a85cdb
1 # nbd client library in userspace
2 # Copyright (C) 2013-2019 Red Hat Inc.
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 AC_INIT([libnbd],[0.9.7])
20 AC_CONFIG_MACRO_DIR([m4])
21 m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],[],
22          [m4_define([AC_USE_SYSTEM_EXTENSIONS],[])])
23 AC_USE_SYSTEM_EXTENSIONS
24 AC_SYS_LARGEFILE
26 dnl NB: Do not [quote] this parameter.
27 AM_INIT_AUTOMAKE(foreign)
28 AC_PROG_LIBTOOL
29 LT_INIT
31 AC_CANONICAL_HOST
33 AC_PROG_SED
35 dnl Check for basic C environment.
36 AC_PROG_CC_STDC
37 AC_PROG_INSTALL
38 AC_PROG_CPP
40 AC_C_PROTOTYPES
41 test "x$U" != "x" && AC_MSG_ERROR([Compiler not ANSI compliant])
43 AM_PROG_CC_C_O
45 AX_PTHREAD
47 dnl Check for C++ (optional, we just use this to test the header
48 dnl can be included from C++ code).
49 AC_PROG_CXX
51 dnl The C++ compiler test is pretty useless because even if it fails
52 dnl it sets CXX=g++.  So test the compiler actually works.
53 AC_MSG_CHECKING([if the C++ compiler really really works])
54 AS_IF([$CXX --version >&AS_MESSAGE_LOG_FD 2>&1],[have_cxx=yes],[have_cxx=no])
55 AC_MSG_RESULT([$have_cxx])
56 AM_CONDITIONAL([HAVE_CXX], [test "$have_cxx" = "yes"])
58 AC_ARG_ENABLE([gcc-warnings],
59     [AS_HELP_STRING([--enable-gcc-warnings],
60                     [turn on lots of GCC warnings (for developers)])],
61      [case $enableval in
62       yes|no) ;;
63       *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
64       esac
65       gcc_warnings=$enableval],
66       [gcc_warnings=no]
68 if test "x$gcc_warnings" = "xyes"; then
69     WARNINGS_CFLAGS="-Wall -Werror"
70     AC_SUBST([WARNINGS_CFLAGS])
73 dnl Check for other headers, all optional.
74 AC_CHECK_HEADERS([\
75     byteswap.h \
76     endian.h \
77     sys/endian.h])
79 dnl Check for GnuTLS (optional, for TLS support).
80 AC_ARG_WITH([gnutls],
81     [AS_HELP_STRING([--without-gnutls],
82                     [disable use of gnutls @<:@default=check@:>@])],
83     [],
84     [with_gnutls=check])
85 AS_IF([test "$with_gnutls" != "no"],[
86     PKG_CHECK_MODULES([GNUTLS], [gnutls >= 3.3.0], [
87         AC_SUBST([GNUTLS_CFLAGS])
88         AC_SUBST([GNUTLS_LIBS])
89         AC_DEFINE([HAVE_GNUTLS],[1],[gnutls found at compile time.])
90     ], [
91         AC_MSG_WARN([gnutls not found or < 3.3.0, TLS support will be disabled.])
92     ])
94 AM_CONDITIONAL([HAVE_GNUTLS], [test "x$GNUTLS_LIBS" != "x"])
96 AS_IF([test "$GNUTLS_LIBS" != ""],[
97     AC_MSG_CHECKING([for default TLS session priority string])
98     AC_ARG_WITH([tls-priority],
99         [AS_HELP_STRING([--with-tls-priority],
100                         [default TLS session priority string @<:@default=NORMAL@:>@])],
101         [tls_priority=$withval],
102         [tls_priority=NORMAL])
103     AC_MSG_RESULT([$tls_priority])
104     AC_DEFINE_UNQUOTED([TLS_PRIORITY],["$tls_priority"],
105                        [Default TLS session priority string])
107     # Check for APIs which may not be present.
108     old_LIBS="$LIBS"
109     LIBS="$GNUTLS_LIBS $LIBS"
110     AC_CHECK_FUNCS([\
111         gnutls_session_set_verify_cert])
112     LIBS="$old_LIBS"
115 dnl certtool (part of GnuTLS) for testing TLS with certificates.
116 AC_CHECK_PROG([CERTTOOL], [certtool], [certtool])
117 AM_CONDITIONAL([HAVE_CERTTOOL], [test "x$CERTTOOL" != "x"])
119 dnl psktool (part of GnuTLS) for testing Pre-Shared Keys (PSK).
120 AC_CHECK_PROG([PSKTOOL], [psktool], [psktool])
121 AM_CONDITIONAL([HAVE_PSKTOOL], [test "x$PSKTOOL" != "x"])
123 dnl Check for libxml2 (optional, for NBD URI support)
124 AC_ARG_WITH([libxml2],
125     [AS_HELP_STRING([--without-libxml2],
126                     [disable use of libxml2 for URI support @<:@default=check@:>@])],
127     [],
128     [with_libxml2=check])
129 AS_IF([test "$with_libxml2" != "no"],[
130     PKG_CHECK_MODULES([LIBXML2], [libxml-2.0], [
131         AC_SUBST([LIBXML2_CFLAGS])
132         AC_SUBST([LIBXML2_LIBS])
133         AC_DEFINE([HAVE_LIBXML2],[1],[libxml2 found at compile time.])
134     ], [
135         AC_MSG_WARN([libxml2 not found, NBD URI support will be disabled.])
136     ])
139 dnl nbdkit, nbdkit-sh-plugin and development headers are only needed
140 dnl to run the test suite.
141 AC_CHECK_PROG([NBDKIT], [nbdkit], [nbdkit])
142 AS_IF([test "x$NBDKIT" != "x"], [
143     PKG_CHECK_MODULES([NBDKIT], [nbdkit >= 1.12], [
144         AC_SUBST([NBDKIT_CFLAGS])
145         AC_SUBST([NBDKIT_LIBS])
146         have_nbdkit_devel=yes
147         ], [
148         AC_MSG_WARN([nbdkit development package is not installed, tests will be disabled])
149     ])
151     AC_MSG_CHECKING([for nbdkit-sh-plugin])
152     AS_IF([$NBDKIT sh --version >&AS_MESSAGE_LOG_FD 2>&1], [
153         AC_MSG_RESULT([yes])
154         have_nbdkit_sh_plugin=yes
155     ],[
156         AC_MSG_RESULT([no])
157 ]   )
159 AM_CONDITIONAL([HAVE_NBDKIT], [test "x$NBDKIT" != "x" && test "x$have_nbdkit_devel" = "xyes" && test "x$have_nbdkit_sh_plugin" = "xyes"])
161 dnl nbd-server and qemu-nbd for interop testing.
162 AC_CHECK_PROG([NBD_SERVER], [nbd-server], [nbd-server])
163 AM_CONDITIONAL([HAVE_NBD_SERVER], [test "x$NBD_SERVER" != "x"])
164 AC_CHECK_PROG([QEMU_NBD], [qemu-nbd], [qemu-nbd])
165 AM_CONDITIONAL([HAVE_QEMU_NBD], [test "x$QEMU_NBD" != "x"])
167 dnl glib2 main loop for examples that interoperate with the glib main loop.
168 PKG_CHECK_MODULES([GLIB], [glib-2.0], [
169     AC_SUBST([GLIB_CFLAGS])
170     AC_SUBST([GLIB_LIBS])
172     AC_MSG_WARN([glib2 not found, some examples will not be compiled])
174 AM_CONDITIONAL([HAVE_GLIB], [test "x$GLIB_LIBS" != "x"])
176 dnl Check we have enough to run podwrapper.
177 AC_CHECK_PROG([PERL],[perl],[perl],[no])
178 AS_IF([test "x$PERL" != "xno"],[
179     AC_MSG_CHECKING([if we have perl Pod::Man and Pod::Simple])
180     AS_IF([$PERL -MPod::Man -MPod::Simple -e 1 >&AS_MESSAGE_LOG_FD 2>&1],[
181         enable_pod=yes
182     ],[
183         enable_pod=no
184     ])
185     AC_MSG_RESULT([$enable_pod])
187 AM_CONDITIONAL([HAVE_POD],
188                [test "x$PERL" != "xno" && test "x$enable_pod" = "xyes"])
190 dnl Define the path to the podwrapper program.
191 PODWRAPPER="$PERL $(pwd)/podwrapper.pl"
192 AC_SUBST([PODWRAPPER])
194 dnl OCaml, required for running the generator when building from git,
195 dnl optional the rest of the time unless you want to build the OCaml
196 dnl bindings.
197 AC_PROG_OCAML
198 AC_PROG_FINDLIB
199 AM_CONDITIONAL([HAVE_OCAML_TOPLEVEL],[test "x$OCAML" != "xno"])
201 dnl Flags we want to pass to every OCaml compiler call.
202 OCAML_WARN_ERROR="-warn-error CDEFLMPSUVYZX+52-3"
203 AC_SUBST([OCAML_WARN_ERROR])
204 OCAML_FLAGS="-g -annot -safe-string"
205 AC_SUBST([OCAML_FLAGS])
207 dnl Note this only disables the OCaml bindings.
208 AC_ARG_ENABLE([ocaml],
209     AS_HELP_STRING([--disable-ocaml], [disable OCaml language bindings]),
210     [],
211     [enable_ocaml=yes])
212 AM_CONDITIONAL([HAVE_OCAML],
213     [test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno" && \
214      test "x$enable_ocaml" = "xyes"])
215 AM_CONDITIONAL([HAVE_OCAMLOPT],
216     [test "x$OCAMLOPT" != "xno" && test "x$OCAMLFIND" != "xno" && \
217      test "x$enable_ocaml" = "xyes"])
219 dnl Python, optional for the Python bindings and shell.
220 PYTHON_PREFIX=
221 PYTHON_VERSION=
222 PYTHON_INSTALLDIR=
224 AC_ARG_ENABLE([python],
225     AS_HELP_STRING([--disable-python], [disable Python 3 language bindings]),
226     [],
227     [enable_python=yes])
228 AS_IF([test "x$enable_python" != "xno"],[
229     AC_CHECK_PROG([PYTHON],[python3],[python3],[no])
231     if test "x$PYTHON" != "xno"; then
232         AC_MSG_CHECKING([Python version])
233         PYTHON_VERSION_MAJOR=`$PYTHON -c "import sys; print (sys.version_info@<:@0@:>@)"`
234         PYTHON_VERSION_MINOR=`$PYTHON -c "import sys; print (sys.version_info@<:@1@:>@)"`
235         PYTHON_VERSION="$PYTHON_VERSION_MAJOR.$PYTHON_VERSION_MINOR"
236         AC_MSG_RESULT([$PYTHON_VERSION])
238         # Debian: python-3.2.pc
239         PKG_CHECK_MODULES([PYTHON], [python-"$PYTHON_VERSION"],[
240             have_python_module=1
241             AC_SUBST([PYTHON_CFLAGS])
242             AC_SUBST([PYTHON_LIBS])
243             AC_SUBST([PYTHON_VERSION])
244             AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time])
245         ],[
246             PKG_CHECK_MODULES([PYTHON], [python],[
247                 have_python_module=1
248                 AC_SUBST([PYTHON_CFLAGS])
249                 AC_SUBST([PYTHON_LIBS])
250                 AC_SUBST([PYTHON_VERSION])
251                 AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time])
252             ],[
253                 AC_MSG_WARN([python $PYTHON_VERSION not found])
254             ])
255         ])
257         AC_MSG_CHECKING([Python prefix])
258         PYTHON_PREFIX=`$PYTHON -c "import sys; print (sys.prefix)"`
259         AC_MSG_RESULT([$PYTHON_PREFIX])
261         AC_ARG_WITH([python-installdir],
262                     [AS_HELP_STRING([--with-python-installdir],
263                         [directory to install python modules @<:@default=check@:>@])],
264                         [PYTHON_INSTALLDIR="$withval"
265                          AC_MSG_NOTICE([Python install dir $PYTHON_INSTALLDIR])],
266                         [PYTHON_INSTALLDIR=check])
268         if test "x$PYTHON_INSTALLDIR" = "xcheck"; then
269             PYTHON_INSTALLDIR=
270             AC_MSG_CHECKING([for Python site-packages path])
271             if test -z "$PYTHON_INSTALLDIR"; then
272                 PYTHON_INSTALLDIR=`$PYTHON -c "import distutils.sysconfig; \
273                                                print (distutils.sysconfig.get_python_lib(1,0));"`
274             fi
275             AC_MSG_RESULT([$PYTHON_INSTALLDIR])
276         fi
278         AC_MSG_CHECKING([for Python extension suffix (PEP-3149)])
279         if test -z "$PYTHON_EXT_SUFFIX"; then
280             python_ext_suffix=`$PYTHON -c "import distutils.sysconfig; \
281                                          print (distutils.sysconfig.get_config_var('EXT_SUFFIX') or distutils.sysconfig.get_config_var('SO'))"`
282             PYTHON_EXT_SUFFIX=$python_ext_suffix
283         fi
284         AC_MSG_RESULT([$PYTHON_EXT_SUFFIX])
285     fi
287     AC_SUBST(PYTHON_PREFIX)
288     AC_SUBST(PYTHON_VERSION)
289     AC_SUBST(PYTHON_INSTALLDIR)
290     AC_SUBST(PYTHON_EXT_SUFFIX)
292 AM_CONDITIONAL([HAVE_PYTHON],
293     [test "x$PYTHON" != "xno" && test "x$have_python_module" = "x1" ])
295 dnl Produce output files.
296 AC_CONFIG_HEADERS([config.h])
298 AC_CONFIG_FILES([podwrapper.pl],
299                 [chmod +x,-w podwrapper.pl])
300 AC_CONFIG_FILES([python/run-python-tests],
301                 [chmod +x,-w python/run-python-tests])
302 AC_CONFIG_FILES([run],
303                 [chmod +x,-w run])
304 AC_CONFIG_FILES([sh/nbdsh],
305                 [chmod +x,-w sh/nbdsh])
307 AC_CONFIG_FILES([Makefile
308                  common/include/Makefile
309                  docs/Makefile
310                  examples/Makefile
311                  generator/Makefile
312                  include/Makefile
313                  interop/Makefile
314                  lib/Makefile
315                  lib/libnbd.pc
316                  ocaml/Makefile
317                  ocaml/META
318                  ocaml/examples/Makefile
319                  ocaml/tests/Makefile
320                  python/Makefile
321                  sh/Makefile
322                  tests/Makefile
323                  tests/functions.sh
324                  valgrind/Makefile])
326 AC_OUTPUT