如何在makefile文件中做算术运算? [英] How to do arithmetic operation in makefile?

查看:556
本文介绍了如何在makefile文件中做算术运算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在makefile中执行以下操作,以测量执行某些操作所花费的时间:-

I am performing the following in the makefile to measure the time taken in doing some operation:-

START=$(shell date +%s) <br>
@if [ -s mfill.mapi.diff ]; then echo "difference exist between GOLDEN map file and test map file, see mfill.map.diff" ; fi <br>
END=$(shell date +%s) <br>
DIFF_SUB=$(shell echo $(END)\-$(START) | bc) <br>
@echo "It took ${DIFF_SUB} seconds"

它产生以下输出:-

START = 1309941257
END = 1309941268
DIFF_SUB =
花了几秒钟

START=1309941257
END=1309941268
DIFF_SUB=
It took seconds

你们能建议我做错了什么地方吗?

Could you guys suggest where i did wrong?

推荐答案

我不认为您应该对Makefile变量使用大括号:$(END)而不是$ {END}

I don't think you should be using curly braces for Makefile variables: $(END) not ${END}

您想要减法,但您使用了'*'.

You want subtraction but you used a '*'.

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

如果要在目标内执行这些操作,请使用花括号,但要加倍$ s:$${DIFF_SUB}

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

这篇关于如何在makefile文件中做算术运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