Posts

Showing posts with the label makefile

Subtract and Echo Difference of Variables in GNU Make

Image
Clash Royale CLAN TAG #URR8PPP Subtract and Echo Difference of Variables in GNU Make I'm echoing the time before I run a task and the time that task ends: test: @echo $(shell date) @JUNIT_REPORT_PATH=test/report.xml ./node_modules/.bin/mocha test/integration @echo $(shell date) Is there a way to store the dates in 2 variables and then show the elapsed time between them? I assume it would look something like this: test: @echo $(shell date) @JUNIT_REPORT_PATH=test/report.xml ./node_modules/.bin/mocha test/integration @echo $(shell date) test: $begin = $(shell date) <do stuff> $end = $(shell date) @echo $end - $begin Any pointers to good documentation on Make would be appreciated too. Thanks! 3 Answers 3 Short answer: what you want is possible: test: @begin=$$(date +%s); <do stuff in same shell: do not forget the ";" and the "...

Makefile test if variable is not empty

Makefile test if variable is not empty In a makefile I'm trying to I've created this simplified makefile to demonstrate my problem. Neither make a or make b executes the body of the if, I don't understand why not. make a make b .PHONY: a b a: $(eval MY_VAR = $(shell echo whatever)) @echo MY_VAR is $(MY_VAR) $(info $(MY_VAR)) ifneq ($(strip $(MY_VAR)),) @echo "should be executed" endif @echo done b: $(eval MY_VAR = $(shell echo '')) @echo MY_VAR is $(MY_VAR) $(info $(MY_VAR)) ifneq ($(strip $(MY_VAR)),) @echo "should not be executed" endif @echo done I'm using $ make --version GNU Make 3.81 There are several problems, and misunderstandings. Your MY_VAR is a make variable, set it without a <tab> to its value, and no need to $(eval ...) . MY_VAR:=$(shell echo whatever) is enough. No <tab> before $(info ...) neither, this is make – Zelnes ...