autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stack-like AC_LANG_WERROR


From: Andrey Simonenko
Subject: Re: Stack-like AC_LANG_WERROR
Date: Wed, 2 Apr 2008 09:13:25 +0300
User-agent: Mutt/1.5.17 (2007-11-01)

Hello Ralf,

On Wed, Mar 26, 2008 at 12:00:49AM +0100, Ralf Wildenhues wrote:
> 
> I would probably like a shell function version better.  But more
> importantly, this patch needs a testsuite addition to exercise the new
> (and the old! claiming compatibility) behavior.  And a NEWS entry.

[skip]

> I wonder a bit whether the functionality should be in two new macros
>   AC_LANG_WERROR_PUSH(on/off)
>   AC_LANG_WERROR_POP([on/off])
> 
> where the optional argument to POP would allow for a consistency check
> with the one passed to the previous PUSH.  This would be nicely similar
> to AC_LANG_{PUSH,POP}.

This is another backward compatible modification for AC_LANG_WERROR:

1. AC_LANG_WERROR([on/off])
  a) no arguments -- similarly to AC_LANG_WERROR([on]);
  b) `on'  -- treat warnings as fatal errors;
  c) `off' -- do not treat warnings as fatal errors.

2. AC_LANG_WERROR_PUSH(on/off)
  a) `on'  -- remember current settings + treat warnings as fatal errors;
  b) `off' -- remember current settings + do no treat warnings as fatal
     errors.

3. AC_LANG_WERROR_POP([on/off])
  a) no arguments -- restore previous settings;
  b) `on' or `off' -- check that current settings match the argument's
     value + restore previous settings.

Used shell variables:

1. ac_${ac_ext}_werror_flag -- current werror flag, it can be `yes' or `'
   (empty), these values are used in Autoconf 2.61 and can be checked
   by developers who modifed this variable directly in their m4 files.

2. ac_${ac_ext}_werror_flags -- stack of werror flags.  It consists of
   `on' and `off' values separated by space.

AC_LANG_WERROR* macros just check number of arguments and their values
for correctness.  All logic is implemented in the following functions:

1. ac_lang_werror(on/off) -- set ac_${ac_ext}_werror_flag to `yes' or `'.

2. ac_lang_werror_push(on/off) -- push old value of ac_${ac_ext}_werror_flag
   to ac_${ac_ext}_werror_flags and set ac_${ac_ext}_werror_flag to `yes'
   or `'.

3. ac_lang_werror_pop([on/off]) -- optionally check that argument's value
   is equal to ac_${ac_ext}_werror_flag and restore ac_${ac_ext}_werror_flag
   from ac_${ac_ext}_werror_flags stack.  This function also check whether
   a stack is empty.

Since all logic is implemented in shell functions, then AC_LANG_WERROR*
also can be used in shell functions.  But now it will be harder to debug
code, since ac_lang_werror_pop() can exit with error and it will be
unclear which AC_LANG_WERROR_POP call caused the problem.

