acinclude.m4 3.5 KB
Newer Older
1 2 3 4 5
dnl
dnl Taken from gnome-common/macros2/gnome-compiler-flags.m4
dnl
dnl We've added:
dnl   -Wextra -Wshadow -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Winline -Wredundant-decls
6 7 8
dnl We've removed
dnl   CFLAGS="$realsave_CFLAGS"
dnl   to avoid clobbering user-specified CFLAGS
9 10 11 12 13 14 15 16 17
dnl
AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
    dnl ******************************
    dnl More compiler warnings
    dnl ******************************

    AC_ARG_ENABLE(compile-warnings,
                  AC_HELP_STRING([--enable-compile-warnings=@<:@no/minimum/yes/maximum/error@:>@],
                                 [Turn on compiler warnings]),,
18
                  [enable_compile_warnings="m4_default([$1],[maximum])"])
19 20 21

    warnCFLAGS=

22
    common_flags="-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fasynchronous-unwind-tables"
23 24 25

    case "$enable_compile_warnings" in
    no)
26
        try_compiler_flags=""
27 28
	;;
    minimum)
29
	try_compiler_flags="-Wall -Wformat -Wformat-security $common_flags"
30 31
	;;
    yes)
32
	try_compiler_flags="-Wall -Wformat -Wformat-security -Wmissing-prototypes $common_flags"
33 34
	;;
    maximum|error)
35
	try_compiler_flags="-Wall -Wformat -Wformat-security -Wmissing-prototypes -Wnested-externs -Wpointer-arith"
36
	try_compiler_flags="$try_compiler_flags -Wextra -Wshadow -Wcast-align -Wwrite-strings -Waggregate-return"
D
Daniel P. Berrange 已提交
37
	try_compiler_flags="$try_compiler_flags -Wstrict-prototypes -Winline -Wredundant-decls -Wno-sign-compare"
38
	try_compiler_flags="$try_compiler_flags $common_flags"
39
	if test "$enable_compile_warnings" = "error" ; then
40
	    try_compiler_flags="$try_compiler_flags -Werror"
41 42 43 44 45 46
	fi
	;;
    *)
	AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings)
	;;
    esac
47

J
John Levon 已提交
48
    COMPILER_FLAGS=
49
    for option in $try_compiler_flags; do
J
John Levon 已提交
50
        gl_COMPILER_FLAGS($option)
51 52 53 54
    done
    unset option
    unset try_compiler_flags

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    AC_ARG_ENABLE(iso-c,
                  AC_HELP_STRING([--enable-iso-c],
                                 [Try to warn if code is not ISO C ]),,
                  [enable_iso_c=no])

    AC_MSG_CHECKING(what language compliance flags to pass to the C compiler)
    complCFLAGS=
    if test "x$enable_iso_c" != "xno"; then
	if test "x$GCC" = "xyes"; then
	case " $CFLAGS " in
	    *[\ \	]-ansi[\ \	]*) ;;
	    *) complCFLAGS="$complCFLAGS -ansi" ;;
	esac
	case " $CFLAGS " in
	    *[\ \	]-pedantic[\ \	]*) ;;
	    *) complCFLAGS="$complCFLAGS -pedantic" ;;
	esac
	fi
    fi
    AC_MSG_RESULT($complCFLAGS)

J
John Levon 已提交
76
    WARN_CFLAGS="$COMPILER_FLAGS $complCFLAGS"
77
    AC_SUBST(WARN_CFLAGS)
78 79 80 81 82 83

    dnl Needed to keep compile quiet on python 2.4
    COMPILER_FLAGS=
    gl_COMPILER_FLAGS(-Wno-redundant-decls)
    WARN_PYTHON_CFLAGS=$COMPILER_FLAGS
    AC_SUBST(WARN_PYTHON_CFLAGS)
84
])
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109


dnl
dnl To support the old pkg-config from RHEL4 vintage, we need
dnl to define the PKG_PROG_PKG_CONFIG macro if its not already
dnl present
m4_ifndef([PKG_PROG_PKG_CONFIG],
  [AC_DEFUN([PKG_PROG_PKG_CONFIG],
[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])dnl
if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
        AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
fi
if test -n "$PKG_CONFIG"; then
        _pkg_min_version=m4_default([$1], [0.9.0])
        AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
        if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
                AC_MSG_RESULT([yes])
        else
                AC_MSG_RESULT([no])
                PKG_CONFIG=""
        fi
fi[]dnl
])])