0ab9477a8fbb4c907bd8af166df1d145b9e85556
[libguestfs.git] / configure.ac
1 # libguestfs
2 # Copyright (C) 2009-2011 Red Hat Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program 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
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 # The major, minor, and release fields MUST be numbers.  Packagers can
19 # add extra information using --with-extra="..." which may be any
20 # freeform string.
21 m4_define([libguestfs_major],   [1])
22 m4_define([libguestfs_minor],   [13])
23 m4_define([libguestfs_release], [10])
24
25 AC_INIT([libguestfs],libguestfs_major.libguestfs_minor.libguestfs_release)
26 AC_CONFIG_AUX_DIR([build-aux])
27 AM_INIT_AUTOMAKE([foreign])
28
29 m4_ifndef([AM_SILENT_RULES], [m4_define([AM_SILENT_RULES],[])])
30 AM_SILENT_RULES([yes]) # make --enable-silent-rules the default.
31
32 AC_CONFIG_MACRO_DIR([m4])
33
34 dnl Stable or unstable version?
35 AC_MSG_CHECKING([if this is a stable or unstable branch of libguestfs])
36 AS_IF([test "$((libguestfs_minor % 2))" -eq 0 ],[
37             AC_MSG_RESULT([stable])
38        ],[
39             AC_MSG_RESULT([unstable])
40             AC_MSG_NOTICE([
41 ***
42 This is a development version of libguestfs. Some APIs may be unstable
43 until they appear in a stable release of libguestfs (at which point
44 the C API and ABI is guaranteed to remain stable forever).  For
45 more information about stable and development branches of libguestfs
46 please see the section "LIBGUESTFS VERSION NUMBERS" in guestfs(3).
47 ***])
48        ])
49
50 dnl Extra string, a freeform string defined by packagers.
51 AC_ARG_WITH([extra],
52   [AS_HELP_STRING([--with-extra],
53                   [extra version string (for use by packagers)])],
54   [libguestfs_extra="$withval"],
55   [libguestfs_extra=]
56 )
57
58 AC_MSG_NOTICE([libguestfs version libguestfs_major.libguestfs_minor.libguestfs_release$libguestfs_extra])
59
60 dnl Split up the version string.
61 AC_DEFINE([PACKAGE_VERSION_MAJOR],[libguestfs_major],[Major version number])
62 AC_DEFINE([PACKAGE_VERSION_MINOR],[libguestfs_minor],[Minor version number])
63 AC_DEFINE([PACKAGE_VERSION_RELEASE],[libguestfs_release],[Release number])
64 AC_DEFINE_UNQUOTED([PACKAGE_VERSION_EXTRA],["$libguestfs_extra"],[Extra version string])
65
66 dnl Early gnulib initialization.
67 gl_EARLY
68 gl_INIT
69
70 AC_PROG_LIBTOOL
71
72 dnl Check for basic C environment.
73 AC_PROG_CC_STDC
74 AC_PROG_INSTALL
75 AC_PROG_CPP
76
77 AC_ARG_ENABLE([gcc-warnings],
78   [AS_HELP_STRING([--enable-gcc-warnings],
79                   [turn on lots of GCC warnings (for developers)])],
80   [case $enableval in
81      yes|no) ;;
82      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
83    esac
84    gl_gcc_warnings=$enableval],
85   [gl_gcc_warnings=no]
86 )
87
88 if test "$gl_gcc_warnings" = yes; then
89   gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
90   AC_SUBST([WERROR_CFLAGS])
91
92   nw=
93   # This, $nw, is the list of warnings we disable.
94   nw="$nw -Wdeclaration-after-statement" # too useful to forbid
95   nw="$nw -Waggregate-return"       # anachronistic
96   nw="$nw -Wc++-compat"             # We don't care about C++ compilers
97   nw="$nw -Wundef"                  # Warns on '#if GNULIB_FOO' etc in gnulib
98   nw="$nw -Wtraditional"            # Warns on #elif which we use often
99   nw="$nw -Wcast-qual"              # Too many warnings for now
100   nw="$nw -Wconversion"             # Too many warnings for now
101   nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
102   nw="$nw -Wsign-conversion"        # Too many warnings for now
103   nw="$nw -Wtraditional-conversion" # Too many warnings for now
104   nw="$nw -Wunreachable-code"       # Too many warnings for now
105   nw="$nw -Wpadded"                 # Our structs are not padded
106   nw="$nw -Wredundant-decls"        # openat.h declares e.g., mkdirat
107   nw="$nw -Wlogical-op"             # any use of fwrite provokes this
108   nw="$nw -Wvla"                    # two warnings in mount.c
109   # things I might fix soon:
110   nw="$nw -Wmissing-format-attribute" # daemon.h's asprintf_nowarn
111   nw="$nw -Winline"                 # daemon.h's asprintf_nowarn
112   nw="$nw -Wshadow"                 # numerous, plus we're not unanimous
113   nw="$nw -Wunsafe-loop-optimizations" # just a warning that an optimization
114                                     # was not possible, safe to ignore
115   nw="$nw -Wpacked"                 # Allow attribute((packed)) on structs
116   nw="$nw -Wlong-long"              # Allow long long since it's required
117                                     # by Python, Ruby and xstrtoll.
118   nw="$nw -Wstack-protector"        # Don't warn about stack-protector
119                                     # failures (seen on Ubuntu).
120   nw="$nw -Wmissing-noreturn"       # Don't warn about missed noreturn funcs
121                                     # (seen on Ubuntu).
122
123   gl_MANYWARN_ALL_GCC([ws])
124   gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
125   for w in $ws; do
126     gl_WARN_ADD([$w])
127   done
128   gl_WARN_ADD([-Wno-unused-parameter]) # stubs.c
129   gl_WARN_ADD([-Wno-jump-misses-init]) # stubs.c
130   gl_WARN_ADD([-Wno-unused-variable]) # FIXME: only temporary, for guestfs_protocol.c, etc
131
132   # In spite of excluding -Wlogical-op above, it is enabled, as of
133   # gcc 4.5.0 20090517, and it provokes warnings in cat.c, dd.c, truncate.c
134   gl_WARN_ADD([-Wno-logical-op])
135
136   # Work around warning in src/inspect.c.  This seems to be a bug in gcc 4.5.1.
137   gl_WARN_ADD([-Wno-strict-overflow])
138
139   gl_WARN_ADD([-fdiagnostics-show-option])
140
141   AC_SUBST([WARN_CFLAGS])
142
143   AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
144   AC_DEFINE([_FORTIFY_SOURCE], [2],
145     [enable compile-time and run-time bounds-checking, and some warnings])
146   AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
147 fi
148
149 AC_C_PROTOTYPES
150 test "x$U" != "x" && AC_MSG_ERROR([Compiler not ANSI compliant])
151
152 AM_PROG_CC_C_O
153
154 dnl Work out how to specify the linker script to the linker.
155 VERSION_SCRIPT_FLAGS=-Wl,--version-script=
156 `/usr/bin/ld --help 2>&1 | grep -- --version-script >/dev/null` || \
157     VERSION_SCRIPT_FLAGS="-Wl,-M -Wl,"
158 AC_SUBST(VERSION_SCRIPT_FLAGS)
159
160 dnl Check support for 64 bit file offsets.
161 AC_SYS_LARGEFILE
162
163 dnl Check sizeof long.
164 AC_CHECK_SIZEOF([long])
165
166 dnl Check if dirent (readdir) supports d_type member.
167 AC_STRUCT_DIRENT_D_TYPE
168
169 dnl Check if stat has the required fields.
170 AC_STRUCT_ST_BLOCKS
171 AC_CHECK_MEMBER([struct stat.st_blksize],[
172         AC_DEFINE([HAVE_STRUCT_STAT_ST_BLKSIZE],[1],[Define to 1 if 'st_blksize' is a member of 'struct stat'])])
173
174 dnl Define a C symbol for the host CPU architecture.
175 AC_DEFINE_UNQUOTED([host_cpu],["$host_cpu"],[Host architecture.])
176
177 dnl Headers.
178 AC_CHECK_HEADERS([\
179         attr/xattr.h \
180         byteswap.h \
181         endian.h \
182         errno.h \
183         printf.h \
184         sys/inotify.h \
185         sys/socket.h \
186         sys/statvfs.h \
187         sys/types.h \
188         sys/un.h \
189         sys/wait.h \
190         windows.h \
191         sys/xattr.h])
192
193 dnl Functions.
194 AC_CHECK_FUNCS([\
195         futimens \
196         getxattr \
197         htonl \
198         htons \
199         inotify_init1 \
200         lgetxattr \
201         listxattr \
202         llistxattr \
203         lsetxattr \
204         lremovexattr \
205         mknod \
206         ntohl \
207         ntohs \
208         posix_fallocate \
209         realpath \
210         removexattr \
211         setitimer \
212         setxattr \
213         sigaction \
214         statvfs \
215         sync])
216
217 dnl For modified printf in the daemon, we need glibc either (old-style)
218 dnl register_printf_function or (new-style) register_printf_specifier.
219 AC_CHECK_FUNC([register_printf_specifier],[
220         AC_DEFINE([HAVE_REGISTER_PRINTF_SPECIFIER],[1],
221                 [Define to 1 if you have new-style register_printf_specifier])
222         ],[
223         AC_CHECK_FUNC([register_printf_function],[
224                 AC_DEFINE([HAVE_REGISTER_PRINTF_FUNCTION],[1],
225                         [Define to 1 if you have old-style register_printf_function])
226                 ],[
227                 AC_MSG_FAILURE(
228 [No support for glibc-style extended printf formatters.
229
230 This means you either have a very old glibc (pre-2.0) or you
231 are using some other libc where this is not supported.])])])
232
233 dnl Build the daemon?
234 AC_MSG_CHECKING([if we should build the daemon])
235 AC_ARG_ENABLE([daemon],
236         [AS_HELP_STRING([--enable-daemon],
237           [enable building the daemon @<:@default=yes@:>@])],
238         [],
239         [enable_daemon=yes])
240 AM_CONDITIONAL([ENABLE_DAEMON],[test "x$enable_daemon" = "xyes"])
241 AC_MSG_RESULT([$enable_daemon])
242
243 if test "x$enable_daemon" = "xyes"; then
244         dnl Install the daemon (for libguestfs live service)
245         AC_MSG_CHECKING([if we should install the daemon])
246         AC_ARG_ENABLE([install-daemon],
247                 [AS_HELP_STRING([--enable-install-daemon],
248                   [enable installing the daemon under $sbindir @<:@default=no@:>@])],
249                 [],
250                 [enable_install_daemon=no])
251         AM_CONDITIONAL([INSTALL_DAEMON],[test "x$enable_install_daemon" = "xyes"])
252         AC_MSG_RESULT([$enable_install_daemon])
253 fi
254
255 dnl Build the appliance?
256 AC_MSG_CHECKING([if we should build the appliance])
257 AC_ARG_ENABLE([appliance],
258         [AS_HELP_STRING([--enable-appliance],
259           [enable building the appliance @<:@default=yes@:>@])],
260         [],
261         [enable_appliance=yes])
262 AM_CONDITIONAL([ENABLE_APPLIANCE],[test "x$enable_appliance" = "xyes"])
263 AC_MSG_RESULT([$enable_appliance])
264
265 if test "x$enable_appliance" = "xyes"; then
266     dnl Check for febootstrap >= 3.0
267     AC_CHECK_PROG([FEBOOTSTRAP],
268                   [febootstrap],[febootstrap],[no])
269     test "x$FEBOOTSTRAP" = "xno" &&
270         AC_MSG_ERROR([febootstrap must be installed])
271     dnl febootstrap 2.x did not support the --version parameter
272     $FEBOOTSTRAP --version >&AS_MESSAGE_LOG_FD 2>&1 ||
273         AC_MSG_ERROR([febootstrap >= 3.0 must be installed, your version is too old])
274
275     dnl Pass a febootstrap --yum-config option.
276     AC_MSG_CHECKING([if user requested febootstrap --yum-config option])
277     AC_ARG_WITH([febootstrap-yum-config],
278         [AS_HELP_STRING([--with-febootstrap-yum-config=FILE],
279           [pass febootstrap --yum-config option @<:@default=no@:>@])],
280         [FEBOOTSTRAP_YUM_CONFIG="$withval"],
281         [FEBOOTSTRAP_YUM_CONFIG=no])
282     AC_MSG_RESULT([$FEBOOTSTRAP_YUM_CONFIG])
283     AC_SUBST([FEBOOTSTRAP_YUM_CONFIG])
284
285     dnl Which distro?
286     dnl
287     dnl This used to be Very Important but is now just used to select
288     dnl which packages to install in the appliance, since the package
289     dnl names vary slightly across distros.  (See
290     dnl appliance/packagelist.in and appliance/excludelist.in)
291     AC_MSG_CHECKING([which Linux distro for package names])
292     DISTRO=REDHAT
293     if test -f /etc/debian_version; then
294         DISTRO=DEBIAN
295         if grep -q 'DISTRIB_ID=Ubuntu' /etc/lsb-release 2>&AS_MESSAGE_LOG_FD; then
296             DISTRO=UBUNTU
297         fi
298     fi
299     if test -f /etc/arch-release; then
300         DISTRO=ARCHLINUX
301     fi
302     AC_MSG_RESULT([$DISTRO])
303     AC_SUBST([DISTRO])
304 fi
305
306 dnl Check for rpcgen and XDR library.  rpcgen is optional.
307 AC_CHECK_PROG([RPCGEN],[rpcgen],[rpcgen],[no])
308 AM_CONDITIONAL([HAVE_RPCGEN],[test "x$RPCGEN" != "xno"])
309 AC_CHECK_LIB([portablexdr],[xdrmem_create],[],[
310         AC_SEARCH_LIBS([xdrmem_create],[rpc xdr nsl])
311         ])
312
313 dnl Check for Augeas (now optional).
314 AC_CHECK_LIB([augeas],[aug_match],[
315         have_augeas=yes
316         AUGEAS_LIB="-laugeas"
317
318         old_LIBS="$LIBS"
319         LIBS="$LIBS $AUGEAS_LIB"
320         dnl Check for functions not available in earlier versions of Augeas.
321         AC_CHECK_FUNCS([aug_load aug_defvar aug_defnode])
322         LIBS="$old_LIBS"
323
324         ],[have_augeas=no])
325 if test "x$have_augeas" = "xyes"; then
326         AC_DEFINE([HAVE_AUGEAS],[1],[Define to 1 if you have Augeas])
327 fi
328 AC_SUBST([AUGEAS_LIB])
329
330 dnl Check for libselinux (optional).
331 AC_CHECK_HEADERS([selinux/selinux.h])
332 AC_CHECK_LIB([selinux],[setexeccon],[
333         have_libselinux="$ac_cv_header_selinux_selinux_h"
334         SELINUX_LIB="-lselinux"
335
336         old_LIBS="$LIBS"
337         LIBS="$LIBS $SELINUX_LIB"
338         AC_CHECK_FUNCS([setcon getcon])
339         LIBS="$old_LIBS"
340
341         ],[have_libselinux=no])
342 if test "x$have_libselinux" = "xyes"; then
343         AC_DEFINE([HAVE_LIBSELINUX],[1],[Define to 1 if you have libselinux])
344 fi
345 AC_SUBST([SELINUX_LIB])
346
347 dnl Check for cpio which isn't in the default Pardus install amazingly.
348 AC_CHECK_PROG([CPIO],[cpio],[cpio],[no])
349 test "x$CPIO" = "xno" &&
350      AC_MSG_ERROR([cpio must be installed])
351
352 dnl Check for gperf.
353 AC_CHECK_PROG([GPERF],[gperf],[gperf],[no])
354 test "x$GPERF" = "xno" &&
355      AC_MSG_ERROR([gperf must be installed])
356
357 dnl Check for pod2man, pod2text, pod2html.
358 AC_CHECK_PROG([POD2MAN],[pod2man],[pod2man],[no])
359 test "x$POD2MAN" = "xno" &&
360      AC_MSG_ERROR([pod2man must be installed])
361 AC_CHECK_PROG([POD2TEXT],[pod2text],[pod2text],[no])
362 test "x$POD2TEXT" = "xno" &&
363      AC_MSG_ERROR([pod2text must be installed])
364 AC_CHECK_PROG([POD2HTML],[pod2html],[pod2html],[no])
365 test "x$POD2HTML" = "xno" &&
366      AC_MSG_ERROR([pod2html must be installed])
367
368 dnl Check if pod2man, pod2text take --stderr and -u options (not in RHEL 5).
369 AC_MSG_CHECKING([if pod2man takes --stderr option])
370 if "$POD2MAN" --stderr >&AS_MESSAGE_LOG_FD 2>&1; then
371     AC_MSG_RESULT([yes])
372     POD2_STDERR_OPTION="--stderr"
373 else
374     AC_MSG_RESULT([no])
375     POD2_STDERR_OPTION=""
376 fi
377 AC_SUBST([POD2_STDERR_OPTION])
378
379 AC_MSG_CHECKING([if pod2man takes -u option])
380 if "$POD2MAN" -u >&AS_MESSAGE_LOG_FD 2>&1; then
381     AC_MSG_RESULT([yes])
382     POD2_UTF8_OPTION="-u"
383 else
384     AC_MSG_RESULT([no])
385     POD2_UTF8_OPTION=""
386 fi
387 AC_SUBST([POD2_UTF8_OPTION])
388
389 dnl Check for genisoimage.
390 AC_PATH_PROGS([GENISOIMAGE],[genisoimage],[no],
391         [$PATH$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/sbin])
392 test "x$GENISOIMAGE" = "xno" && AC_MSG_ERROR([genisoimage must be installed])
393
394 dnl Check for optional xmllint.
395 AC_CHECK_PROG([XMLLINT],[xmllint],[xmllint],[no])
396 AM_CONDITIONAL([HAVE_XMLLINT],[test "x$XMLLINT" != "xno"])
397
398 dnl po4a for translating man pages and POD files (optional).
399 AC_CHECK_PROG([PO4A],[po4a],[po4a],[no])
400 AM_CONDITIONAL([HAVE_PO4A], [test "x$PO4A" != "xno"])
401
402 dnl Check for db_dump, db_load (optional).
403 AC_CHECK_PROGS([DB_DUMP],
404                [db_dump db4_dump db4.8_dump db4.7_dump db4.6_dump],[no])
405 AC_CHECK_PROGS([DB_LOAD],
406                [db_load db4_load db4.8_load db4.7_load db4.6_load],[no])
407 if test "x$DB_DUMP" != "xno"; then
408     AC_DEFINE_UNQUOTED([DB_DUMP],["$DB_DUMP"],[Name of db_dump program.])
409 fi
410 if test "x$DB_LOAD" != "xno"; then
411     AC_DEFINE_UNQUOTED([DB_LOAD],["$DB_LOAD"],[Name of db_load program.])
412 fi
413
414 dnl Check for QEMU for running binaries on this $host_cpu, fall
415 dnl back to basic 'qemu'.  Allow the user to override it.
416 default_qemu="qemu-kvm kvm qemu-system-$host_cpu qemu"
417 AC_ARG_WITH([qemu],
418         [AS_HELP_STRING([--with-qemu],
419           [set default QEMU binary @<:@default=[qemu-kvm] qemu-system-<host> qemu@:>@])],
420         [],
421         [with_qemu="$default_qemu"])
422 AC_PATH_PROGS([QEMU],[$with_qemu],[no],
423         [$PATH$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/sbin$PATH_SEPARATOR/usr/libexec])
424 test "x$QEMU" = "xno" && AC_MSG_ERROR([qemu must be installed])
425 AC_DEFINE_UNQUOTED([QEMU],["$QEMU"],[Location of qemu binary.])
426
427 dnl Check that the chosen qemu has virtio-serial support.
428 if test "x$vmchannel_test" != "xno"; then
429     AC_MSG_CHECKING([that $QEMU -help works])
430     if $QEMU -help >&AS_MESSAGE_LOG_FD 2>&1; then
431         AC_MSG_RESULT([yes])
432     else
433         AC_MSG_RESULT([no])
434         AC_MSG_FAILURE(
435 [$QEMU -help: command failed.
436
437 This could be a very old version of qemu, or qemu might not be
438 working.
439 ])
440     fi
441
442     AC_MSG_CHECKING([for virtio-serial support in $QEMU])
443     if $QEMU -nographic -device \? 2>&1 | grep -sq virtio-serial; then
444         AC_MSG_RESULT([yes])
445     else
446         AC_MSG_RESULT([no])
447         AC_MSG_FAILURE(
448 [I did not find virtio-serial support in
449 $QEMU.
450
451 virtio-serial support in qemu or KVM is essential for libguestfs
452 to operate.
453
454 Usually this means that you have to install a newer version of qemu
455 and/or KVM.  Please read the relevant section in the README file for
456 more information about this.
457
458 You can override this test by setting the environment variable
459 vmchannel_test=no  However if you don't have the right support
460 in your qemu, then this just delays the pain.
461
462 If I am using the wrong qemu or you want to compile qemu from source
463 and install it in another location, then you should configure with
464 the --with-qemu option.
465 ])
466     fi
467 fi
468
469 dnl Set default drive interface used by the guestfs_add_drive_opts call
470 dnl ('-drive ...,if=...' option to qemu).
471 dnl
472 dnl If you encounter performance problems with virtio (RHBZ#509383)
473 dnl then try '--with-drive-if=ide'.
474 AC_ARG_WITH([drive-if],
475         [AS_HELP_STRING([--with-drive-if],
476           [set default driver (ide|scsi|virtio) @<:@default=virtio@:>@])],
477         [],
478         [with_drive_if=virtio])
479 AC_DEFINE_UNQUOTED([DRIVE_IF],["$with_drive_if"],[Default drive interface.])
480
481 dnl Set interface used by the network.  Normally you should
482 dnl leave this at the default (virtio-net-pci) but you can use the
483 dnl alternative (ne2k_pci) because of bugs in virtio networking
484 dnl eg. https://bugzilla.redhat.com/show_bug.cgi?id=516022
485 AC_ARG_WITH([net-if],
486         [AS_HELP_STRING([--with-net-if],
487           [set default net driver (virtio-net-pci|ne2k_pci) @<:@default=virtio-net-pci@:>@])],
488         [],
489         [with_net_if=virtio-net-pci])
490 AC_DEFINE_UNQUOTED([NET_IF],["$with_net_if"],[Default network interface.])
491
492 dnl Enable packet dumps when in verbose mode.  This generates lots
493 dnl of debug info, only useful for people debugging the RPC mechanism.
494 AC_ARG_ENABLE([packet-dump],
495         [AS_HELP_STRING([--enable-packet-dump],
496           [enable packet dumps in verbose mode @<:@default=no@:>@])],
497         [AC_DEFINE([ENABLE_PACKET_DUMP],[1],[Enable packet dumps in verbose mode.])],
498         [])
499
500 dnl Readline.
501 AC_ARG_WITH([readline],
502     [AS_HELP_STRING([--with-readline],
503         [support fancy command line editing @<:@default=check@:>@])],
504     [],
505     [with_readline=check])
506
507 LIBREADLINE=
508 AS_IF([test "x$with_readline" != xno],
509     [AC_CHECK_LIB([readline], [main],
510         [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
511          AC_DEFINE([HAVE_LIBREADLINE], [1],
512                    [Define if you have libreadline])
513         ],
514         [if test "x$with_readline" != xcheck; then
515          AC_MSG_FAILURE(
516              [--with-readline was given, but test for readline failed])
517          fi
518         ], -lncurses)
519      old_LIBS="$LIBS"
520      LIBS="$LIBS $LIBREADLINE"
521      AC_CHECK_FUNCS([append_history completion_matches rl_completion_matches])
522      LIBS="$old_LIBS"
523     ])
524
525 dnl For i18n.
526 AM_GNU_GETTEXT([external])
527
528 dnl Check for PCRE (required)
529 PKG_CHECK_MODULES([PCRE], [libpcre])
530
531 dnl libmagic (highly recommended)
532 AC_CHECK_LIB([magic],[magic_file],
533         [AC_CHECK_HEADER([magic.h],
534                 [AC_SUBST([MAGIC_LIBS], ["-lmagic"])
535                  AC_DEFINE([HAVE_LIBMAGIC],[1],[libmagic found at compile time.])
536                 ], [])
537         ],
538         [AC_MSG_WARN([libmagic not found, some core features will be disabled])])
539
540 dnl libvirt (highly recommended)
541 PKG_CHECK_MODULES([LIBVIRT], [libvirt],
542         [AC_SUBST([LIBVIRT_CFLAGS])
543          AC_SUBST([LIBVIRT_LIBS])
544          AC_DEFINE([HAVE_LIBVIRT],[1],[libvirt found at compile time.])
545         ],
546         [AC_MSG_WARN([libvirt not found, some core features will be disabled])])
547 AM_CONDITIONAL([HAVE_LIBVIRT],[test "x$LIBVIRT_LIBS" != "x"])
548
549 dnl libxml2 (highly recommended)
550 PKG_CHECK_MODULES([LIBXML2], [libxml-2.0],
551         [AC_SUBST([LIBXML2_CFLAGS])
552          AC_SUBST([LIBXML2_LIBS])
553          AC_DEFINE([HAVE_LIBXML2],[1],[libxml2 found at compile time.])
554         ],
555         [AC_MSG_WARN([libxml2 not found, some core features will be disabled])])
556 AM_CONDITIONAL([HAVE_LIBXML2],[test "x$LIBXML2_LIBS" != "x"])
557
558 dnl libconfig (highly recommended)
559 PKG_CHECK_MODULES([LIBCONFIG], [libconfig],
560         [AC_SUBST([LIBCONFIG_CFLAGS])
561          AC_SUBST([LIBCONFIG_LIBS])
562          AC_DEFINE([HAVE_LIBCONFIG],[1],[libconfig found at compile time.])
563         ],
564         [AC_MSG_WARN([libconfig not found, some features will be disabled])])
565 AM_CONDITIONAL([HAVE_LIBCONFIG],[test "x$LIBCONFIG_LIBS" != "x"])
566
567 dnl hivex library (highly recommended)
568 dnl This used to be a part of libguestfs, but was spun off into its
569 dnl own separate upstream project in libguestfs 1.0.85.
570 PKG_CHECK_MODULES([HIVEX], [hivex],
571         [AC_SUBST([HIVEX_CFLAGS])
572          AC_SUBST([HIVEX_LIBS])
573          AC_DEFINE([HAVE_HIVEX],[1],[hivex library found at compile time.])
574         ],
575         [AC_MSG_WARN([hivex not found, some core features will be disabled])])
576 AM_CONDITIONAL([HAVE_HIVEX],[test "x$HIVEX_LIBS" != "x"])
577
578 dnl FUSE is optional to build the FUSE module.
579 AC_ARG_ENABLE([fuse],
580         AS_HELP_STRING([--disable-fuse], [Disable FUSE (guestmount) support]),
581         [],
582         [enable_fuse=yes])
583 AS_IF([test "x$enable_fuse" != "xno"],
584         [PKG_CHECK_MODULES([FUSE],[fuse],,[
585                 enable_fuse=no
586                 AC_MSG_WARN([FUSE library and headers are missing, so optional FUSE module won't be built])])])
587 AM_CONDITIONAL([HAVE_FUSE],[test "x$enable_fuse" != "xno"])
588
589 dnl Check for OCaml (optional, for OCaml bindings).
590 OCAMLC=no
591 OCAMLFIND=no
592 AC_ARG_ENABLE([ocaml],
593         AS_HELP_STRING([--disable-ocaml], [Disable OCaml language bindings]),
594         [],
595         [enable_ocaml=yes])
596 AS_IF([test "x$enable_ocaml" != "xno"],
597         [dnl OCAMLC and OCAMLFIND have to be unset first, otherwise
598          dnl AC_CHECK_TOOL (inside AC_PROG_OCAML) will not look.
599          OCAMLC=
600          OCAMLFIND=
601          AC_PROG_OCAML
602          AC_PROG_FINDLIB
603
604          AS_IF([test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno"],
605                 [AC_CHECK_OCAML_PKG([pcre])])
606         ])
607 AM_CONDITIONAL([HAVE_OCAML],
608                [test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno"])
609 AM_CONDITIONAL([HAVE_OCAML_PCRE],
610                [test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno" && test "x$OCAML_PKG_pcre" != "xno"])
611 AM_CONDITIONAL([HAVE_OCAMLDOC],
612                [test "x$OCAMLDOC" != "xno"])
613
614 dnl Check for Perl (optional, for Perl bindings).
615 PERL=no
616 AC_ARG_ENABLE([perl],
617         AS_HELP_STRING([--disable-perl], [Disable Perl language bindings]),
618         [],
619         [enable_perl=yes])
620 AS_IF([test "x$enable_perl" != "xno"],
621         [
622         PERL=
623         AC_CHECK_PROG([PERL],[perl],[perl],[no])
624
625         dnl Check for Perl modules that must be present to compile and
626         dnl test the Perl bindings.
627         missing_perl_modules=no
628         for pm in Test::More ExtUtils::MakeMaker; do
629             AC_MSG_CHECKING([for $pm])
630             if ! perl -M$pm -e1 >&AS_MESSAGE_LOG_FD 2>&1; then
631                 AC_MSG_RESULT([no])
632                 missing_perl_modules=yes
633             else
634                 AC_MSG_RESULT([yes])
635             fi
636         done
637         if test "x$missing_perl_modules" = "xyes"; then
638             AC_MSG_WARN([some Perl modules required to compile or test the Perl bindings are missing])
639         fi
640         ])
641 AM_CONDITIONAL([HAVE_PERL],
642     [test "x$PERL" != "xno" && test "x$missing_perl_modules" != "xyes"])
643
644 dnl Check for Python (optional, for Python bindings).
645 PYTHON_PREFIX=
646 PYTHON_VERSION=
647 PYTHON_INCLUDEDIR=
648 PYTHON_INSTALLDIR=
649
650 AC_ARG_ENABLE([python],
651         AS_HELP_STRING([--disable-python], [Disable Python language bindings]),
652         [],
653         [enable_python=yes])
654 AS_IF([test "x$enable_python" != "xno"],
655         [
656         AC_CHECK_PROG([PYTHON],[python],[python],[no])
657
658         if test "x$PYTHON" != "xno"; then
659             AC_MSG_CHECKING([Python prefix])
660             PYTHON_PREFIX=`$PYTHON -c "import sys; print (sys.prefix)"`
661             AC_MSG_RESULT([$PYTHON_PREFIX])
662
663             AC_MSG_CHECKING([Python version])
664             PYTHON_VERSION=`$PYTHON -c "import sys; print (sys.version[[0:3]])"`
665             AC_MSG_RESULT([$PYTHON_VERSION])
666
667             AC_MSG_CHECKING([for Python include path])
668             if test -z "$PYTHON_INCLUDEDIR"; then
669                 python_path=`$PYTHON -c "import distutils.sysconfig; \
670                                          print (distutils.sysconfig.get_python_inc ());"`
671                 PYTHON_INCLUDEDIR=$python_path
672             fi
673             AC_MSG_RESULT([$PYTHON_INCLUDEDIR])
674
675             AC_ARG_WITH([python-installdir],
676                         [AS_HELP_STRING([--with-python-installdir],
677                                         [directory to install python modules @<:@default=check@:>@])],
678                         [PYTHON_INSTALLDIR="$withval"
679                         AC_MSG_NOTICE([Python install dir $PYTHON_INSTALLDIR])],
680                         [PYTHON_INSTALLDIR=check])
681
682             if test "x$PYTHON_INSTALLDIR" = "xcheck"; then
683                 PYTHON_INSTALLDIR=
684                 AC_MSG_CHECKING([for Python site-packages path])
685                 if test -z "$PYTHON_INSTALLDIR"; then
686                     PYTHON_INSTALLDIR=`$PYTHON -c "import distutils.sysconfig; \
687                                                    print (distutils.sysconfig.get_python_lib(1,0));"`
688                 fi
689                 AC_MSG_RESULT([$PYTHON_INSTALLDIR])
690             fi
691
692             old_LIBS="$LIBS"
693             LIBS="$LIBS -lpython$PYTHON_VERSION"
694             AC_CHECK_FUNCS([PyCapsule_New])
695             LIBS="$old_LIBS"
696         fi
697
698         AC_SUBST(PYTHON_PREFIX)
699         AC_SUBST(PYTHON_VERSION)
700         AC_SUBST(PYTHON_INCLUDEDIR)
701         AC_SUBST(PYTHON_INSTALLDIR)
702         ])
703 AM_CONDITIONAL([HAVE_PYTHON],
704     [test "x$PYTHON" != "xno" && test "x$PYTHON_INCLUDEDIR" != "x" && test "x$PYTHON_INSTALLDIR" != "x"])
705
706 dnl Check for Ruby and rake (optional, for Ruby bindings).
707 AC_ARG_ENABLE([ruby],
708         AS_HELP_STRING([--disable-ruby], [Disable Ruby language bindings]),
709         [],
710         [enable_ruby=yes])
711 AS_IF([test "x$enable_ruby" != "xno"],
712         [
713         AC_CHECK_LIB([ruby],[ruby_init],[HAVE_LIBRUBY=1],[HAVE_LIBRUBY=0])
714         AC_CHECK_PROG([RAKE],[rake],[rake],[no])
715         ])
716 AM_CONDITIONAL([HAVE_RUBY],
717     [test "x$RAKE" != "xno" && test -n "$HAVE_LIBRUBY"])
718
719 dnl Check for Java.
720 AC_ARG_WITH(java_home,
721     [AS_HELP_STRING([--with-java-home],
722         [specify path to JDK directory @<:@default=check@:>@])],
723     [],
724     [with_java_home=check])
725
726 if test "x$with_java_home" != "xno"; then
727     if test "x$with_java_home" != "xyes" && test "x$with_java_home" != "xcheck"
728     then
729         # Reject unsafe characters in $JAVA_HOME
730         jh_lf='
731 '
732         case $JAVA_HOME in
733           *[\\\"\#\$\&\'\`$jh_lf\ \     ]*)
734             AC_MSG_FAILURE([unsafe \$JAVA_HOME directory (use --with-java-home=no to disable Java support)]);;
735         esac
736         if test -d "$with_java_home"; then
737             JAVA_HOME="$with_java_home"
738         else
739             AC_MSG_FAILURE([$with_java_home is not a directory (use --with-java-home=no to disable Java support)])
740         fi
741     fi
742
743     if test "x$JAVA_HOME" = "x"; then
744         # Look for Java in some likely locations.
745         for d in \
746             /usr/lib/jvm/java \
747             /usr/lib/jvm/java-6-openjdk
748         do
749             if test -d $d && test -f $d/bin/java; then
750                 JAVA_HOME=$d
751                 break
752             fi
753         done
754     fi
755
756     if test "x$JAVA_HOME" != "x"; then
757         AC_MSG_CHECKING(for JDK in $JAVA_HOME)
758         if test ! -x "$JAVA_HOME/bin/java"; then
759             AC_MSG_ERROR([missing $JAVA_HOME/bin/java binary (use --with-java-home=no to disable Java support)])
760         else
761             JAVA="$JAVA_HOME/bin/java"
762         fi
763         if test ! -x "$JAVA_HOME/bin/javac"; then
764             AC_MSG_ERROR([missing $JAVA_HOME/bin/javac binary])
765         else
766             JAVAC="$JAVA_HOME/bin/javac"
767         fi
768         if test ! -x "$JAVA_HOME/bin/javah"; then
769             AC_MSG_ERROR([missing $JAVA_HOME/bin/javah binary])
770         else
771             JAVAH="$JAVA_HOME/bin/javah"
772         fi
773         if test ! -x "$JAVA_HOME/bin/javadoc"; then
774             AC_MSG_ERROR([missing $JAVA_HOME/bin/javadoc binary])
775         else
776             JAVADOC="$JAVA_HOME/bin/javadoc"
777         fi
778         if test ! -x "$JAVA_HOME/bin/jar"; then
779             AC_MSG_ERROR([missing $JAVA_HOME/bin/jar binary])
780         else
781             JAR="$JAVA_HOME/bin/jar"
782         fi
783         java_version=`$JAVA -version 2>&1 | grep "java version"`
784         AC_MSG_RESULT(found $java_version in $JAVA_HOME)
785
786         dnl Find jni.h.
787         AC_MSG_CHECKING([for jni.h])
788         if test -f "$JAVA_HOME/include/jni.h"; then
789             JNI_CFLAGS="-I$JAVA_HOME/include"
790         else
791             if test "`find $JAVA_HOME -name jni.h`" != ""; then
792                 head=`find $JAVA_HOME -name jni.h | tail -1`
793                 dir=`dirname "$head"`
794                 JNI_CFLAGS="-I$dir"
795             else
796                 AC_MSG_FAILURE([missing jni.h header file])
797             fi
798         fi
799         AC_MSG_RESULT([$JNI_CFLAGS])
800
801         dnl Find jni_md.h.
802         AC_MSG_CHECKING([for jni_md.h])
803         case "$build_os" in
804         *linux*) system="linux" ;;
805         *SunOS*) system="solaris" ;;
806         *cygwin*) system="win32" ;;
807         *) system="$build_os" ;;
808         esac
809         if test -f "$JAVA_HOME/include/$system/jni_md.h"; then
810             JNI_CFLAGS="$JNI_CFLAGS -I$JAVA_HOME/include/$system"
811         else
812             if test "`find $JAVA_HOME -name jni_md.h`" != ""; then
813                 head=`find $JAVA_HOME -name jni_md.h | tail -1`
814                 dir=`dirname "$head"`
815                 JNI_CFLAGS="$JNI_CFLAGS -I$dir"
816             else
817                 AC_MSG_FAILURE([missing jni_md.h header file])
818             fi
819         fi
820         AC_MSG_RESULT([$JNI_CFLAGS])
821
822         dnl Need extra version flag?
823         AC_MSG_CHECKING([extra javac flags])
824         JAVAC_FLAGS=
825         javac_version=`$JAVAC -version 2>&1`
826         case "$javac_version" in
827         *Eclipse*)
828             JAVAC_FLAGS="-source 1.5" ;;
829         esac
830         AC_MSG_RESULT([$JAVAC_FLAGS])
831
832         dnl Where to install jarfiles.
833         dnl XXX How to make it configurable?
834         JAR_INSTALL_DIR=\${prefix}/share/java
835         JNI_INSTALL_DIR=\${libdir}
836
837         dnl JNI version.
838         jni_major_version=`echo "$VERSION" | awk -F. '{print $1}'`
839         jni_minor_version=`echo "$VERSION" | awk -F. '{print $2}'`
840         jni_micro_version=`echo "$VERSION" | awk -F. '{print $3}'`
841         JNI_VERSION_INFO=`expr "$jni_major_version" + "$jni_minor_version"`":$jni_micro_version:$jni_minor_version"
842     fi
843 fi
844
845 AC_SUBST(JAVA_HOME)
846 AC_SUBST(JAVA)
847 AC_SUBST(JAVAC)
848 AC_SUBST(JAVAH)
849 AC_SUBST(JAVADOC)
850 AC_SUBST(JAR)
851 AC_SUBST(JNI_CFLAGS)
852 AC_SUBST(JAVAC_FLAGS)
853 AC_SUBST(JAR_INSTALL_DIR)
854 AC_SUBST(JNI_INSTALL_DIR)
855 AC_SUBST(JNI_VERSION_INFO)
856
857 AM_CONDITIONAL([HAVE_JAVA],[test -n "$JAVAC"])
858
859 dnl Check for Haskell (GHC).
860 GHC=no
861 AC_ARG_ENABLE([haskell],
862         AS_HELP_STRING([--disable-haskell], [Disable Haskell language bindings]),
863         [],
864         [enable_haskell=yes])
865 AS_IF([test "x$enable_haskell" != "xno"],
866         [
867         GHC=
868         AC_CHECK_PROG([GHC],[ghc],[ghc],[no])
869         ])
870 AM_CONDITIONAL([HAVE_HASKELL],
871     [test "x$GHC" != "xno"])
872
873 dnl PHP
874 PHP=no
875 AC_ARG_ENABLE([php],
876         AS_HELP_STRING([--disable-php], [Disable PHP language bindings]),
877         [],
878         [enable_php=yes])
879 AS_IF([test "x$enable_php" != "xno"],
880         [
881         PHP=
882         AC_CHECK_PROG([PHP],[php],[php],[no])
883         AC_CHECK_PROG([PHPIZE],[phpize],[phpize],[no])
884         ])
885 AM_CONDITIONAL([HAVE_PHP], [test "x$PHP" != "xno" && test "x$PHPIZE" != "xno"])
886
887 dnl Check for Perl modules needed by Perl virt tools (virt-df, etc.)
888 AS_IF([test "x$PERL" != "xno"],
889         [
890         missing_perl_modules=no
891         for pm in Pod::Usage Getopt::Long Sys::Virt Data::Dumper Locale::TextDomain Win::Hivex Win::Hivex::Regedit String::ShellQuote; do
892             AC_MSG_CHECKING([for $pm])
893             if ! $PERL -M$pm -e1 >&AS_MESSAGE_LOG_FD 2>&1; then
894                 AC_MSG_RESULT([no])
895                 missing_perl_modules=yes
896             else
897                 AC_MSG_RESULT([yes])
898             fi
899         done
900         if test "x$missing_perl_modules" = "xyes"; then
901             AC_MSG_WARN([some Perl modules required to compile the Perl virt-* tools are missing])
902         fi
903         ])
904
905 AM_CONDITIONAL([HAVE_TOOLS],
906     [test "x$PERL" != "xno" && test "x$missing_perl_modules" != "xyes"])
907
908 dnl Library versioning.
909 MAX_PROC_NR=`cat $srcdir/src/MAX_PROC_NR`
910 AC_SUBST(MAX_PROC_NR)
911
912 dnl Replace libtool with a wrapper that clobbers dependency_libs in *.la files
913 dnl http://lists.fedoraproject.org/pipermail/devel/2010-November/146343.html
914 LIBTOOL='bash $(top_srcdir)/libtool-kill-dependency_libs.sh $(top_builddir)/libtool'
915 AC_SUBST([LIBTOOL])
916
917 dnl Produce output files.
918 AC_CONFIG_HEADERS([config.h])
919 dnl http://www.mail-archive.com/automake@gnu.org/msg10204.html
920 AC_CONFIG_FILES([podwrapper.sh],
921                 [chmod +x podwrapper.sh])
922 AC_CONFIG_FILES([run],
923                 [chmod +x run])
924 AC_CONFIG_FILES([Makefile
925                  appliance/Makefile
926                  capitests/Makefile
927                  cat/Makefile
928                  caution/Makefile
929                  csharp/Makefile
930                  daemon/Makefile
931                  debian/changelog
932                  df/Makefile
933                  edit/Makefile
934                  examples/Makefile
935                  fish/Makefile
936                  fuse/Makefile
937                  generator/Makefile
938                  gnulib/lib/Makefile
939                  gnulib/tests/Makefile
940                  haskell/Makefile
941                  images/Makefile
942                  inspector/Makefile
943                  java/Makefile
944                  java/examples/Makefile
945                  libguestfs.pc
946                  ocaml/META
947                  ocaml/Makefile
948                  ocaml/examples/Makefile
949                  perl/Makefile
950                  perl/Makefile.PL
951                  perl/examples/Makefile
952                  php/Makefile
953                  po-docs/Makefile
954                  po-docs/ja/Makefile
955                  po-docs/uk/Makefile
956                  po/Makefile.in
957                  python/Makefile
958                  python/examples/Makefile
959                  regressions/Makefile
960                  rescue/Makefile
961                  resize/Makefile
962                  ruby/Makefile
963                  ruby/Rakefile
964                  ruby/examples/Makefile
965                  src/Makefile
966                  test-tool/Makefile
967                  tools/Makefile])
968 AC_OUTPUT
969
970 dnl Produce summary.
971 echo
972 echo
973 echo "------------------------------------------------------------"
974 echo "Thank you for downloading $PACKAGE_STRING"
975 echo
976 echo "This is how we have configured the optional components for you today:"
977 echo
978 echo    "Daemon .............................. $enable_daemon"
979 echo    "Appliance ........................... $enable_appliance"
980 echo    "QEMU ................................ $QEMU"
981 echo -n "OCaml bindings ...................... "
982 if test "x$HAVE_OCAML_TRUE" = "x"; then echo "yes"; else echo "no"; fi
983 echo -n "Perl bindings ....................... "
984 if test "x$HAVE_PERL_TRUE" = "x"; then echo "yes"; else echo "no"; fi
985 echo -n "Python bindings ..................... "
986 if test "x$HAVE_PYTHON_TRUE" = "x"; then echo "yes"; else echo "no"; fi
987 echo -n "Ruby bindings ....................... "
988 if test "x$HAVE_RUBY_TRUE" = "x"; then echo "yes"; else echo "no"; fi
989 echo -n "Java bindings ....................... "
990 if test "x$HAVE_JAVA_TRUE" = "x"; then echo "yes"; else echo "no"; fi
991 echo -n "Haskell bindings .................... "
992 if test "x$HAVE_HASKELL_TRUE" = "x"; then echo "yes"; else echo "no"; fi
993 echo -n "PHP bindings ........................ "
994 if test "x$HAVE_PHP_TRUE" = "x"; then echo "yes"; else echo "no"; fi
995 echo    "guestfish and C virt tools .......... yes"
996 echo -n "Perl virt tools ..................... "
997 if test "x$HAVE_TOOLS_TRUE" = "x"; then echo "yes"; else echo "no"; fi
998 echo -n "virt-resize ......................... "
999 if test "x$HAVE_OCAML_TRUE" = "x" && test "x$HAVE_OCAML_PCRE_TRUE" = "x"; then echo "yes"; else echo "no"; fi
1000 echo "FUSE filesystem ..................... $enable_fuse"
1001 echo
1002 echo "If any optional component is configured 'no' when you expected 'yes'"
1003 echo "then you should check the preceeding messages."
1004 echo
1005 echo "Please report bugs back to the mailing list:"
1006 echo "http://www.redhat.com/mailman/listinfo/libguestfs"
1007 echo
1008 echo "Next you should type 'make' to build the package,"
1009 echo "then 'make check' to run the tests."
1010 echo "------------------------------------------------------------"