Version 1.1.1.
[hivex.git] / configure.ac
1 # hivex
2 # Copyright (C) 2009-2010 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([hivex_major],   [1])
20 m4_define([hivex_minor],   [1])
21 m4_define([hivex_release], [1])
22 # extra can be any string
23 m4_define([hivex_extra],   [])
24
25 AC_INIT([hivex],hivex_major.hivex_minor.hivex_release[]hivex_extra)
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],[hivex_major],[Major version number])
36 AC_DEFINE([PACKAGE_VERSION_MINOR],[hivex_minor],[Minor version number])
37 AC_DEFINE([PACKAGE_VERSION_RELEASE],[hivex_release],[Release number])
38 AC_DEFINE([PACKAGE_VERSION_EXTRA],["hivex_extra"],[Extra version string])
39
40 gl_EARLY
41 gl_INIT
42
43 AC_PROG_LIBTOOL
44
45 dnl Check for basic C environment.
46 AC_PROG_CC_STDC
47 AC_PROG_INSTALL
48 AC_PROG_CPP
49
50 AC_ARG_ENABLE([gcc-warnings],
51   [AS_HELP_STRING([--enable-gcc-warnings],
52                   [turn on lots of GCC warnings (for developers)])],
53   [case $enableval in
54      yes|no) ;;
55      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
56    esac
57    gl_gcc_warnings=$enableval],
58   [gl_gcc_warnings=no]
59 )
60
61 if test "$gl_gcc_warnings" = yes; then
62   gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
63   AC_SUBST([WERROR_CFLAGS])
64
65   nw=
66   # This, $nw, is the list of warnings we disable.
67   nw="$nw -Wdeclaration-after-statement" # too useful to forbid
68   nw="$nw -Waggregate-return"       # anachronistic
69   nw="$nw -Wc++-compat"             # We don't care about C++ compilers
70   nw="$nw -Wundef"                  # Warns on '#if GNULIB_FOO' etc in gnulib
71   nw="$nw -Wtraditional"            # Warns on #elif which we use often
72   nw="$nw -Wcast-qual"              # Too many warnings for now
73   nw="$nw -Wconversion"             # Too many warnings for now
74   nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
75   nw="$nw -Wsign-conversion"        # Too many warnings for now
76   nw="$nw -Wtraditional-conversion" # Too many warnings for now
77   nw="$nw -Wunreachable-code"       # Too many warnings for now
78   nw="$nw -Wpadded"                 # Our structs are not padded
79   nw="$nw -Wredundant-decls"        # openat.h declares e.g., mkdirat
80   nw="$nw -Wlogical-op"             # any use of fwrite provokes this
81   nw="$nw -Wvla"                    # two warnings in mount.c
82   # things I might fix soon:
83   nw="$nw -Wmissing-format-attribute" # daemon.h's asprintf_nowarn
84   nw="$nw -Winline"                 # daemon.h's asprintf_nowarn
85   nw="$nw -Wshadow"                 # numerous, plus we're not unanimous
86   # ?? -Wstrict-overflow
87   nw="$nw -Wunsafe-loop-optimizations" # just a warning that an optimization
88                                     # was not possible, safe to ignore
89   nw="$nw -Wpacked"                 # Allow attribute((packed)) on structs
90
91   gl_MANYWARN_ALL_GCC([ws])
92   gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
93   for w in $ws; do
94     gl_WARN_ADD([$w])
95   done
96   gl_WARN_ADD([-Wno-unused-parameter]) # stubs.c
97   gl_WARN_ADD([-Wno-jump-misses-init]) # stubs.c
98   gl_WARN_ADD([-Wno-unused-variable]) # FIXME: only temporary, for guestfs_protocol.c, etc
99
100   # In spite of excluding -Wlogical-op above, it is enabled, as of
101   # gcc 4.5.0 20090517, and it provokes warnings in cat.c, dd.c, truncate.c
102   gl_WARN_ADD([-Wno-logical-op])
103
104   gl_WARN_ADD([-fdiagnostics-show-option])
105
106   AC_SUBST([WARN_CFLAGS])
107
108   AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
109   AC_DEFINE([_FORTIFY_SOURCE], [2],
110     [enable compile-time and run-time bounds-checking, and some warnings])
111   AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
112 fi
113
114 AC_C_PROTOTYPES
115 test "x$U" != "x" && AC_MSG_ERROR([Compiler not ANSI compliant])
116
117 AM_PROG_CC_C_O
118
119 dnl Check support for 64 bit file offsets.
120 AC_SYS_LARGEFILE
121
122 dnl Check sizeof long.
123 AC_CHECK_SIZEOF([long])
124
125 dnl Headers.
126 AC_CHECK_HEADERS([endian.h byteswap.h])
127
128 dnl Check for pod2man and pod2text.
129 AC_CHECK_PROG([POD2MAN],[pod2man],[pod2man],[no])
130 test "x$POD2MAN" = "xno" &&
131      AC_MSG_ERROR([pod2man must be installed])
132 AC_CHECK_PROG([POD2TEXT],[pod2text],[pod2text],[no])
133 test "x$POD2TEXT" = "xno" &&
134      AC_MSG_ERROR([pod2text must be installed])
135
136 dnl Readline.
137 AC_ARG_WITH([readline],
138     [AS_HELP_STRING([--with-readline],
139         [support fancy command line editing @<:@default=check@:>@])],
140     [],
141     [with_readline=check])
142
143 LIBREADLINE=
144 AS_IF([test "x$with_readline" != xno],
145     [AC_CHECK_LIB([readline], [main],
146         [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
147          AC_DEFINE([HAVE_LIBREADLINE], [1],
148                    [Define if you have libreadline])
149         ],
150         [if test "x$with_readline" != xcheck; then
151          AC_MSG_FAILURE(
152              [--with-readline was given, but test for readline failed])
153          fi
154         ], -lncurses)])
155
156 dnl For i18n.
157 AM_GNU_GETTEXT([external])
158 AM_GNU_GETTEXT_VERSION([0.17])
159
160 dnl libxml2.
161 PKG_CHECK_MODULES([LIBXML2], [libxml-2.0])
162 AC_SUBST([LIBXML2_CFLAGS])
163 AC_SUBST([LIBXML2_LIBS])
164
165 dnl Check for OCaml (optional, for OCaml bindings).
166 AC_PROG_OCAML
167 AC_PROG_FINDLIB
168 AM_CONDITIONAL([HAVE_OCAML],[test "x$OCAMLC" != "xno" -a "x$OCAMLFIND" != "xno"])
169
170 dnl Check for Perl (optional, for Perl bindings).
171 dnl XXX This isn't quite right, we should check for Perl devel library.
172 AC_CHECK_PROG([PERL],[perl],[perl],[no])
173
174 dnl Check for Perl modules that must be present to compile and
175 dnl test the Perl bindings.
176 missing_perl_modules=no
177 for pm in Test::More Test::Pod Test::Pod::Coverage ExtUtils::MakeMaker; do
178     AC_MSG_CHECKING([for $pm])
179     if ! perl -M$pm -e1 >/dev/null 2>&1; then
180         AC_MSG_RESULT([no])
181         missing_perl_modules=yes
182     else
183         AC_MSG_RESULT([yes])
184     fi
185 done
186 if test "x$missing_perl_modules" = "xyes"; then
187     AC_MSG_WARN([some Perl modules required to compile or test the Perl bindings are missing])
188 fi
189
190 AM_CONDITIONAL([HAVE_PERL],
191     [test "x$PERL" != "xno" -a "x$missing_perl_modules" != "xyes"])
192
193 dnl Check for Python (optional, for Python bindings).
194 AC_CHECK_PROG([PYTHON],[python],[python],[no])
195
196 PYTHON_PREFIX=
197 PYTHON_VERSION=
198 PYTHON_INCLUDEDIR=
199 PYTHON_SITE_PACKAGES=
200
201 if test "x$PYTHON" != "xno"; then
202     PYTHON_PREFIX=`$PYTHON -c "import sys; print sys.prefix"`
203     PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[[0:3]]"`
204     for d in \
205         $PYTHON_PREFIX/include/python$PYTHON_VERSION \
206         /usr/include/python$PYTHON_VERSION \
207         /usr/local/include/python$PYTHON_VERSION
208     do
209         AC_MSG_CHECKING([Python.h in $d])
210         if test -r "$d/Python.h"; then
211             AC_MSG_RESULT([found])
212             PYTHON_INCLUDEDIR=$d
213             break
214         fi
215         AC_MSG_RESULT([not found])
216     done
217     for d in \
218         $PYTHON_PREFIX/lib64/python$PYTHON_VERSION/site-packages \
219         $PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages \
220         /usr/lib64/python$PYTHON_VERSION/site-packages \
221         /usr/lib/python$PYTHON_VERSION/site-packages \
222         /usr/local/lib/python$PYTHON_VERSION/site-packages
223     do
224         AC_MSG_CHECKING([for $d])
225         if test -d "$d"; then
226             AC_MSG_RESULT([found])
227             PYTHON_SITE_PACKAGES=$d
228             break
229         fi
230         AC_MSG_RESULT([not found])
231     done
232 fi
233
234 AC_SUBST(PYTHON_PREFIX)
235 AC_SUBST(PYTHON_VERSION)
236 AC_SUBST(PYTHON_INCLUDEDIR)
237 AC_SUBST(PYTHON_SITE_PACKAGES)
238
239 AM_CONDITIONAL([HAVE_PYTHON],
240     [test "x$PYTHON_INCLUDEDIR" != "x" -a "x$PYTHON_SITE_PACKAGES" != "x"])
241
242 dnl Check for Ruby and rake (optional, for Ruby bindings).
243 AC_CHECK_LIB([ruby],[ruby_init],[HAVE_LIBRUBY=1],[HAVE_LIBRUBY=0])
244 AC_CHECK_PROG([RAKE],[rake],[rake],[no])
245
246 AM_CONDITIONAL([HAVE_RUBY],
247     [test "x$RAKE" != "xno" -a -n "$HAVE_LIBRUBY"])
248
249 dnl Check for Java.
250 AC_ARG_WITH(java_home,
251     [AS_HELP_STRING([--with-java-home],
252         [specify path to JDK directory @<:@default=check@:>@])],
253     [],
254     [with_java_home=check])
255
256 if test "x$with_java_home" != "xno"; then
257     if test "x$with_java_home" != "xyes" -a "x$with_java_home" != "xcheck"
258     then
259         # Reject unsafe characters in $JAVA_HOME
260         jh_lf='
261 '
262         case $JAVA_HOME in
263           *[\\\"\#\$\&\'\`$jh_lf\ \     ]*)
264             AC_MSG_FAILURE([unsafe \$JAVA_HOME directory (use --with-java-home=no to disable Java support)]);;
265         esac
266         if test -d "$with_java_home"; then
267             JAVA_HOME="$with_java_home"
268         else
269             AC_MSG_FAILURE([$with_java_home is not a directory (use --with-java-home=no to disable Java support)])
270         fi
271     fi
272
273     if test "x$JAVA_HOME" = "x"; then
274         # Look for Java in some likely locations.
275         for d in \
276             /usr/lib/jvm/java \
277             /usr/lib/jvm/java-6-openjdk
278         do
279             if test -d $d -a -f $d/bin/java; then
280                 JAVA_HOME=$d
281                 break
282             fi
283         done
284     fi
285
286     if test "x$JAVA_HOME" != "x"; then
287         AC_MSG_CHECKING(for JDK in $JAVA_HOME)
288         if test ! -x "$JAVA_HOME/bin/java"; then
289             AC_MSG_ERROR([missing $JAVA_HOME/bin/java binary (use --with-java-home=no to disable Java support)])
290         else
291             JAVA="$JAVA_HOME/bin/java"
292         fi
293         if test ! -x "$JAVA_HOME/bin/javac"; then
294             AC_MSG_ERROR([missing $JAVA_HOME/bin/javac binary])
295         else
296             JAVAC="$JAVA_HOME/bin/javac"
297         fi
298         if test ! -x "$JAVA_HOME/bin/javah"; then
299             AC_MSG_ERROR([missing $JAVA_HOME/bin/javah binary])
300         else
301             JAVAH="$JAVA_HOME/bin/javah"
302         fi
303         if test ! -x "$JAVA_HOME/bin/javadoc"; then
304             AC_MSG_ERROR([missing $JAVA_HOME/bin/javadoc binary])
305         else
306             JAVADOC="$JAVA_HOME/bin/javadoc"
307         fi
308         if test ! -x "$JAVA_HOME/bin/jar"; then
309             AC_MSG_ERROR([missing $JAVA_HOME/bin/jar binary])
310         else
311             JAR="$JAVA_HOME/bin/jar"
312         fi
313         java_version=`$JAVA -version 2>&1 | grep "java version"`
314         AC_MSG_RESULT(found $java_version in $JAVA_HOME)
315
316         dnl Find jni.h.
317         AC_MSG_CHECKING([for jni.h])
318         if test -f "$JAVA_HOME/include/jni.h"; then
319             JNI_CFLAGS="-I$JAVA_HOME/include"
320         else
321             if test "`find $JAVA_HOME -name jni.h`" != ""; then
322                 head=`find $JAVA_HOME -name jni.h | tail -1`
323                 dir=`dirname "$head"`
324                 JNI_CFLAGS="-I$dir"
325             else
326                 AC_MSG_FAILURE([missing jni.h header file])
327             fi
328         fi
329         AC_MSG_RESULT([$JNI_CFLAGS])
330
331         dnl Find jni_md.h.
332         AC_MSG_CHECKING([for jni_md.h])
333         case "$build_os" in
334         *linux*) system="linux" ;;
335         *SunOS*) system="solaris" ;;
336         *cygwin*) system="win32" ;;
337         *) system="$build_os" ;;
338         esac
339         if test -f "$JAVA_HOME/include/$system/jni_md.h"; then
340             JNI_CFLAGS="$JNI_CFLAGS -I$JAVA_HOME/include/$system"
341         else
342             if test "`find $JAVA_HOME -name jni_md.h`" != ""; then
343                 head=`find $JAVA_HOME -name jni_md.h | tail -1`
344                 dir=`dirname "$head"`
345                 JNI_CFLAGS="$JNI_CFLAGS -I$dir"
346             else
347                 AC_MSG_FAILURE([missing jni_md.h header file])
348             fi
349         fi
350         AC_MSG_RESULT([$JNI_CFLAGS])
351
352         dnl Need extra version flag?
353         AC_MSG_CHECKING([extra javac flags])
354         JAVAC_FLAGS=
355         javac_version=`$JAVAC -version 2>&1`
356         case "$javac_version" in
357         *Eclipse*)
358             JAVAC_FLAGS="-source 1.5" ;;
359         esac
360         AC_MSG_RESULT([$JAVAC_FLAGS])
361
362         dnl Where to install jarfiles.
363         dnl XXX How to make it configurable?
364         JAR_INSTALL_DIR=\${prefix}/share/java
365         JNI_INSTALL_DIR=\${libdir}
366
367         dnl JNI version.
368         jni_major_version=`echo "$VERSION" | awk -F. '{print $1}'`
369         jni_minor_version=`echo "$VERSION" | awk -F. '{print $2}'`
370         jni_micro_version=`echo "$VERSION" | awk -F. '{print $3}'`
371         JNI_VERSION_INFO=`expr "$jni_major_version" + "$jni_minor_version"`":$jni_micro_version:$jni_minor_version"
372     fi
373 fi
374
375 AC_SUBST(JAVA_HOME)
376 AC_SUBST(JAVA)
377 AC_SUBST(JAVAC)
378 AC_SUBST(JAVAH)
379 AC_SUBST(JAVADOC)
380 AC_SUBST(JAR)
381 AC_SUBST(JNI_CFLAGS)
382 AC_SUBST(JAVAC_FLAGS)
383 AC_SUBST(JAR_INSTALL_DIR)
384 AC_SUBST(JNI_INSTALL_DIR)
385 AC_SUBST(JNI_VERSION_INFO)
386
387 AM_CONDITIONAL([HAVE_JAVA],[test -n "$JAVAC"])
388
389 dnl Check for Haskell (GHC).
390 AC_CHECK_PROG([GHC],[ghc],[ghc],[no])
391
392 AM_CONDITIONAL([HAVE_HASKELL],
393     [test "x$GHC" != "xno"])
394
395 dnl Produce output files.
396 AC_CONFIG_HEADERS([config.h])
397 AC_CONFIG_FILES([Makefile
398                  gnulib/lib/Makefile
399                  gnulib/tests/Makefile
400                  hivex.pc
401                  hivex/Makefile
402                  hivex/t/Makefile
403                  hivex/tools/Makefile
404                  po/Makefile.in])
405 AC_OUTPUT
406
407 dnl Produce summary.
408 echo
409 echo
410 echo "------------------------------------------------------------"
411 echo "Thank you for downloading $PACKAGE_STRING"
412 echo
413 echo "This is how we have configured the optional components for you today:"
414 echo
415 echo -n "OCaml bindings ...................... "
416 if test "x$HAVE_OCAML_TRUE" = "x"; then echo "yes"; else echo "no"; fi
417 echo -n "Perl bindings ....................... "
418 if test "x$HAVE_PERL_TRUE" = "x"; then echo "yes"; else echo "no"; fi
419 echo -n "Python bindings ..................... "
420 if test "x$HAVE_PYTHON_TRUE" = "x"; then echo "yes"; else echo "no"; fi
421 echo -n "Ruby bindings ....................... "
422 if test "x$HAVE_RUBY_TRUE" = "x"; then echo "yes"; else echo "no"; fi
423 echo -n "Java bindings ....................... "
424 if test "x$HAVE_JAVA_TRUE" = "x"; then echo "yes"; else echo "no"; fi
425 echo -n "Haskell bindings .................... "
426 if test "x$HAVE_HASKELL" = "x"; then echo "yes"; else echo "no"; fi
427 echo
428 echo "If any optional component is configured 'no' when you expected 'yes'"
429 echo "then you should check the preceeding messages."
430 echo
431 echo "Please report bugs back to the mailing list:"
432 echo "http://www.redhat.com/mailman/listinfo/libguestfs"
433 echo
434 echo "Next you should type 'make' to build the package,"
435 echo "then 'make check' to run the tests."
436 echo "------------------------------------------------------------"