How can I use shell parameter extension in a Makefile?
I need to get the path to the leveldb database.
What I tried so far is in my Makefile:
$(shell db=$(locate leveldb/db.h); export LEVELDB_PATH=${db%%/include/leveldb/db.h})
LEVELDB_LIBS=-L$(LEVELDB_PATH) -I$(LEVELDB_PATH)/include -lleveldb
But LEVELDB_PATH is empty.
Thanks for help.
The shell cannot export stuff into your Makefile. Try something like this instead.
… or, to spare the temp variable,
Edit: Fix to use
$(patsubst)instead of$(subst), and double the dollar sign in thesedscript.Generally speaking, whatever goes on inside
$(shell ...)happens in a subprocess, which (as ever) cannot modify its parent.makesees the output of the function when it finishes, but not what happened during the execution of the shell commands.