maint: normalize to exactly one newline at EOF
[hivex.git] / configure.ac
1 # hivex
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([hivex_major],   [1])
20 m4_define([hivex_minor],   [2])
21 m4_define([hivex_release], [7])
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 AM_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   nw="$nw -Wlong-long"              # Allow long long since it's required
91                                     # by xstrtoll.
92
93   gl_MANYWARN_ALL_GCC([ws])
94   gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
95   for w in $ws; do
96     gl_WARN_ADD([$w])
97   done
98   gl_WARN_ADD([-Wno-unused-parameter]) # stubs.c
99   gl_WARN_ADD([-Wno-jump-misses-init]) # stubs.c
100   gl_WARN_ADD([-Wno-unused-variable]) # FIXME: only temporary, for guestfs_protocol.c, etc
101
102   # In spite of excluding -Wlogical-op above, it is enabled, as of
103   # gcc 4.5.0 20090517, and it provokes warnings in cat.c, dd.c, truncate.c
104   gl_WARN_ADD([-Wno-logical-op])
105
106   gl_WARN_ADD([-fdiagnostics-show-option])
107
108   AC_SUBST([WARN_CFLAGS])
109
110   AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
111   AC_DEFINE([_FORTIFY_SOURCE], [2],
112     [enable compile-time and run-time bounds-checking, and some warnings])
113   AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
114 fi
115
116 AC_C_PROTOTYPES
117 test "x$U" != "x" && AC_MSG_ERROR([Compiler not ANSI compliant])
118
119 AM_PROG_CC_C_O
120
121 dnl Work out how to specify the linker script to the linker.
122 VERSION_SCRIPT_FLAGS=-Wl,--version-script=
123 `/usr/bin/ld --help 2>&1 | grep -- --version-script >/dev/null` || \
124     VERSION_SCRIPT_FLAGS="-Wl,-M -Wl,"
125 AC_SUBST(VERSION_SCRIPT_FLAGS)
126
127 dnl Check support for 64 bit file offsets.
128 AC_SYS_LARGEFILE
129
130 dnl Check sizeof long.
131 AC_CHECK_SIZEOF([long])
132
133 dnl Headers.
134 AC_CHECK_HEADERS([endian.h byteswap.h])
135
136 dnl Check for pod2man and pod2text.
137 AC_CHECK_PROG([POD2MAN],[pod2man],[pod2man],[no])
138 test "x$POD2MAN" = "xno" &&
139      AC_MSG_ERROR([pod2man must be installed])
140 AC_CHECK_PROG([POD2TEXT],[pod2text],[pod2text],[no])
141 test "x$POD2TEXT" = "xno" &&
142      AC_MSG_ERROR([pod2text must be installed])
143
144 dnl Readline.
145 AC_ARG_WITH([readline],
146     [AS_HELP_STRING([--with-readline],
147         [support fancy command line editing @<:@default=check@:>@])],
148     [],
149     [with_readline=check])
150
151 LIBREADLINE=
152 AS_IF([test "x$with_readline" != xno],
153     [AC_CHECK_LIB([readline], [main],
154         [AC_SUBST([LIBREADLINE], ["-lreadline"])
155          AC_DEFINE([HAVE_LIBREADLINE], [1],
156                    [Define if you have libreadline])
157         ],
158         [if test "x$with_readline" != xcheck; then
159          AC_MSG_FAILURE(
160              [--with-readline was given, but test for readline failed])
161          fi
162         ])])
163
164 dnl For i18n.
165 AM_GNU_GETTEXT([external])
166 AM_GNU_GETTEXT_VERSION([0.17])
167
168 dnl libxml2.
169 PKG_CHECK_MODULES([LIBXML2], [libxml-2.0])
170 AC_SUBST([LIBXML2_CFLAGS])
171 AC_SUBST([LIBXML2_LIBS])
172
173 dnl Check for OCaml (optional, for OCaml bindings).
174 AC_PROG_OCAML
175 AC_PROG_FINDLIB
176 AM_CONDITIONAL([HAVE_OCAML],[test "x$OCAMLC" != "xno" -a "x$OCAMLFIND" != "xno"])
177 AM_CONDITIONAL([HAVE_OCAMLOPT], [test "x$OCAMLOPT" != "xno" -a "x$OCAMLFIND" != "xno"])
178
179 if test "x$OCAMLC" != "xno"; then
180     dnl Check if we have caml/unixsupport.h header (OCaml bindings only).
181     old_CFLAGS="$CFLAGS"
182     CFLAGS="$CFLAGS -I$OCAMLLIB"
183     AC_CHECK_HEADERS([caml/unixsupport.h],[],[],
184     [
185     #include <caml/config.h>
186     #include <caml/mlvalues.h>
187     ])
188     CFLAGS="$old_CFLAGS"
189
190     dnl Do we have function caml_raise_with_args?
191     f=caml_raise_with_args
192     AC_MSG_CHECKING([for function $f])
193     echo "char $f (); char foo() { return $f (); }" > conftest.c
194     rm -f conftest_ml.ml
195     touch conftest_ml.ml
196     if $OCAMLC -c conftest.c 2>/dev/null && \
197        $OCAMLC -c conftest_ml.ml 2>/dev/null && \
198        $OCAMLC conftest.o conftest_ml.cmo -o conftest 2>/dev/null ; then
199         AC_DEFINE([HAVE_CAML_RAISE_WITH_ARGS],[1],
200                   [Defined if function caml_raise_with_args exists.])
201         AC_MSG_RESULT([found])
202     else
203         AC_MSG_RESULT([not found])
204     fi
205     rm -f conftest conftest.* conftest_ml.*
206 fi
207
208 dnl Check for Perl (optional, for Perl bindings).
209 dnl XXX This isn't quite right, we should check for Perl devel library.
210 AC_CHECK_PROG([PERL],[perl],[perl],[no])
211
212 dnl Check for Perl modules that must be present to compile and
213 dnl test the Perl bindings.
214 missing_perl_modules=no
215 for pm in Test::More ExtUtils::MakeMaker IO::Stringy; do
216     AC_MSG_CHECKING([for $pm])
217     if ! perl -M$pm -e1 >/dev/null 2>&1; then
218         AC_MSG_RESULT([no])
219         missing_perl_modules=yes
220     else
221         AC_MSG_RESULT([yes])
222     fi
223 done
224 if test "x$missing_perl_modules" = "xyes"; then
225     AC_MSG_WARN([some Perl modules required to compile or test the Perl bindings are missing])
226 fi
227
228 AM_CONDITIONAL([HAVE_PERL],
229     [test "x$PERL" != "xno" -a "x$missing_perl_modules" != "xyes"])
230
231 dnl Check for Python (optional, for Python bindings).
232 AC_CHECK_PROG([PYTHON],[python],[python],[no])
233
234 PYTHON_PREFIX=
235 PYTHON_VERSION=
236
237 if test "x$PYTHON" != "xno"; then
238     PYTHON_PREFIX=`$PYTHON -c "import sys; print sys.prefix"`
239     PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[[0:3]]"`
240
241     AC_MSG_CHECKING([for Python include path])
242     if test -z "$PYTHON_INCLUDEDIR"; then
243         python_path=`$PYTHON -c "import distutils.sysconfig; \
244                                  print (distutils.sysconfig.get_python_inc ());"`
245         PYTHON_INCLUDEDIR=$python_path
246     fi
247     AC_MSG_RESULT([$PYTHON_INCLUDEDIR])
248
249     AC_MSG_CHECKING([for Python site-packages path])
250     if test -z "$PYTHON_SITE_PACKAGES"; then
251         PYTHON_SITE_PACKAGES=`$PYTHON -c "import distutils.sysconfig; \
252                 print (distutils.sysconfig.get_python_lib(1,0));"`
253     fi
254     AC_MSG_RESULT([$PYTHON_SITE_PACKAGES])
255
256     old_LIBS="$LIBS"
257     LIBS="$LIBS -lpython$PYTHON_VERSION"
258     AC_CHECK_FUNCS([PyCapsule_New])
259     LIBS="$old_LIBS"
260 fi
261
262 AC_SUBST(PYTHON_PREFIX)
263 AC_SUBST(PYTHON_VERSION)
264 AC_SUBST(PYTHON_INCLUDEDIR)
265 AC_SUBST(PYTHON_SITE_PACKAGES)
266
267 AM_CONDITIONAL([HAVE_PYTHON],
268     [test "x$PYTHON_INCLUDEDIR" != "x" -a "x$PYTHON_SITE_PACKAGES" != "x"])
269
270 dnl dnl Check for Ruby and rake (optional, for Ruby bindings).
271 dnl AC_CHECK_LIB([ruby],[ruby_init],[HAVE_LIBRUBY=1],[HAVE_LIBRUBY=0])
272 dnl AC_CHECK_PROG([RAKE],[rake],[rake],[no])
273
274 dnl AM_CONDITIONAL([HAVE_RUBY],
275 dnl     [test "x$RAKE" != "xno" -a -n "$HAVE_LIBRUBY"])
276
277 dnl dnl Check for Java.
278 dnl AC_ARG_WITH(java_home,
279 dnl     [AS_HELP_STRING([--with-java-home],
280 dnl         [specify path to JDK directory @<:@default=check@:>@])],
281 dnl     [],
282 dnl     [with_java_home=check])
283
284 dnl if test "x$with_java_home" != "xno"; then
285 dnl     if test "x$with_java_home" != "xyes" -a "x$with_java_home" != "xcheck"
286 dnl     then
287 dnl         # Reject unsafe characters in $JAVA_HOME
288 dnl         jh_lf='
289 dnl '
290 dnl         case $JAVA_HOME in
291 dnl           *[\\\"\#\$\&\'\`$jh_lf\ \ ]*)
292 dnl             AC_MSG_FAILURE([unsafe \$JAVA_HOME directory (use --with-java-home=no to disable Java support)]);;
293 dnl         esac
294 dnl         if test -d "$with_java_home"; then
295 dnl             JAVA_HOME="$with_java_home"
296 dnl         else
297 dnl             AC_MSG_FAILURE([$with_java_home is not a directory (use --with-java-home=no to disable Java support)])
298 dnl         fi
299 dnl     fi
300
301 dnl     if test "x$JAVA_HOME" = "x"; then
302 dnl         # Look for Java in some likely locations.
303 dnl         for d in \
304 dnl             /usr/lib/jvm/java \
305 dnl             /usr/lib/jvm/java-6-openjdk
306 dnl         do
307 dnl             if test -d $d -a -f $d/bin/java; then
308 dnl                 JAVA_HOME=$d
309 dnl                 break
310 dnl             fi
311 dnl         done
312 dnl     fi
313
314 dnl     if test "x$JAVA_HOME" != "x"; then
315 dnl         AC_MSG_CHECKING(for JDK in $JAVA_HOME)
316 dnl         if test ! -x "$JAVA_HOME/bin/java"; then
317 dnl             AC_MSG_ERROR([missing $JAVA_HOME/bin/java binary (use --with-java-home=no to disable Java support)])
318 dnl         else
319 dnl             JAVA="$JAVA_HOME/bin/java"
320 dnl         fi
321 dnl         if test ! -x "$JAVA_HOME/bin/javac"; then
322 dnl             AC_MSG_ERROR([missing $JAVA_HOME/bin/javac binary])
323 dnl         else
324 dnl             JAVAC="$JAVA_HOME/bin/javac"
325 dnl         fi
326 dnl         if test ! -x "$JAVA_HOME/bin/javah"; then
327 dnl             AC_MSG_ERROR([missing $JAVA_HOME/bin/javah binary])
328 dnl         else
329 dnl             JAVAH="$JAVA_HOME/bin/javah"
330 dnl         fi
331 dnl         if test ! -x "$JAVA_HOME/bin/javadoc"; then
332 dnl             AC_MSG_ERROR([missing $JAVA_HOME/bin/javadoc binary])
333 dnl         else
334 dnl             JAVADOC="$JAVA_HOME/bin/javadoc"
335 dnl         fi
336 dnl         if test ! -x "$JAVA_HOME/bin/jar"; then
337 dnl             AC_MSG_ERROR([missing $JAVA_HOME/bin/jar binary])
338 dnl         else
339 dnl             JAR="$JAVA_HOME/bin/jar"
340 dnl         fi
341 dnl         java_version=`$JAVA -version 2>&1 | grep "java version"`
342 dnl         AC_MSG_RESULT(found $java_version in $JAVA_HOME)
343
344 dnl         dnl Find jni.h.
345 dnl         AC_MSG_CHECKING([for jni.h])
346 dnl         if test -f "$JAVA_HOME/include/jni.h"; then
347 dnl             JNI_CFLAGS="-I$JAVA_HOME/include"
348 dnl         else
349 dnl             if test "`find $JAVA_HOME -name jni.h`" != ""; then
350 dnl                 head=`find $JAVA_HOME -name jni.h | tail -1`
351 dnl                 dir=`dirname "$head"`
352 dnl                 JNI_CFLAGS="-I$dir"
353 dnl             else
354 dnl                 AC_MSG_FAILURE([missing jni.h header file])
355 dnl             fi
356 dnl         fi
357 dnl         AC_MSG_RESULT([$JNI_CFLAGS])
358
359 dnl         dnl Find jni_md.h.
360 dnl         AC_MSG_CHECKING([for jni_md.h])
361 dnl         case "$build_os" in
362 dnl         *linux*) system="linux" ;;
363 dnl         *SunOS*) system="solaris" ;;
364 dnl         *cygwin*) system="win32" ;;
365 dnl         *) system="$build_os" ;;
366 dnl         esac
367 dnl         if test -f "$JAVA_HOME/include/$system/jni_md.h"; then
368 dnl             JNI_CFLAGS="$JNI_CFLAGS -I$JAVA_HOME/include/$system"
369 dnl         else
370 dnl             if test "`find $JAVA_HOME -name jni_md.h`" != ""; then
371 dnl                 head=`find $JAVA_HOME -name jni_md.h | tail -1`
372 dnl                 dir=`dirname "$head"`
373 dnl                 JNI_CFLAGS="$JNI_CFLAGS -I$dir"
374 dnl             else
375 dnl                 AC_MSG_FAILURE([missing jni_md.h header file])
376 dnl             fi
377 dnl         fi
378 dnl         AC_MSG_RESULT([$JNI_CFLAGS])
379
380 dnl         dnl Need extra version flag?
381 dnl         AC_MSG_CHECKING([extra javac flags])
382 dnl         JAVAC_FLAGS=
383 dnl         javac_version=`$JAVAC -version 2>&1`
384 dnl         case "$javac_version" in
385 dnl         *Eclipse*)
386 dnl             JAVAC_FLAGS="-source 1.5" ;;
387 dnl         esac
388 dnl         AC_MSG_RESULT([$JAVAC_FLAGS])
389
390 dnl         dnl Where to install jarfiles.
391 dnl         dnl XXX How to make it configurable?
392 dnl         JAR_INSTALL_DIR=\${prefix}/share/java
393 dnl         JNI_INSTALL_DIR=\${libdir}
394
395 dnl         dnl JNI version.
396 dnl         jni_major_version=`echo "$VERSION" | awk -F. '{print $1}'`
397 dnl         jni_minor_version=`echo "$VERSION" | awk -F. '{print $2}'`
398 dnl         jni_micro_version=`echo "$VERSION" | awk -F. '{print $3}'`
399 dnl         JNI_VERSION_INFO=`expr "$jni_major_version" + "$jni_minor_version"`":$jni_micro_version:$jni_minor_version"
400 dnl     fi
401 dnl fi
402
403 dnl AC_SUBST(JAVA_HOME)
404 dnl AC_SUBST(JAVA)
405 dnl AC_SUBST(JAVAC)
406 dnl AC_SUBST(JAVAH)
407 dnl AC_SUBST(JAVADOC)
408 dnl AC_SUBST(JAR)
409 dnl AC_SUBST(JNI_CFLAGS)
410 dnl AC_SUBST(JAVAC_FLAGS)
411 dnl AC_SUBST(JAR_INSTALL_DIR)
412 dnl AC_SUBST(JNI_INSTALL_DIR)
413 dnl AC_SUBST(JNI_VERSION_INFO)
414
415 dnl AM_CONDITIONAL([HAVE_JAVA],[test -n "$JAVAC"])
416
417 dnl dnl Check for Haskell (GHC).
418 dnl AC_CHECK_PROG([GHC],[ghc],[ghc],[no])
419
420 dnl AM_CONDITIONAL([HAVE_HASKELL],
421 dnl     [test "x$GHC" != "xno"])
422
423 dnl Produce output files.
424 AC_CONFIG_HEADERS([config.h])
425 AC_CONFIG_FILES([Makefile
426                  generator/Makefile
427                  gnulib/lib/Makefile
428                  gnulib/tests/Makefile
429                  hivex.pc
430                  images/Makefile
431                  lib/Makefile
432                  lib/tools/Makefile
433                  ocaml/Makefile ocaml/META
434                  perl/Makefile perl/Makefile.PL
435                  python/Makefile
436                  po/Makefile.in
437                  regedit/Makefile
438                  sh/Makefile
439                  xml/Makefile])
440 AC_OUTPUT
441
442 dnl Produce summary.
443 echo
444 echo
445 echo "------------------------------------------------------------"
446 echo "Thank you for downloading $PACKAGE_STRING"
447 echo
448 echo "This is how we have configured the optional components for you today:"
449 echo
450 echo -n "OCaml bindings ...................... "
451 if test "x$HAVE_OCAML_TRUE" = "x"; then echo "yes"; else echo "no"; fi
452 echo -n "Perl bindings ....................... "
453 if test "x$HAVE_PERL_TRUE" = "x"; then echo "yes"; else echo "no"; fi
454 echo -n "Python bindings ..................... "
455 if test "x$HAVE_PYTHON_TRUE" = "x"; then echo "yes"; else echo "no"; fi
456 dnl echo -n "Ruby bindings ....................... "
457 dnl if test "x$HAVE_RUBY_TRUE" = "x"; then echo "yes"; else echo "no"; fi
458 dnl echo -n "Java bindings ....................... "
459 dnl if test "x$HAVE_JAVA_TRUE" = "x"; then echo "yes"; else echo "no"; fi
460 dnl echo -n "Haskell bindings .................... "
461 dnl if test "x$HAVE_HASKELL" = "x"; then echo "yes"; else echo "no"; fi
462 echo
463 echo "If any optional component is configured 'no' when you expected 'yes'"
464 echo "then you should check the preceeding messages."
465 echo
466 echo "Please report bugs back to the mailing list:"
467 echo "http://www.redhat.com/mailman/listinfo/libguestfs"
468 echo
469 echo "Next you should type 'make' to build the package,"
470 echo "then 'make check' to run the tests."
471 echo "------------------------------------------------------------"