1dnl _GP_CHECK_CFLAG(FLAG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
2dnl Checks whether the C compiler works when passed FLAG
3dnl This might not mean it actually understand the flag, in case it is
4dnl forgiving about unknown flags.
5AC_DEFUN([_GP_CHECK_CFLAG],
6[
7    gp_check_cflag_CFLAGS="$CFLAGS"
8    CFLAGS="$1"
9    AC_LANG_PUSH(C)
10    AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) {return 0;}])],
11                      [$2], [$3])
12    AC_LANG_POP(C)
13    CFLAGS="$gp_check_cflag_CFLAGS"
14])
15
16dnl _GP_CHECK_CFLAG_WERROR
17dnl Checks for the flag the compiler has to treat warnings as errors
18dnl Sets $_GP_CFLAG_WERROR
19AC_DEFUN([_GP_CHECK_CFLAG_WERROR],
20[
21    _GP_CFLAG_WERROR=
22    AC_MSG_CHECKING([for the C compiler flag to treat warnings as errors])
23    _GP_CHECK_CFLAG([-Werror], [_GP_CFLAG_WERROR="-Werror"])
24    AC_MSG_RESULT([${_GP_CFLAG_WERROR:-none}])
25])
26
27dnl GP_CHECK_CFLAG(FLAG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
28dnl Checks whether the C compiler understands FLAG
29AC_DEFUN([GP_CHECK_CFLAG],
30[
31    AC_REQUIRE([_GP_CHECK_CFLAG_WERROR])
32
33    AC_MSG_CHECKING([whether the C compiler understands $1])
34    _GP_CHECK_CFLAG([$1 $_GP_CFLAG_WERROR],
35                    [AC_MSG_RESULT([yes])
36                     $2],
37                    [AC_MSG_RESULT([no])
38                     $3])
39])
40
41dnl GP_CHECK_CFLAGS
42dnl Checks for default Geany-Plugins CFLAGS and defines GP_CFLAGS
43AC_DEFUN([GP_CHECK_CFLAGS],
44[
45    AC_ARG_ENABLE([extra-c-warnings],
46                  AS_HELP_STRING([--disable-extra-c-warnings],
47                                 [Disable extra C Compiler warnings]),
48                  [enable_extra_c_warnings=$enableval],
49                  [enable_extra_c_warnings=yes])
50
51    GP_CFLAGS=
52    AS_IF([test "x$enable_extra_c_warnings" != xno],
53    [
54        enable_extra_c_warnings=yes
55        for flag in -Wall \
56                    -Wimplicit-function-declaration \
57                    -Wmissing-parameter-type \
58                    -Wold-style-declaration \
59                    -Wpointer-arith \
60                    -Wshadow \
61                    -Wundef \
62                    -Wwrite-strings
63        do
64            GP_CHECK_CFLAG([$flag], [GP_CFLAGS="${GP_CFLAGS} $flag"])
65        done
66    ])
67    AC_SUBST([GP_CFLAGS])
68    GP_STATUS_BUILD_FEATURE_ADD([Extra C compiler warnings],
69                                [$enable_extra_c_warnings])
70])
71