[quote] How to do arithmetic operation in makefile?

from

http://stackoverflow.com/questions/6593605/how-to-do-arithmetic-operation-in-makefile

 

jcomeau@intrepid:/tmp$ cat Makefile 
START=3
END=5
DIFF_SUB=$(shell echo $(END)-$(START)| bc)
test:@echo it took $(DIFF_SUB) seconds
jcomeau@intrepid:/tmp$ make
it took 2 seconds

If you're doing these inside the target, use your curly braces but double $s: $${DIFF_SUB}

jcomeau@intrepid:/tmp$ cat Makefile 
START=3
END=5
DIFF_SUB=$(shell echo $(END)-$(START)| bc)
test:@echo it took $(DIFF_SUB) seconds
test2:@START=3&& \
    echo HELLO && \
    END=7&& \
    DIFF_SUB=$$(($$END - $$START))&& \
    echo it took $${DIFF_SUB} seconds
jcomeau@intrepid:/tmp$ make test test2
it took 2 seconds
HELLO
it took 4 seconds

posted on 2014-01-07 09:16  Shawn X.Y. Bai  阅读(420)  评论(0)    收藏  举报

导航