Unlike previous AC_LANG_WERROR this implementation AC_LANG_WERROR does not
do m4_divert_text([DEFAULTS], [ac_[]_AC_LANG_ABBREV[]_werror_flag=].  If
this line is really needed, then it should not be part of AC_LANG_WERROR*,
instead it should be part of AC_LANG or similar.

I've got few questions:

1. Is there another (more standard) way to "include" something in
   configure script only once?  See AC_LANG_WERROR*_FUNC_INCLUDED

2. How to output current language name in shell function?  I use
   ${ac_ext}, but its value sometimes is not very informative.

3. Which exit code should be used in ac_lang_werror_pop()?

4. Should ac_lang_werror*() functions be mentioned in documentation?

Examples of usage (<werror_flag>, 'werror_flags'):

1.
Initial
<>, ''
WERROR_PUSH(on)
<yes>, 'off '
WERROR_PUSH(on)
<yes>, 'on off '
WERROR_PUSH(off)
<>, 'on on off '
WERROR_POP(off)
<yes>, 'on off '
WERROR_POP
<yes>, 'off '
WERROR_POP(on)
<>, ''

2.
Initial
<>, ''
WERROR_PUSH(on)
<yes>, 'off '
WERROR_POP(off)
configure:604: error: ac_lang_werror_pop(off): current werror flag is on for 
'c' language

3.
Initial
<>, ''
WERROR_POP(off)
configure:613: error: ac_lang_werror_pop(off): stack is empty for 'c' language

What is your opinion about this modification for AC_LANG_WERROR?

Modifications in lang.m4:

# AC_LANG_WERROR_FUNC
# -------------------
# This macro definition contains one shell function that enables (if an
# argument is `on') or disables (if an argument is `off') werror flag.
AC_DEFUN([AC_LANG_WERROR_FUNC],
[m4_define([AC_LANG_WERROR_FUNC_INCLUDED])dnl
ac_lang_werror()
{
  case $[]1 in
  on)  eval ac_${ac_ext}_werror_flag=yes ;;
  off) eval ac_${ac_ext}_werror_flag= ;;
  esac
}])# AC_LANG_WERROR_FUNC

