在Makefile中做简单的数学运算 [英] Doing simple math in Makefile

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

问题描述

我需要在Makefile中做一些简单的数学运算,但是找不到如何做.在shell脚本中,我会这样:

I need to do some simple math in a Makefile but can't find out how to do it. In a shell script I would do it like this:

A=1
B=2
C=$[$A+$B]

但是如何在Makefile中执行此操作?让我们以此为基础:

But how can I do this in a Makefile? Let's use this as a base:

A=1
B=2
C=$(A)+$(B)

all:
        @echo 'A is $(A)'
        @echo 'B is $(B)'
        @echo 'C is $(C)'

自然地,它输出C is 1+2.如何重写变量C的定义,以便Makefile输出C is 3?

Naturally this outputs C is 1+2. How can I rewrite the definition of the variable C so the Makefile outputs C is 3?

推荐答案

在shell中使用"$(())"

use "$(())" in shell

all:
        @echo C is $$(($(C)))

一年后

我不知道您是否需要在Makefile中使用$ C的最终值. (您刚刚显示了它仅在Makefile中的shell脚本中使用,否则我犯了错误)您只需要将我的代码移至$ C的定义即可:

I did not know you need to used the final value of $C in the Makefile. (You just shown it is only used in the shell script inside the Makefile or I had make mistake) You just need to move my code to the definition of the $C:

C=$(shell echo $$(($A+$B)))

这篇关于在Makefile中做简单的数学运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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