Bash 在Makefile中使用shell参数扩展名

Bash 在Makefile中使用shell参数扩展名,bash,shell,makefile,Bash,Shell,Makefile,如何在Makefile中使用shell参数扩展名? 我需要获取leveldb数据库的路径 到目前为止,我尝试的是在我的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 但是LEVELDB\u路径为空 谢谢您的帮助。shel

如何在Makefile中使用shell参数扩展名? 我需要获取leveldb数据库的路径

到目前为止,我尝试的是在我的
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
但是
LEVELDB\u路径
为空


谢谢您的帮助。

shell无法将内容导出到您的Makefile中。试试这样吧

db := $(shell locate leveldb/db.h)
LEVELDB_PATH:=$(patsubst %/include/leveldb/db.h,%,$(db))
。。。或者,为了节省温度变量

LEVELDB_PATH:=$(shell locate leveldb/db.h | sed 's%/include/leveldb/db.h$$%%')
编辑:修复使用
$(patsubst)
而不是
$(subst)
,并在
sed
脚本中加倍美元符号


一般来说,
$(shell…
内部发生的任何事情都发生在子流程中,而子流程(一如既往)无法修改其父流程
make
在函数完成时查看函数的输出,但不查看shell命令执行期间发生的情况。

第一个函数生成例如
-I/home/volker/TID/databases/leveldb/include/leveldb/db.h/include
第二个函数给出:
sed:-e表达式#,char 24:unterminated
s'command`看起来
%
出现了问题。离开它(并且考虑到这可能是路径中间的一个字符串?)它是有效的。这意味着,在MaFe文件中不能使用%吗?不,这个问题与百分比符号无关。