Do this:
MAKEFLAGS += rR
$(foreach x,$(filter-out .% MAKE% SHELL CURDIR,$(.VARIABLES)) MAKEINFO,$(if $(filter default,$(origin $x)),$(eval override undefine $x)))
Here, rR
is equivalent to --no-builtin-rules --no-builtin-variables
.
--no-builtin-rules
seems to work properly, but --no-builtin-variables
is wonky.
--no-builtin-variables
prevents the recipes from seeing the variables, but if you try to access them outside of a recipe, they are still there.
That's what the second line is for. It manually undefines all built-in variables. (Same idea as in @JohnMarshall's answer, but without shell invocations.)
It removes all variables for which $(origin
)
reports default
, except that it ignores SHELL
,CURDIR
, and variables starting with .
and MAKE
(except MAKEINFO
), since those look useful.