I have the following code in my makefile:
S_RES=$(shell cat output) echo -e "Serial result = \t" $(S_RES)
Basically, I want to store the output of the shell command cat output
in the S_RES variable, and then echo that variable to the screen (with some explanatory text in front of it). I also want to be able to use the variable later on in my program. I thought I had followed the instructions given in various StackOverflow questions, but it doesn't seem to work.
To use it, just set the list of variables to print on the command line, and include the debug target: $ make V="USERNAME SHELL" debug makefile:2: USERNAME = Owner makefile:2: SHELL = /bin/sh.exe make: debug is up to date. Now you can print variables by simply listing them on the command line.
The ' @ ' is discarded before the line is passed to the shell. Typically you would use this for a command whose only effect is to print something, such as an echo command to indicate progress through the makefile: @echo About to make distribution files.
@enchanter You can use echo, but you would need to put it outside the foreach loop, like this: @echo -e $(foreach var,$(. VARIABLES),"$(var)=$($(var))\n") . $(foreach...) concatenates all of the values from the loop, and then executes the result.
If simple space instead of escape sequence \t
is allowed, and your make
is GNU make
3.81 or higher, $(info)
is available.
For example:
$(info Serial result = $(S_RES))
If your make
's version is 3.80 or lower, $(warning)
might meet the purpose. However, warning
prints line number etc. too.
EDIT: For your information, the following makefile outputs abc
on my GNU make 3.81.
A := $(shell echo abc) $(info $(A))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With