Update copyright statement
[nbd.git] / configure.ac
blob8602445e5a73ec79fd2e0a6cbcb673288b7dd97b
1 dnl Configure script for NBD system
2 dnl (c) 1998 Martin Mares <mj@ucw.cz>, (c) 2000 Pavel Machek <pavel@ucw.cz>,
3 dnl (c) 2003-2024 Wouter Verhelst <wouter@debian.org>
4 AC_INIT([nbd],
5   m4_esyscmd(support/genver.sh | tr -d '\n'),
6   [nbd@other.debian.org],,
7   [http://nbd.sourceforge.net/])
8 m4_define([serial_tests], [
9   m4_esyscmd([automake --version |
10               head -1 |
11               awk '{split ($NF,a,"."); if (a[1] == 1 && a[2] >= 12) { print "serial-tests" }}'
12   ])
14 AM_INIT_AUTOMAKE(foreign dist-xz serial_tests subdir-objects)
15 AM_MAINTAINER_MODE([enable])
16 AM_SILENT_RULES([yes])
17 AC_CONFIG_MACRO_DIR([support])
18 LT_INIT
20 AC_ARG_ENABLE(
21   lfs,
22   AS_HELP_STRING([--disable-lfs],[Disable Large File Support (default on)]),
23   [
24     if test "x$enableval" = "xyes" ; then
25       NBD_LFS=1
26     else
27       NBD_LFS=0
28     fi
29   ],
30   [NBD_LFS=1]
32 AC_MSG_CHECKING([whether Large File Support should be enabled])
33 if test $NBD_LFS -eq 1; then
34   AC_DEFINE(NBD_LFS,1, [Define to 1 if Large File Support should be enabled])
35   AC_MSG_RESULT([yes])
36 else
37   AC_DEFINE(NBD_LFS,0)
38   AC_MSG_RESULT([no])
41 AC_ARG_ENABLE(
42   syslog,
43   AS_HELP_STRING([--enable-syslog],[Enable Syslog logging]),
44   [
45     if test "x$enableval" = "xyes" ; then
46       ISSERVER=1
47     else
48       ISSERVER=0
49     fi
50   ],
51   [ISSERVER=0]
54 AC_MSG_CHECKING([whether syslog logging is requested])
55 if test $ISSERVER -eq 1; then
56   AC_DEFINE(ISSERVER,1, [Define to 1 if you want nbd-server to log through syslog])
57   AC_MSG_RESULT([yes])
58 else
59   AC_MSG_RESULT([no])
62 AC_ARG_ENABLE(
63   debug,
64   AS_HELP_STRING([--enable-debug],[Build a debugging version of the server]),
65   [
66     if test "x$enableval" = "xyes"; then
67       DODBG=1
68     else
69       DODBG=0
70     fi
71   ],
72   [DODBG=0]
75 AC_MSG_CHECKING([whether a debugging version is requested])
76 if test $DODBG -eq 1; then
77   AC_MSG_RESULT([yes])
78   if test $ISSERVER -eq 1; then
79     AC_MSG_ERROR([You requested both syslog logging and a debugging version of the server. Bad idea!])
80   fi
81   AC_DEFINE(DODBG,1,[Define if you want a debugging version of nbd-server (lots of copious output)])
82   AC_DEFINE(NOFORK,1,[Define if you do not want the nbd-server to fork()])
83 else
84   AC_MSG_RESULT([no])
87 AC_ARG_ENABLE(
88   [gznbd],
89   [AS_HELP_STRING([--enable-gznbd],[Build gznbd too (nbd server with on-the-fly decompression of images. NOTE: no support for newstyle protocol.)])],
90   [
91     AS_IF(
92       [test "x$enableval" = "xyes"],
93       [ENABLE_GZNBD=yes],
94       [ENABLE_GZNBD=no]
95     )
96   ],
97   [ENABLE_GZNBD=no]
100 AC_PROG_CC
101 AC_PROG_CPP
102 AC_PROG_INSTALL
103 AM_PROG_LEX(noyywrap)
104 m4_ifdef([AX_PROG_BISON],,
105  [m4_fatal([The m4 macro AX_PROG_BISON has not been defined. Please install the autoconf-archive package.])])
106 AX_PROG_BISON([],AC_MSG_ERROR([bison is required]))
107 PKG_PROG_PKG_CONFIG
108 AC_CANONICAL_HOST
109 AC_C_BIGENDIAN
110 AC_C_INLINE
111 AC_C_CONST
112 AC_CHECK_SIZEOF(unsigned short int)
113 AC_CHECK_SIZEOF(unsigned int)
114 AC_CHECK_SIZEOF(unsigned long int)
115 AC_CHECK_SIZEOF(unsigned long long int)
116 AC_STRUCT_DIRENT_D_TYPE
117 AC_CHECK_FUNCS([llseek alarm gethostbyname inet_ntoa memset socket strerror strstr mkstemp fdatasync])
118 HAVE_FL_PH=no
120 AC_CHECK_FUNC(fallocate,
121   [
122     AC_CHECK_HEADERS([linux/falloc.h])
123     if test "x$ac_cv_header_linux_falloc_h" = "xyes"
124     then
125       AC_CHECK_DECL(FALLOC_FL_PUNCH_HOLE, [HAVE_FL_PH=yes], [HAVE_FL_PH=no], [[#include <linux/falloc.h>]])
126     fi
127   ]
130 AC_MSG_CHECKING([for FALLOC_FL_PUNCH_HOLE support])
131 if test "x$HAVE_FL_PH" = "xyes"
132 then
133         AC_DEFINE(HAVE_FALLOC_PH, 1, [Define to 1 if you have FALLOC_FL_PUNCH_HOLE])
134         AC_MSG_RESULT([yes])
135 else
136         AC_DEFINE(HAVE_FALLOC_PH, 0, [Define to 1 if you have FALLOC_FL_PUNCH_HOLE])
137         AC_MSG_RESULT([no])
140 AC_CHECK_DECL([BLKDISCARD], AC_DEFINE(HAVE_BLKDISCARD, 1, [Define to 1 if you have the BLKDISCARD ioctl]), AC_DEFINE(HAVE_BLKDISCARD, 0), [#include <linux/fs.h>])
142 AC_CHECK_FUNC(splice, [HAVE_SPLICE=yes], [HAVE_SPLICE=no])
143 if test "$HAVE_SPLICE" = "yes"
144 then
145         HAVE_SETPIPE_SZ=no
146         AC_CHECK_DECL(F_SETPIPE_SZ, [HAVE_SETPIPE_SZ=yes],
147                 [
148                         unset ac_cv_have_decl_F_SETPIPE_SZ
149                         AC_CHECK_HEADERS([linux/fcntl.h])
150                         if test "$ac_cv_header_linux_fcntl_h" = "yes"
151                         then
152                                 AC_CHECK_DECL(F_SETPIPE_SZ, [HAVE_SETPIPE_SZ=define], [HAVE_SETPIPE_SZ=no], [[#include <linux/fcntl.h>]])
153                         fi
154                 ],
155                 [[
156                         #define _GNU_SOURCE
157                         #include <fcntl.h>
158                 ]]
159         )
160         AC_MSG_CHECKING([for F_SETPIPE_SZ support])
161         case $HAVE_SETPIPE_SZ in
162                 yes)
163                         AC_DEFINE(HAVE_SPLICE, 1, [Define to 1 if we have splice support])
164                         AC_MSG_RESULT([yes])
165                 ;;
166                 define)
167                         AC_DEFINE(HAVE_SPLICE, 1, [Define to 1 if we have splice support])
168                         AC_DEFINE(F_SETPIPE_SZ, 1031, [Define to 1031 if we have kernel support but no userspace support])
169                         AC_MSG_RESULT([yes])
170                 ;;
171                 no)
172                         AC_MSG_RESULT([missing, disabling splice support])
173                 ;;
174         esac
177 m4_ifndef([PKG_CHECK_MODULES], [m4_fatal([Missing pkg-config M4 macros. Please ensure that pkg-config is installed.])])
179 dnl AC_MSG_CHECKING([where to puth systemd unit files])
180 dnl AC_ARG_WITH(
181 dnl   systemd,
182 dnl   AS_HELP_STRING([--with-systemd=loc|pkgconfig],[Install systemd files in loc; if passing pkgconfig, use pkg-config to detect the correct location and install there.])
183 dnl   [
184 dnl     if test "x$enableval" = "xyes"; then
185 dnl       ENABLE_SYSTEMD=yes
186 dnl     else
187 dnl       ENABLE_SYSTEMD=no
188 dnl     fi
189 dnl   ],[]
190 dnl )
191 dnl 
192 dnl if test "x$ENABLE_SYSTEMD" != "xno"; then
193 dnl     PKG_CHECK_VAR([SYSTEMDUNIT],[systemd],systemdsystemunitdir],[AC_SUBST([SYSTEMDLOC], [$SYSTEMDUNIT])])
194 dnl fi
195 dnl AM_CONDITIONAL(SYSTEMD, [test ! -z "$SYSTEMDUNIT"])
196 dnl if test ! -z $SYSTEMDUNIT; then
197 dnl     AC_MSG_RESULT([$SYSTEMDUNIT])
198 dnl else
199 dnl     case $ENABLE_SYSTEMD in
200 dnl             no)
201 dnl                     AC_MSG_RESULT([disabled])
202 dnl             ;;
203 dnl             yes)
204 dnl                     AC_MSG_ERROR([systemd not found])
205 dnl             ;;
206 dnl             *)
207 dnl                     AC_MSG_RESULT([not found])
208 dnl             ;;
209 dnl     esac
210 dnl fi
212 AC_ARG_WITH([gnutls],
213         [AS_HELP_STRING([--without-gnutls],
214                 [do not use gnutls])],
215         [],
216         [with_gnutls=check]
218 if test "x$with_gnutls" != "xno"; then
219         PKG_CHECK_MODULES(GnuTLS, [gnutls >= 2.12.0],
220                 [HAVE_GNUTLS=1
221                 AC_DEFINE(HAVE_GNUTLS, 1, [Define to 1 if you have a GnuTLS version of 2.12 or above])],
222                 [if test "x$with_gnutls" = "xyes"; then
223                         AC_MSG_ERROR([--with-gnutls given but cannot find gnutls])
224                 else
225                         HAVE_GNUTLS=0
226                         AC_DEFINE(HAVE_GNUTLS, 0)
227                 fi]
228         )
229 else
230         HAVE_GNUTLS=0
231         AC_DEFINE(HAVE_GNUTLS, 0)
233 AM_CONDITIONAL([GNUTLS], [test "x$HAVE_GNUTLS" = "x1"])
235 AC_CHECK_HEADERS([winioctl.h], [], [],
236 [#include <io.h>
237 #include <windef.h>
238 #include <winbase.h>
240 HAVE_FSCTL_SET_ZERO_DATA=no
241 if test "x$ac_cv_header_winioctl_h" = "xyes"
242 then
243         AC_CHECK_DECL(FSCTL_SET_ZERO_DATA, [HAVE_FSCTL_SET_ZERO_DATA=yes], [HAVE_FSCTL_SET_ZERO_DATA=no],
244         [#include <windef.h>
245         #include <winbase.h>
246         #include <winioctl.h>
247         ])
249 if test "x$HAVE_FSCTL_SET_ZERO_DATA" = "xyes"
250 then
251         AC_DEFINE(HAVE_FSCTL_SET_ZERO_DATA, 1, [Define to 1 if you have FSCTL_SET_ZERO_DATA])
252 else
253         AC_DEFINE(HAVE_FSCTL_SET_ZERO_DATA, 0, [Define to 1 if you have FSCTL_SET_ZERO_DATA])
256 AC_CHECK_FUNC([sync_file_range],
257         [AC_DEFINE([HAVE_SYNC_FILE_RANGE], [sync_file_range(2) is not supported], [sync_file_range(2) is supported])],
258         [])
259 AC_FUNC_FORK
260 AC_MSG_CHECKING(whether client should be built)
261 AS_CASE([$host_os],
262   [linux*], [NBD_CLIENT_NAME="nbd-client"; AC_MSG_RESULT(yes)],
263   [NBD_CLIENT_NAME=""; AC_MSG_RESULT(no)]
265 AC_MSG_CHECKING(whether to expect tlshuge test to fail)
266 AS_CASE([$host_os],
267   [darwin*], [RUN_XFAIL=tlshuge; AC_MSG_RESULT(yes)],
268   [RUN_XFAIL=""; AC_MSG_RESULT(no)]
270 AC_SUBST([RUN_XFAIL])
271 AM_CONDITIONAL(CLIENT, [test ! -z "$NBD_CLIENT_NAME"])
272 AC_SEARCH_LIBS(bind, socket,, AC_MSG_ERROR([Could not find an implementation of the bind() system call]))
273 AC_SEARCH_LIBS(inet_ntoa, nsl,, AC_MSG_ERROR([Could not find an implementation of the inet_ntoa() system call]))
274 AC_SEARCH_LIBS(daemon, resolv,, AC_MSG_ERROR([Could not find an implementation of the daemon() system call]))
275 AC_CHECK_HEADERS([sys/mount.h],,,
276 [[#include <sys/param.h>
278 AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h sys/ioctl.h sys/socket.h syslog.h linux/types.h sys/dirent.h sys/uio.h])
279 PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.32.0 gthread-2.0 >= 2.32.0], [HAVE_GLIB=yes], AC_MSG_ERROR([Missing glib]))
280 #PKG_CHECK_MODULES(SW, [socket_wrapper], [HAVE_SW=yes], [HAVE_SW=no])
281 #PKG_CHECK_MODULES(NW, [nss_wrapper], [HAVE_NW=yes], [HAVE_NW=no])
282 #AM_CONDITIONAL(CWRAP, test "$HAVE_SW" = "yes" -a "$HAVE_NW" = "yes")
284 my_save_cflags="$CFLAGS"
285 my_save_libs="$LIBS"
286 CFLAGS="-Wdeprecated-declarations -Werror $GLIB_CFLAGS"
287 LIBS="$GLIB_LIBS"
288 dnl g_memdup2 added in glib-2.68
289 AC_CHECK_FUNCS([g_memdup2])
290 CFLAGS="$my_save_cflags"
291 LIBS="$my_save_libs"
293 AC_MSG_CHECKING([whether _BSD_SOURCE needs to be defined for DT_* macros])
294 AC_PREPROC_IFELSE(
295         [AC_LANG_PROGRAM([[#include <dirent.h>]],
296                          [[#ifndef DT_UNKNOWN
297 #error nope
298 #endif]])],
299         [AC_MSG_RESULT([no]); NEED_BSD_SOURCE=0],
300         [AC_MSG_RESULT([yes]); NEED_BSD_SOURCE=1])
301 AC_DEFINE([NEED_BSD_SOURCE], $NEED_BSD_SOURCE, [Define to 1 if _BSD_SOURCE needs to be defined before certain inclusions])
303 AC_ARG_WITH([libnl],
304         [AS_HELP_STRING([--without-libnl],
305                 [do not use libnl])],
306         [],
307         [with_libnl=check]
309 if test "x$with_libnl" != "xno"; then
310         PKG_CHECK_MODULES(LIBNL3, libnl-genl-3.0 >= 3.1,
311                 [HAVE_NETLINK=1
312                 AC_DEFINE(HAVE_NETLINK, 1, [Define to 1 if we have netlink support])
313                 CFLAGS="$CFLAGS $LIBNL3_CFLAGS"
314                 LIBS="$LIBS $LIBNL3_LIBS"],
315                 [if test "x$with_libnl" = "xyes"; then
316                         AC_MSG_ERROR([--with-libnl given but cannot find libnl])
317                 else
318                         HAVE_NETLINK=0
319                         AC_DEFINE(HAVE_NETLINK, 0)
320                 fi]
321         )
322 else
323         HAVE_NETLINK=0
324         AC_DEFINE(HAVE_NETLINK, 0, [Define to 1 if we have netlink support])
327 AC_ARG_ENABLE([manpages],
328         AS_HELP_STRING([--disable-manpages], [Do not install man pages]),
329         [],
330         [: m4_divert_text([DEFAULTS], [enable_manpages=check])]
333 AS_IF([test "x$enable_manpages" != "xno"], [
334        AC_CHECK_PROG([DB2M], docbook2man, [docbook2man])
335         ],
336       [test "x$enable_manpages" = "xyes" -a "x$DB2M" = "x"], [
337        AC_MSG_ERROR([docbook2man not found, but is required to build manpages])
338         ]
339       [test "x$DB2M" != "x"], [enable_manpages=yes])
341 AM_CONDITIONAL(MANPAGES, test "x$enable_manpages" = "xyes"])
342 AS_IF([test "x$enable_manpages" != "xno"], [
343         AC_SUBST([MAN_CONFIG_FILES],["\
344                 man/nbd-client.8.sgml \
345                 man/nbd-server.5.sgml \
346                 man/nbd-server.1.sgml \
347                 man/nbd-trdump.1.sgml \
348                 man/nbd-trplay.1.sgml \
349                 man/nbdtab.5.sgml \
350                 "])
351         ])
352 MAN_PREFIX="$prefix"
353 test "x$MAN_PREFIX" = "xNONE" && MAN_PREFIX="$ac_default_prefix"
354 AC_SUBST([MAN_PREFIX])
355 MAN_EXEC_PREFIX=$(eval echo "$exec_prefix")
356 test "x$MAN_EXEC_PREFIX" = "xNONE" && MAN_EXEC_PREFIX="$MAN_PREFIX"
357 AC_SUBST([MAN_EXEC_PREFIX])
358 MAN_SYSCONFDIR=$(eval echo "$sysconfdir")
359 test "x$MAN_SYSCONFDIR" = "xNONE/etc" && MAN_SYSCONFDIR="$MAN_PREFIX/etc"
360 AC_SUBST([MAN_SYSCONFDIR])
362 AC_HEADER_SYS_WAIT
363 AC_TYPE_OFF_T
364 AC_TYPE_PID_T
365 AM_CPPFLAGS=$AM_CPPFLAGS" -DSYSCONFDIR='\"$sysconfdir\"'"
366 AC_SUBST(AM_CPPFLAGS)
367 AM_CONDITIONAL(GZNBD, [test "x$ENABLE_GZNBD" = "xyes"])
368 AC_CONFIG_HEADERS([config.h])
369 AC_CONFIG_LINKS([tests/run/buffer.c:buffer.c
370                  tests/run/crypto-gnutls.c:crypto-gnutls.c
371                  tests/run/cliserv.c:cliserv.c])
372 AC_CONFIG_FILES([Makefile
373                  doc/Doxyfile
374                  doc/Makefile
375                  man/Makefile
376                  gznbd/Makefile
377                  tests/Makefile
378                  tests/code/Makefile
379                  tests/run/Makefile
380                  tests/parse/Makefile
381                  $MAN_CONFIG_FILES
382                  systemd/Makefile
383                  systemd/nbd@.service.sh
384                 ])
385 AC_OUTPUT