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