autoconf
[Top][All Lists]
Advanced

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

Re: best way to check for compiler _warnings_?


From: Ralf Wildenhues
Subject: Re: best way to check for compiler _warnings_?
Date: Tue, 2 Nov 2010 20:15:10 +0100
User-agent: Mutt/1.5.20 (2010-08-04)

Hello Peter, Miles,

* Miles Bader wrote on Tue, Nov 02, 2010 at 08:18:24AM CET:
> On Tue, Nov 2, 2010 at 4:04 PM, Peter Rosin wrote:
> > Den 2010-11-02 06:46 skrev Ralf Wildenhues:
> >> Except then you may run into MSVC which prints its command-line options
> >> (dunno whether on stdout or stderr) ...
> >
> > To expand on that tangent...
> >
> > MSVC "only" prints the options it ends up feeding to link.exe (or maybe
> > it's link.exe that prints them?) and only if the -nologo option isn't
> > specified.  On stdout.  Unknown options are reported on stderr (with
> > zero exit status, of course).

Yes, it becomes more and more clear that -nologo should be added as
early as possible to the compiler flags.

> Yeah, this is what I tried, which seems to work OK:
> 
>       ... junk omitted ...
>       CXXFLAGS="$CXXFLAGS $OPT"
>       AC_MSG_CHECKING(whether C++ compiler accepts "$OPT" option)
>       AC_COMPILE_IFELSE(AC_LANG_SOURCE([int x;]),

This is not suitably quoted, you need at least
        AC_COMPILE_IFELSE([AC_LANG_SOURCE([int x;])],

in order to avoid warnings from Autoconf 2.68 (but it's also very
prudent to always m4-quote arguments which themselves contain macros).

>         [opt_ok=yes
>        if test -s conftest.err; then
>          for ONE_OPT in $OPT; do
>            if grep -e "$ONE_OPT" conftest.err >/dev/null; then

-e is not portable to Solaris grep.  Does MSVC print options at the
beginning of the line?  If not, then you could
             if grep ".$ONE_OPT" ...

>              opt_ok=no
>              break
>            fi
>          done
>        fi],
>       [opt_ok=no])
>       AC_MSG_RESULT([$opt_ok])

Since there's bound to be a compiler or setup where the test doesn't
provide the correct answer, it would be prudent to cache its result
(so the user could override the cache variable if needed).  You can use
AS_TR_SH to form a cache variable name from the option name, see the
manual or the implementation of AC_CHECK_HEADER or so for details and
examples.

Cheers,
Ralf



reply via email to

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