docs/requirements/interception-cc-env-var-flags.md
Compiler environment variables often carry not just the compiler path but a simple trailing flag or two. This is a GNU Make convention and shows up in configure scripts, Makefiles, and Dockerfiles:
CC="gcc -std=c11"CXX="clang++ -stdlib=libc++"CC="/usr/local/bin/gcc -m32"When the user runs bear -- make with a value of this shape, Bear's
wrapper mode registers a wrapper for the real program and rewrites the
env var so the build still receives the flags.
Anything more elaborate -- flags with embedded whitespace, shell
quoting, metacharacters, command substitutions -- belongs in CFLAGS /
CXXFLAGS / LDFLAGS. Bear splits the env var value on whitespace
and goes no further. The man page points users at CFLAGS for
anything that does not fit that shape.
(program, flags) on
whitespace before resolution.interception-wrapper-recursion), and the flag
tokens are preserved.CC/CXX convention is a Unix / GNU Make inheritance.CC=gcc or an absolute path
such as CC=/usr/bin/gcc) and an unset variable follow the ordinary
wrapper-mode resolution owned by interception-wrapper-mechanism;
the whitespace split is observable only when flag tokens are present.nmake, cmd, PowerShell) does not read
CC/CXX from the environment.Given a wrapper-mode setup with a fake compiler on PATH:
When
CC="fake-cc -std=c11", then the wrapper config is keyed by the compiler basename and points at the real compiler, and the override value forCCequals"<wrapper_path> -std=c11".
Given a wrapper-mode setup with a fake compiler at an absolute path:
When
CC="/abs/path/my-gcc -m32", then the resolved program is/abs/path/my-gcc, and the override preserves-m32.
Given a wrapper-mode setup with no flags (regression guard):
When
CC=/usr/bin/gcc, then the override value equals the wrapper path verbatim (no shell quoting introduced).
Given an empty or whitespace-only value:
When
CC=""orCC=" ", then noCCoverride appears in the build environment, and a warning is emitted.
Given a ccache masquerade directory on PATH and a real compiler past it:
When
CC="gcc -std=c11", then the wrapper config entry points at the real compiler past the masquerade directory, and the override forCCstill contains-std=c11.
Given a Unix-like shell on Windows producing forward-slash paths:
When
CC="C:/tools/fake-cc.exe -DBEAR_TEST=1", then the wrapper is registered forfake-cc.exe, and the override forCCstill contains-DBEAR_TEST=1.
Given a C source file and a build script that runs $CC -c test.c:
When the user runs
bearin wrapper mode withCC="<compiler> -DBEAR_TEST_FLAG=1", then the build succeeds, andcompile_commands.jsonhas exactly one entry, and theargumentsarray contains-DBEAR_TEST_FLAG=1.
interception-wrapper-mechanism -- the wrapper mode this
feature extends.interception-wrapper-recursion -- masquerade handling of
the program token.output-env-derived-flags -- folding include/option env
vars into entries, a separate output-side mechanism.