Implement extensible strings with catprintf.
[libguestfs.git] / configure.ac
1 # libguestfs
2 # Copyright (C) 2009 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 AC_INIT([libguestfs],[1.0.11])
19 AM_INIT_AUTOMAKE
20
21 AC_CONFIG_MACRO_DIR([m4])
22
23 AC_PROG_LIBTOOL
24
25 dnl Check for basic C environment.
26 AC_PROG_CC
27 AC_PROG_INSTALL
28 AC_PROG_CPP
29
30 AC_C_PROTOTYPES
31 test "x$U" != "x" && AC_MSG_ERROR([Compiler not ANSI compliant])
32
33 AM_PROG_CC_C_O
34
35 dnl Check support for 64 bit file offsets.
36 AC_SYS_LARGEFILE
37
38 dnl Headers.
39 AC_CHECK_HEADERS([errno.h sys/types.h sys/un.h sys/wait.h sys/socket.h])
40
41 dnl Check for rpcgen and XDR library.  rpcgen is optional.
42 AC_CHECK_PROG([RPCGEN],[rpcgen],[rpcgen],[no])
43 AM_CONDITIONAL([HAVE_RPCGEN],[test "x$RPCGEN" != "xno"])
44 AC_CHECK_LIB([portablexdr],[xdrmem_create],[],[
45         AC_SEARCH_LIBS([xdrmem_create],[rpc xdr nsl])
46         ])
47
48 dnl Check for pod2man and pod2text.
49 AC_CHECK_PROG([POD2MAN],[pod2man],[pod2man],[no])
50 test "x$POD2MAN" = "xno" &&
51      AC_MSG_ERROR([pod2man must be installed])
52 AC_CHECK_PROG([POD2TEXT],[pod2text],[pod2text],[no])
53 test "x$POD2TEXT" = "xno" &&
54      AC_MSG_ERROR([pod2text must be installed])
55
56 dnl Check for QEMU for running binaries on this $host_cpu, fall
57 dnl back to basic 'qemu'.  Allow the user to override it.
58 default_qemu="qemu-system-$host_cpu qemu"
59 # On x86-64, try using KVM first.
60 if test "x$host_cpu" = "xx86_64"; then
61     default_qemu="qemu-kvm $default_qemu"
62 fi
63 AC_ARG_WITH([qemu],
64         [AS_HELP_STRING([--with-qemu],
65           [set default QEMU binary @<:@default=[qemu-kvm] qemu-system-<host> qemu@:>@])],
66         [],
67         [with_qemu="$default_qemu"])
68 AC_PATH_PROGS([QEMU],[$with_qemu],[no],
69         [$PATH$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/sbin])
70 test "x$QEMU" = "xno" && AC_MSG_ERROR([qemu must be installed])
71 AC_DEFINE_UNQUOTED([QEMU],["$QEMU"],[Location of qemu binary.])
72
73 dnl Check for febootstrap etc.
74 AC_CHECK_PROG([FEBOOTSTRAP],
75         [febootstrap],[febootstrap],[no])
76 test "x$FEBOOTSTRAP" = "xno" && \
77      AC_MSG_ERROR([febootstrap must be installed])
78 AC_CHECK_PROG([FEBOOTSTRAP_RUN],
79         [febootstrap-run],[febootstrap-run],[no])
80 test "x$FEBOOTSTRAP_RUN" = "xno" && \
81      AC_MSG_ERROR([febootstrap-run must be installed])
82 AC_CHECK_PROG([FEBOOTSTRAP_MINIMIZE],
83         [febootstrap-minimize],[febootstrap-minimize],[no])
84 test "x$FEBOOTSTRAP_MINIMIZE" = "xno" && \
85      AC_MSG_ERROR([febootstrap-minimize must be installed])
86 AC_CHECK_PROG([FEBOOTSTRAP_TO_INITRAMFS],
87         [febootstrap-to-initramfs],[febootstrap-to-initramfs],[no])
88 test "x$FEBOOTSTRAP_TO_INITRAMFS" = "xno" && \
89      AC_MSG_ERROR([febootstrap-to-initramfs must be installed])
90
91 dnl --with-repo to specify a Fedora repository.
92 AC_ARG_WITH([repo],
93         [AS_HELP_STRING([--with-repo],
94           [set name of Fedora repository @<:@default=fedora-10@:>@])],
95         [],
96         [with_repo=fedora-10])
97 REPO="$with_repo"
98 AC_SUBST(REPO)
99 AC_DEFINE_UNQUOTED([REPO],["$REPO"],[Name of Fedora repository.])
100
101 AC_DEFINE_UNQUOTED([host_cpu],["$host_cpu"],[Host architecture.])
102
103 dnl --with-updates to specify a Fedora updates repository.
104 AC_ARG_WITH([updates],
105         [AS_HELP_STRING([--with-updates],
106           [set name of Fedora updates repository @<:@default=updates-released-f10@:>@])],
107         [],
108         [with_updates=updates-released-f10])
109 UPDATES="$with_updates"
110 AC_SUBST(UPDATES)
111 AC_DEFINE_UNQUOTED([UPDATES],["$UPDATES"],[Name of Fedora updates repository.])
112
113 AC_DEFINE_UNQUOTED([host_cpu],["$host_cpu"],[Host architecture.])
114
115 dnl --with-mirror to specify a local Fedora mirror.
116 AC_ARG_WITH([mirror],
117         [AS_HELP_STRING([--with-mirror],
118           [set URI of a local Fedora mirror])],
119         [],
120         [with_mirror=])
121 MIRROR="$with_mirror"
122 AC_SUBST(MIRROR)
123
124 dnl Readline.
125 AC_ARG_WITH([readline],
126     [AS_HELP_STRING([--with-readline],
127         [support fancy command line editing @<:@default=check@:>@])],
128     [],
129     [with_readline=check])
130
131 LIBREADLINE=
132 AS_IF([test "x$with_readline" != xno],
133     [AC_CHECK_LIB([readline], [main],
134         [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
135          AC_DEFINE([HAVE_LIBREADLINE], [1],
136                    [Define if you have libreadline])
137         ],
138         [if test "x$with_readline" != xcheck; then
139          AC_MSG_FAILURE(
140              [--with-readline was given, but test for readline failed])
141          fi
142         ], -lncurses)])
143
144 dnl Check for OCaml (optional, for OCaml bindings).
145 AC_PROG_OCAML
146 AC_PROG_FINDLIB
147 AM_CONDITIONAL([HAVE_OCAML],[test "x$OCAMLC" != "xno" -a "x$OCAMLFIND" != "xno"])
148
149 dnl Check for Perl (optional, for Perl bindings).
150 dnl XXX This isn't quite right, we should check for Perl devel library.
151 AC_CHECK_PROG([PERL],[perl],[perl],[no])
152
153 dnl Check for Perl modules that must be present to compile and
154 dnl test the Perl bindings.
155 missing_perl_modules=no
156 for pm in Test::More Test::Pod Test::Pod::Coverage ExtUtils::MakeMaker; do
157     AC_MSG_CHECKING([for $pm])
158     if ! perl -M$pm >/dev/null 2>&1; then
159         AC_MSG_RESULT([no])
160         missing_perl_modules=yes
161     else
162         AC_MSG_RESULT([yes])
163     fi
164 done
165 if test "x$missing_perl_modules" = "xyes"; then
166     AC_MSG_WARN([some Perl modules required to compile or test the Perl bindings are missing])
167 fi
168
169 AM_CONDITIONAL([HAVE_PERL],
170     [test "x$PERL" != "xno" -a "x$missing_perl_modules" != "xyes"])
171
172 dnl Check for Python (optional, for Python bindings).
173 AC_CHECK_PROG([PYTHON],[python],[python],[no])
174
175 PYTHON_PREFIX=
176 PYTHON_VERSION=
177 PYTHON_INCLUDEDIR=
178 PYTHON_SITE_PACKAGES=
179
180 if test "x$PYTHON" != "xno"; then
181     PYTHON_PREFIX=`$PYTHON -c "import sys; print sys.prefix"`
182     PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[[0:3]]"`
183     for d in \
184         $PYTHON_PREFIX/include/python$PYTHON_VERSION \
185         /usr/include/python$PYTHON_VERSION \
186         /usr/local/include/python$PYTHON_VERSION
187     do
188         AC_MSG_CHECKING([Python.h in $d])
189         if test -r "$d/Python.h"; then
190             AC_MSG_RESULT([found])
191             PYTHON_INCLUDEDIR=$d
192             break
193         fi
194         AC_MSG_RESULT([not found])
195     done
196     for d in \
197         $PYTHON_PREFIX/lib64/python$PYTHON_VERSION/site-packages \
198         $PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages \
199         /usr/lib64/python$PYTHON_VERSION/site-packages \
200         /usr/lib/python$PYTHON_VERSION/site-packages \
201         /usr/local/lib/python$PYTHON_VERSION/site-packages
202     do
203         AC_MSG_CHECKING([for $d])
204         if test -d "$d"; then
205             AC_MSG_RESULT([found])
206             PYTHON_SITE_PACKAGES=$d
207             break
208         fi
209         AC_MSG_RESULT([not found])
210     done
211 fi
212
213 AC_SUBST(PYTHON_PREFIX)
214 AC_SUBST(PYTHON_VERSION)
215 AC_SUBST(PYTHON_INCLUDEDIR)
216 AC_SUBST(PYTHON_SITE_PACKAGES)
217
218 AM_CONDITIONAL([HAVE_PYTHON],
219     [test "x$PYTHON_INCLUDEDIR" != "x" -a "x$PYTHON_SITE_PACKAGES" != "x"])
220
221 dnl Check for Ruby and rake (optional, for Ruby bindings).
222 AC_CHECK_LIB([ruby],[ruby_init],[HAVE_LIBRUBY=1],[HAVE_LIBRUBY=0])
223 AC_CHECK_PROG([RAKE],[rake],[rake],[no])
224
225 AM_CONDITIONAL([HAVE_RUBY],
226     [test "x$RAKE" != "xno" -a -n "$HAVE_LIBRUBY"])
227
228 dnl Check for Java.
229 AC_ARG_WITH(java_home,
230     [AS_HELP_STRING([--with-java-home],
231         [specify path to JDK directory @<:@default=check@:>@])],
232     [],
233     [with_java_home=check])
234
235 if test "x$with_java_home" != "xno"; then
236     if test "x$with_java_home" != "xyes" -a "x$with_java_home" != "xcheck"
237     then
238         if test -d "$with_java_home"; then
239             JAVA_HOME="$with_java_home"
240         else
241             AC_MSG_FAILURE([$with_java_home is not a directory (use --with-java-home=no to disable Java support)])
242         fi
243     fi
244     if test "x$JAVA_HOME" = "x"; then
245         JAVA_HOME=/usr/lib/jvm/java
246     fi
247     AC_MSG_CHECKING(for JDK in $JAVA_HOME)
248     if test ! -x "$JAVA_HOME/bin/java"; then
249         AC_MSG_ERROR([missing $JAVA_HOME/bin/java binary (use --with-java-home=no to disable Java support)])
250     else
251         JAVA="$JAVA_HOME/bin/java"
252     fi
253     if test ! -x "$JAVA_HOME/bin/javac"; then
254         AC_MSG_ERROR([missing $JAVA_HOME/bin/javac binary])
255     else
256         JAVAC="$JAVA_HOME/bin/javac"
257     fi
258     if test ! -x "$JAVA_HOME/bin/javah"; then
259         AC_MSG_ERROR([missing $JAVA_HOME/bin/javah binary])
260     else
261         JAVAH="$JAVA_HOME/bin/javah"
262     fi
263     if test ! -x "$JAVA_HOME/bin/javadoc"; then
264         AC_MSG_ERROR([missing $JAVA_HOME/bin/javadoc binary])
265     else
266         JAVADOC="$JAVA_HOME/bin/javadoc"
267     fi
268     if test ! -x "$JAVA_HOME/bin/jar"; then
269         AC_MSG_ERROR([missing $JAVA_HOME/bin/jar binary])
270     else
271         JAR="$JAVA_HOME/bin/jar"
272     fi
273     java_version=`$JAVA -version 2>&1 | grep "java version"`
274     AC_MSG_RESULT(found $java_version in $JAVA_HOME)
275
276     dnl Find jni.h.
277     AC_MSG_CHECKING([for jni.h])
278     if test -f "$JAVA_HOME/include/jni.h"; then
279         JNI_CFLAGS="-I$JAVA_HOME/include"
280     else
281     if test "`find $JAVA_HOME -name jni.h`" != ""; then
282         head=`find $JAVA_HOME -name jni.h | tail -1`
283         dir=`dirname $head`
284         JNI_CFLAGS="-I$dir"
285     else
286         AC_MSG_FAILURE([missing jni.h header file])
287     fi
288     fi
289     AC_MSG_RESULT([$JNI_CFLAGS])
290
291     dnl Find jni_md.h.
292     AC_MSG_CHECKING([for jni_md.h])
293     case "$build_os" in
294     *linux*) system="linux" ;;
295     *SunOS*) system="solaris" ;;
296     *cygwin*) system="win32" ;;
297     *) system="$build_os" ;;
298     esac
299     if test -f "$JAVA_HOME/include/$system/jni_md.h"; then
300         JNI_CFLAGS="$JNI_CFLAGS -I$JAVA_HOME/include/$system"
301     else
302     if test "`find $JAVA_HOME -name jni_md.h`" != ""; then
303         head=`find $JAVA_HOME -name jni_md.h | tail -1`
304         dir=`dirname $head`
305         JNI_CFLAGS="$JNI_CFLAGS -I$dir"
306     else
307         AC_MSG_FAILURE([missing jni_md.h header file])
308     fi
309     fi
310     AC_MSG_RESULT([$JNI_CFLAGS])
311
312     dnl Need extra version flag?
313     AC_MSG_CHECKING([extra javac flags])
314     JAVAC_FLAGS=
315     javac_version=`$JAVAC -version 2>&1`
316     case "$javac_version" in
317     *Eclipse*)
318         JAVAC_FLAGS="-source 1.5" ;;
319     esac
320     AC_MSG_RESULT([$JAVAC_FLAGS])
321
322     dnl Where to install jarfiles.
323     dnl XXX How to make it configurable?
324     JAR_INSTALL_DIR=\${prefix}/share/java
325     JNI_INSTALL_DIR=\${libdir}
326
327     dnl JNI version.
328     jni_major_version=`echo $VERSION | awk -F. '{print $1}'`
329     jni_minor_version=`echo $VERSION | awk -F. '{print $2}'`
330     jni_micro_version=`echo $VERSION | awk -F. '{print $3}'`
331     JNI_VERSION_INFO=`expr $jni_major_version + $jni_minor_version`:$jni_micro_version:$jni_minor_version
332 fi
333
334 AC_SUBST(JAVA_HOME)
335 AC_SUBST(JAVA)
336 AC_SUBST(JAVAC)
337 AC_SUBST(JAVAH)
338 AC_SUBST(JAVADOC)
339 AC_SUBST(JAR)
340 AC_SUBST(JNI_CFLAGS)
341 AC_SUBST(JAVAC_FLAGS)
342 AC_SUBST(JAR_INSTALL_DIR)
343 AC_SUBST(JNI_INSTALL_DIR)
344 AC_SUBST(JNI_VERSION_INFO)
345
346 AM_CONDITIONAL([HAVE_JAVA],[test -n "$JAVAC"])
347
348 dnl Run in subdirs.
349 AC_CONFIG_SUBDIRS([daemon])
350
351 dnl Produce output files.
352 AC_CONFIG_HEADERS([config.h])
353 AC_CONFIG_FILES([Makefile src/Makefile fish/Makefile examples/Makefile
354                  images/Makefile
355                  ocaml/Makefile ocaml/examples/Makefile
356                  perl/Makefile
357                  python/Makefile
358                  ruby/Makefile ruby/Rakefile
359                  java/Makefile
360                  make-initramfs.sh update-initramfs.sh
361                  libguestfs.spec libguestfs.pc
362                  ocaml/META perl/Makefile.PL])
363 AC_OUTPUT
364
365 dnl WTF?
366 chmod +x make-initramfs.sh update-initramfs.sh
367
368 dnl Produce summary.
369 echo
370 echo
371 echo "------------------------------------------------------------"
372 echo "Thank you for downloading $PACKAGE_STRING"
373 echo
374 echo "This is how we have configured the optional components for you today:"
375 echo
376 echo    "QEMU ................................ $QEMU"
377 echo -n "OCaml bindings ...................... "
378 if test "x$HAVE_OCAML_TRUE" = "x"; then echo "yes"; else echo "no"; fi
379 echo -n "Perl bindings ....................... "
380 if test "x$HAVE_PERL_TRUE" = "x"; then echo "yes"; else echo "no"; fi
381 echo -n "Python bindings ..................... "
382 if test "x$HAVE_PYTHON_TRUE" = "x"; then echo "yes"; else echo "no"; fi
383 echo -n "Ruby bindings ....................... "
384 if test "x$HAVE_RUBY_TRUE" = "x"; then echo "yes"; else echo "no"; fi
385 echo -n "Java bindings ....................... "
386 if test "x$HAVE_JAVA_TRUE" = "x"; then echo "yes"; else echo "no"; fi
387 echo
388 echo "If any optional component is configured 'no' when you expected 'yes'"
389 echo "then you should check the preceeding messages."
390 echo
391 echo "Please report bugs back to the fedora-virt mailing list:"
392 echo "http://www.redhat.com/mailman/listinfo/fedora-virt"
393 echo
394 echo "Next you should type 'make' to build the package,"
395 echo "then 'make check' to run the tests."
396 echo "------------------------------------------------------------"