make:尝试将git_commit_id传递给make_file中的变量

问题描述 投票:1回答:2

我试图获取git commit id并将其作为命令行值传递给我在cpp中编译的文件。为此,我写了下面的剪辑我的makefile。

%.cool_stuff:  %.c cool_stuff.cpp 
    $(CXX) $(OPT) cool_stuff.cpp -include $< -o $@ -l sqlite3 
    git_commit_id=$(shell $$(git rev-parse HEAD))
    ./$@ 1 $(git_commit_id)

问题是当我运行代码时,部分输出包含以下语句:

/ bin / sh:1:cdc8bdff6ccbc9dd14da68343fe4809f02cbe07e:未找到

所以没有任何东西最终被$(git_commit_id)传递给片段的最后一行。

请指教。

git shell makefile
2个回答
3
投票

Waayyyyy解释器调用层次太多。尝试

%.cool_stuff:  %.c cool_stuff.cpp 
    $(CXX) $(OPT) cool_stuff.cpp -include $< -o $@ -l sqlite3
    git_commit_id=`git rev-parse HEAD`; \
    ./$@ 1 $$git_commit_id

(编辑:来自评论的更正;还有:请注意,降价格式会占用标签,请勿在没有使用前导标签替换前导空格的情况下进行c&p)。


0
投票

在调用eval时围绕$(shell..)命令,如下所示

$(eval git_commit_id=$(shell git rev-parse HEAD)) 
© www.soinside.com 2019 - 2024. All rights reserved.