Example for your reference:
Below is the "Makefile", which is at the top level.
Makefile
export ROOT_DIR=${PWD} all: $(MAKE) -C test
Then in the "test" folder (relative to the current location) there is another "Makefile", as shown below:
Makefile
all: echo $(ROOT_DIR)
When you say "do everything" in the top-level folder, then it will be built in accordance with the current Makefile, and then in accordance with the specified rule in the "test" folder (using Makefile at "test" for the assembly rules). Therefore, when parent-Makefile exports some variable, then for this build environment, the exported variable will be visible to all Makefiles subdirectories.
However, if you try to explicitly enter the "test" folder and try to "do everything", you will have to explicitly set the environment variable before it (which in the previous case is set to uppercase, the Makefile level).
Additional information .
source share