configure doesn't honor CPPFLAGS

My experiment building clang with gcc 4.6 on NetBSD today exposed a
problem in the clang build system: although I defined CPPFLAGS before
invoking configure, the variable wasn't used in the build. It's used
in *configure*, sure enough, but by the time we're compiling
Triple.cpp, it's nowhere in sight.

With guidance, I can correct some of what's wrong. Let me first
explain what I'm seeing.

I've identified three problems with CPPFLAGS.

1. configure uses it, but it's not passed on to the main build.
2. overwrites it (sometimes).
3. configure promises to use it.

I was able to work around that by defining my variable as part of the
CXX variable:


Until I did that, -DDNU_SYS_PARAMS_H was not passed to the compiler.

The autoconf manual says CPPFLAGS is a "preset output variable", and
automake says it's one of the variables "inherited from autoconf".
Indeed, my config.log shows the variable twice on the command line e.g.:

configure:2160: /usr/pkg/gcc46/bin/cc -DDNU_SYS_PARAMS_H
-DDNU_SYS_PARAMS_H c onftest.c >&5

I won't quote the whole command line from the build log here. The
variable appears only once, immediately after the c++ command:

  /usr/pkg/gcc46/bin/c++ -DDNU_SYS_PARAMS_H -I/home....

Ignoring CPPFLAGS looks to be intentional. The very nice document
Getting Started with the LLVM System — LLVM 16.0.0git documentation mentions only CC
and CXX as variables, and configure --help mentions
--with-optimize-options and --with-extra-options. (I don't know if
they're intended as replacements. If I may say so, they're are a bit
vague and afaict undocumented.)

It would be better to support CPPFLAGS. overwrites CPPFLAGS:

   1184 CPPFLAGS="-I${withval}/include";;

And configure itself promises to use it:

$ ../configure --help | sed -ne '/^Some/,/CPP /p'
Some influential environment variables:
  CC C compiler command
  CFLAGS C compiler flags
  LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I<include

if you have headers in a nonstandard directory <include dir>

  CXX C++ compiler command
  CXXFLAGS C++ compiler flags
  CPP C preprocessor

That's my story. Probably I've missed something. As I said, I'm
prepared to make corrections, but I don't want to tromp on something
that needs to be the way it is.

Humbly submitted,


Shouldn't you use CXXFLAGS instead?

Not according to the autoconf documentation. The AC_LANG macro for
example says:

          Do compilation tests using `CXX' and `CXXCPP' and use
          extension `.C' for test programs. Use compilation flags:
          `CPPFLAGS' with `CXXCPP', and both `CPPFLAGS' and `CXXFLAGS'
          with `CXX'.

Under "Preset Output Variables" it says:

-- Variable: CPPFLAGS
     Preprocessor options for the C, C++, Objective C, and Objective C++
     preprocessors and compilers. If it is not set in the environment
     when `configure' runs, the default value is empty. `configure'
     uses this variable when preprocessing or compiling programs to
     test for C, C++, Objective C, and Objective C++ features.

Is CXXFLAGS supported? It's not mentioned on the Getting Started page