# AC_LANG_WERROR([VALUE])
# -----------------------
# How to treat warnings from the current language's preprocessor, compiler,
# and linker:
# 1. No arguments:
#       Similarly to AC_LANG_WERROR([on])
# 2. One argument:
#       `on'  -- treat warnings as fatal errors;
#       `off' -- do not treat warnings as fatal errors;
# AC_LANG_WERROR can be mixed with AC_LANG_WERROR_PUSH/POP.
AC_DEFUN([AC_LANG_WERROR],
[m4_ifndef([AC_LANG_WERROR_FUNC_INCLUDED],
          [m4_divert_text([DEFAULTS], [AC_LANG_WERROR_FUNC])])dnl
m4_if(
    $#, 1, [m4_if(
        [$1], [on], [ac_lang_werror on],
        [$1], [off], [ac_lang_werror off],
        [m4_fatal([$0: wrong argument: `$1'])])],
    $#, 0, [AC_LANG_WERROR([on])],
    [m4_fatal([$0: incorrect number of arguments: $#])])[]dnl
])# AC_LANG_WERROR

# AC_LANG_WERROR_PUSH(VALUE)
# --------------------------
# Save the current werror flag and set it to a new VALUE, that can be
# `on' or `off'.
AC_DEFUN([AC_LANG_WERROR_PUSH],
[m4_ifndef([AC_LANG_WERROR_FUNC_INCLUDED],
          [m4_divert_text([DEFAULTS], [AC_LANG_WERROR_FUNC])])dnl
m4_ifndef([AC_LANG_WERROR_PUSH_FUNC_INCLUDED],
          [m4_divert_text([DEFAULTS],
[m4_define([AC_LANG_WERROR_PUSH_FUNC_INCLUDED])dnl
ac_lang_werror_push()
{
  case "`eval echo \\$ac_${ac_ext}_werror_flag`" in
  yes) eval ac_${ac_ext}_werror_flags=\"on \${ac_${ac_ext}_werror_flags}\" ;;
  *)   eval ac_${ac_ext}_werror_flags=\"off \${ac_${ac_ext}_werror_flags}\" ;;
  esac
  ac_lang_werror $[]1
}])])dnl
m4_if(
    $#, 1, [m4_if(
        [$1], [on], [ac_lang_werror_push on],
        [$1], [off], [ac_lang_werror_push off],
        [m4_fatal([$0: wrong argument: `$1'])])],
    [m4_fatal([$0: incorrect number of arguments: $#])])[]dnl
])# AC_LANG_LANG_WERROR_PUSH

# AC_LANG_WERROR_POP([VALUE])
# ---------------------------
# If an argument is given, then check that the current werror flag matches
# VALUE (that can be `on' or `off'), and restore the previous werror flag.
AC_DEFUN([AC_LANG_WERROR_POP],
[m4_ifndef([AC_LANG_WERROR_FUNC_INCLUDED],
          [m4_divert_text([DEFAULTS], [AC_LANG_WERROR_FUNC])])dnl
m4_ifndef([AC_LANG_WERROR_POP_FUNC_INCLUDED],
          [m4_divert_text([DEFAULTS],
[m4_define([AC_LANG_WERROR_POP_FUNC_INCLUDED])dnl
ac_lang_werror_pop()
{
  case $[]# in
  1)
    case "`eval echo \\$ac_${ac_ext}_werror_flag`" in
    yes)
      case $[]1 in
      off)
        echo "$as_me:$LINENO: error: ac_lang_werror_pop(off): current werror 
flag is on for '${ac_ext}' language"
        exit 1 ;;
      esac ;;
    *)
      case $[]1 in
      on)
        echo "$as_me:$LINENO: error: ac_lang_werror_pop(on): current werror 
flag is off for '${ac_ext}' language"
        exit 1 ;;
      esac ;;
    esac ;;
  esac
  case "`eval echo \\${ac_${ac_ext}_werror_flags%% *}`" in
  on)
    ac_lang_werror on ;;
  off)
    ac_lang_werror off ;;
  *)
    echo "$as_me:$LINENO: error: ac_lang_werror_pop($[]1): stack is empty for 
'${ac_ext}' language"
    exit 1 ;;
  esac
  eval ac_${ac_ext}_werror_flags=\${ac_${ac_ext}_werror_flags#* }
}])])dnl
m4_if(
    $#, 1, [m4_if(
        [$1], [on], [ac_lang_werror_pop on],
        [$1], [off], [ac_lang_werror_pop off],
        [m4_fatal([$0: wrong argument: `$1'])])],
    $#, 0, [ac_lang_werror_pop],
    [m4_fatal([$0: incorrect number of arguments: $#])])[]dnl
])# AC_LANG_LANG_WERROR_POP

Modifications for autoconf.texi:

@defmac AC_LANG_WERROR (@ovar{value})
@acindex{LANG_WERROR}
Normally Autoconf ignores warnings generated by the compiler, linker, and
preprocessor.  This macro allows to change this behaviour.  If @var{value}
is @code{on} or if an optional argument is not given, then warnings are
treated as fatal errors for the current language.  If @var{value} is
@code{off}, then the normal Autoconf's behaviour for the current language is
restored.  This macro can be mixed with @code{AC_LANG_WERROR_PUSH} and
@code{AC_LANG_WERROR_POP} and can be used in shell functions.

This macro is useful when the results of configuration are used where
warnings are unacceptable; for instance, if parts of a program are built
with the @acronym{GCC}
@option{-Werror}
option.  If the whole program is built using @option{-Werror} it is
often simpler to put @option{-Werror} in the compiler flags (@code{CFLAGS},
etc.).
@end defmac

@defmac AC_LANG_WERROR_PUSH (@var{value})
@acindex{LANG_WERROR_PUSH}
This macro works like @code{AC_LANG_WERROR}, but in a stack-like fashion.
Each macro call with @code{on} or @code{off} @var{value} remembers current
settings on a stack and sets new settings for the current language.  Each
language has its own stack that is used exclusively by this macro and
@code{AC_LANG_WERROR_POP} for saving and restoring settings.  This macro
can be used in shell functions.
@end defmac

@defmac AC_LANG_WERROR_POP (@ovar{value})
@acindex{LANG_WERROR_POP}
This macro should be used together with @code{AC_LANG_WERROR_PUSH}.  It
restores settings that are saved on the top of the stack for the current
language and removes them from the stack.

If an argument is given, then check that current settings for the current
language match @var{VALUE} (@code{on} or @code{off}).  Specify this argument
if it is known, since Autoconf detects inconsistencies.

@example
AC_LANG_WERROR_PUSH([on])
# Treat warnings for the current language as fatal.
# @dots{}
AC_LANG_WERROR_POP([on])
@end example

This macro call can be used in shell functions.
@end defmac




reply via email to

[Prev in Thread] Current Thread [Next in Thread]