Reputation: 6770
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.
Upvotes: 2
Views: 241
Reputation: 189477
The shell cannot export stuff into your Makefile. Try something like this instead.
db := $(shell locate leveldb/db.h)
LEVELDB_PATH:=$(patsubst %/include/leveldb/db.h,%,$(db))
... or, to spare the temp variable,
LEVELDB_PATH:=$(shell locate leveldb/db.h | sed 's%/include/leveldb/db.h$$%%')
Edit: Fix to use $(patsubst)
instead of $(subst)
, and double the dollar sign in the sed
script.
Generally speaking, whatever goes on inside $(shell ...)
happens in a subprocess, which (as ever) cannot modify its parent. make
sees the output of the function when it finishes, but not what happened during the execution of the shell commands.
Upvotes: 3