WINGs: Added a few missing const attributes
[wmaker-crm.git] / m4 / wm_cflags_check.m4
blobd46511a1b4ba0c958b606dccd45831781607ea1f
1 # wm_cflags_check.m4 - Macros to check options for the compiler into CFLAGS
3 # Copyright (c) 2013 Christophe CURIS
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 # WM_CFLAGS_CHECK_FIRST
21 # ---------------------
23 # For each option provided, check which one is supported and stops when
24 # found, adding it to CFLAGS. It extends AX_CFLAGS_GCC_OPTION which does
25 # not checks for fallbacks; as a bonus it uses a shared function to
26 # produce smaller configure script.
28 # Usage: WM_CFLAGS_CHECK_FIRST([message], [option alt_option...])
29 #   $1 message: required, message displayed in 'Checking for...'
30 #   $2 option_list: list of options, tested in given order
32 # The first option that works is added to CFLAGS
33 AC_DEFUN([WM_CFLAGS_CHECK_FIRST],
34 [AC_REQUIRE([_WM_SHELLFN_CHKCFLAGS])
35 m4_define([_wm_optlist], m4_split([$2]))dnl
36 AS_VAR_PUSHDEF([VAR], [wm_cv_c_check_compopt[]m4_car(_wm_optlist)])dnl
37 m4_define([_wm_trimmed_optlist], m4_join([ ], _wm_optlist))dnl
38 AC_CACHE_CHECK([CFLAGS for m4_ifnblank($1,$1,m4_car(_wm_optlist))], VAR,
39   [VAR="no, unknown"
40    for wm_option in _wm_trimmed_optlist ; do
41      AS_IF([wm_fn_c_try_compile_cflag "$wm_option"],
42            [VAR="$wm_option" ; break])
43    done])
44 AS_CASE([$VAR],
45   [no,*], [],
46   [AS_IF([echo " $CFLAGS " | grep " $VAR " 2>&1 > /dev/null],
47     [AC_MSG_WARN([option $VAR already present in \$CFLAGS, not appended])],
48     [CFLAGS="$CFLAGS $VAR"]) ])
49 AS_VAR_POPDEF([VAR])dnl
50 m4_undefine([_wm_optlist])dnl
51 m4_undefine([_wm_trimmed_optlist])dnl
55 # _WM_SHELLFN_CHKCFLAGS
56 # ---------------------
57 # (internal shell function)
59 # Create a shell function that tries compiling a simple program with the
60 # specified compiler option. Assumes the current compilation language is
61 # already set to C
62 AC_DEFUN_ONCE([_WM_SHELLFN_CHKCFLAGS],
63 [@%:@ wm_fn_c_try_compile_cflag CC_OPTION
64 @%:@ -----------------------------------
65 @%:@ Try compiling a function using CC_OPTION in the compiler's options
66 wm_fn_c_try_compile_cflag ()
68   wm_save_CFLAGS="$CFLAGS"
69   CFLAGS="$CFLAGS -Werror $[]1"
70   AC_COMPILE_IFELSE(
71     [AC_LANG_PROGRAM([], [])],
72     [wm_retval=0],
73     [wm_retval=1])
74   CFLAGS="$wm_save_CFLAGS"
75   AS_SET_STATUS([$wm_retval])