I have a command where I want the return code stored inside of a variable inside a makefile. I found out how to do this stackoverflow page here.
I am failing to make the eval command into multi line inside my makefile since it is very long. trying to change this
.PHONY: target2
target2:
$(eval CREATE__ACCOUNT := $(shell curl -o /dev/null -s -w "%{http_code}\n" -X POST "$(dev_url)/api/" -H "accept: application/json" -H "token: $(dev_token)" -H "Content-Type: application/json" -d "{ \"key1\": \"value1\", \"key2\": \"value2\", \"key3\": \"value3\", \"key4\": value4, \"key5\": \"value5\", \"key6\": \"value6\", \"key7\": \"value7\", \"key8\": \"value8"}"))
@if [ ${CREATE_ACCOUNT} -eq 201 ]; then \
echo "all good, account crated"; \
else \
echo "not good, got code ${CREATE_ACCOUNT} , account not created"; \
exit 1; \
fi
into someting resembling this
.PHONY: target2
target2:
$(eval CREATE__ACCOUNT := $(shell curl -o /dev/null -s -w "%{http_code}\n" \
-X POST "$(dev_url)/api/" \
-H "accept: application/json" \
-H "token: $(dev_token)" \
-H "Content-Type: application/json" \
-d "{ \"key1\": \"value1\", \"key2\": \"value2\", \"key3\": \"value3\", \"key4\": value4, \"key5\": \"value5\", \"key6\": \"value6\", \"key7\": \"value7\", \"key8\": \"value8"}"))
@if [ ${CREATE_ACCOUNT} -eq 201 ]; then \
echo "all good, account crated"; \
else \
echo "not good, got code ${CREATE_ACCOUNT} , account not created"; \
exit 1; \
fi
It seems int his case using the \
as line continuation is not working.
when trying this i get the following error
makefile:8: *** missing separator. Stop.