I want to assign the output of a shell command into a make variable.
this is what I tried:
phonegap:
#download new phonegap
cd ${SOURCE_PHONEGAP};git pull
PHONE_VER = $(shell cat d:/path/to/workspace/common/phonegap/VERSION)
echo phonegap version: ${PHONE_VER}
when running MAKE from the command line I get the following:
PHONE_VER = 1.3.0
make: PHONE_VER: Command not found
so the shell string is translated to the right value (1.3.0) but something fails after that.
I also tried declaring :
PHONE_VER =
and then in the command:
${PHONE_VER} = $(shell cat d:/path/to/workspace/common/phonegap/VERSION)
or using := or +=. didn’t work
I’m using cygwin (on win 7) with GNU make 3.81
I found this question and answer – but this doesn’t seem to work for me.
I’m obviously missing something (probably basic), but after a day of experimenting I have no clue whats the missing part.
You can’t assign variables inside rule recipes.
The first possible solutions is to initialize it somewhere outside the rule, and then use it as regular:
This will work fine as far as
PHONE_VERis recursively expanded (note the=sign in assignment), and the actual invocation ofshell cat ...will appear after satisfyingpull_phonegapprerequisite.The other possibility is make
PHONE_VERvariabletarget-specificforphonegap:Finally, if the only thing you want to do is to print the version of downloaded repo, then it would be easier to get rid of variables at all: