Dale Visser
2014-02-19 21:05:36 UTC
I have been working on a changes whereby an autoconf user can invoke a macro like
AC_WARN_ADD([-Wextra])
to add user-specified flags to the compiler/linker invocations. Ideally we would like
AC_WARN_ADD([-Wunknown-warning-flag])
to not add the offending unknown flag. My initial implementation couldn't detect and suppress unknown flags in the LLVM clang/clang++ compiler. Eric Blake pointed me to the gnulib warnings module which has a clever way utilizing "-Wunknown-warning-option -Werror" to handle this: http://lists.gnu.org/archive/html/autoconf-patches/2014-02/msg00006.html
Wanting to be thorough, I checked whether unknown flags would also get suppressed by the Intel C++ compiler. It turns out that AFAICT the Intel compiler never exits with a non-zero status for unknown flags, eliminating the usual way of testing in autoconf. (See also https://stackoverflow.com/questions/14820890/intel-compilers-silence-commandline-warnings)
I would like to take the following approach, and want to see if the community has any helpful advice on whether this is advisable or ways to improve on it:
IF perform test compile with given flag (e.g., -Wunknown-warning-flag) (using above-mentioned strategy so LLVM will detect, too) is successful(true) THEN
Perform test compile with unknown flag, redirecting stdout and stderr to fileA
Perform test compile without unknown flag, redirecting stdout and stderr to fileB
IF "diff fileA fileB | grep --quiet -- -Wunknown-warning-flag" is successful (true) THEN
Flag is unknown. Do not add to flags.
ELSE
Success. Add to flags. It was not explicitly mentioned in output, so must be known.
FI
ELSE
Flag is unknown. Do not add to flags.
FI
Please let me know if you see any problems or pitfalls with this approach.
Best regards,
Dale Visser
AC_WARN_ADD([-Wextra])
to add user-specified flags to the compiler/linker invocations. Ideally we would like
AC_WARN_ADD([-Wunknown-warning-flag])
to not add the offending unknown flag. My initial implementation couldn't detect and suppress unknown flags in the LLVM clang/clang++ compiler. Eric Blake pointed me to the gnulib warnings module which has a clever way utilizing "-Wunknown-warning-option -Werror" to handle this: http://lists.gnu.org/archive/html/autoconf-patches/2014-02/msg00006.html
Wanting to be thorough, I checked whether unknown flags would also get suppressed by the Intel C++ compiler. It turns out that AFAICT the Intel compiler never exits with a non-zero status for unknown flags, eliminating the usual way of testing in autoconf. (See also https://stackoverflow.com/questions/14820890/intel-compilers-silence-commandline-warnings)
I would like to take the following approach, and want to see if the community has any helpful advice on whether this is advisable or ways to improve on it:
IF perform test compile with given flag (e.g., -Wunknown-warning-flag) (using above-mentioned strategy so LLVM will detect, too) is successful(true) THEN
Perform test compile with unknown flag, redirecting stdout and stderr to fileA
Perform test compile without unknown flag, redirecting stdout and stderr to fileB
IF "diff fileA fileB | grep --quiet -- -Wunknown-warning-flag" is successful (true) THEN
Flag is unknown. Do not add to flags.
ELSE
Success. Add to flags. It was not explicitly mentioned in output, so must be known.
FI
ELSE
Flag is unknown. Do not add to flags.
FI
Please let me know if you see any problems or pitfalls with this approach.
Best regards,
Dale Visser