export HELLO=Hello,world
all:
@echo $(HELLO)
@echo $(shell echo $$HELLO)
@echo `echo $$HELLO`
outputs:
Hello,world
Hello,world
Why is there a difference between backtick and $(shell), and is there a way to pass the environment variables to $(shell) invocations?
I'm trying to use pkg-config in a cross-compilation environment, so I need to set $PKG_CONFIG_SYSROOT. I can use backticks, but it's executed once for every .o file. As per Computing Makefile variable on assignment, I need to use PKG_CFLAGS := $(shell pkg-config $(PACKAGES)), but I can't pass in the required environment variable to make that work properly.
Tested on GNU Make 4.0.
Congratulations you have hit a make bug: $(shell) doesn't honor export but this is undocumented?
There's a comment in the code (that precede's the filing of the ticket and is quoted in the ticket) which indicates that there are complicated situations where this cannot work correctly and so it appears that it just isn't done.
I can think of two ways to get the $(shell)
environment to have the variables you want to set manually available.
Set them in the $(shell)
context explicitly.
PCVAR:=$(shell PKG_CONFIG_SYSROOT=$(make-level-variable-PKG_CONFIG_SYSROOT) pkg-config ...)
Set them in the make
processes environment so the $(shell)
environment inherits them normally.
$ PKG_CONFIG_SYSROOT=/some/path make
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With