Reputation: 2132
I am trying to get the git commit id and pass it to a script as a command line value to a file that I've compiled in cpp. To this end I've written the following snipped it my 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)
The problem is that when I run the code, part of the output contains the statement:
/bin/sh: 1: cdc8bdff6ccbc9dd14da68343fe4809f02cbe07e: not found
so that nothing ends up getting passed for $(git_commit_id) to the last line of the snippet.
please advise.
Upvotes: 1
Views: 151
Reputation: 60323
Waayyyyy too many layers of interpreter invocation. Try
%.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
(edit: corrections from comments; also: note that markdown formatting eats tabs, don't c&p without replacing leading spaces with leading tabs).
Upvotes: 3
Reputation: 2132
Surround the $(shell..)
command in a call to eval as shown below
$(eval git_commit_id=$(shell git rev-parse HEAD))
Upvotes: 0