Make: Capture output of shell command and return code at same time
makefile, return-value, shell
Solution
What about
OUTPUT_WITH_RC := $(shell $(COMMAND); echo $$?)
RETURN_CODE := $(lastword $(OUTPUT_WITH_RC))
OUTPUT := $(subst $(RETURN_CODE)QQQQ,,$(OUTPUT_WITH_RC)QQQQ)
If your command fails, it will probably write to stderr; you can use this to capture everything:
OUTPUT_WITH_RC := $(shell $(COMMAND) 2>$1; echo $$?)
Problem
In make, if I want to capture the output of a shell command, I do something like this ``` RESULT:=$(shell $(COMMAND)) ``` If I want to check if a command executed properly, I do this ``` RETURN_CODE := $(shell $(COMMAND); echo $$?) ``` How can I do both simultaneously, i.e. execute the command once, store the output, but also check the return code? EDIT Duplicate here although his solution is not pleasant: Makefile: Output and Exitcode to variable?