如何在Makefile中执行算术运算? [英] How do I perform arithmetic in a makefile?

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

问题描述

是否可以对Makefile中的变量执行某些操作? 例如,定义

Is it possible to perform some operations on variables in a makefile? For instance, defining

JPI=4
JPJ=2

是否可以在同一个makefile文件中定义等于$(JPI)* $(JPJ)扩展值的变量JPIJ?

Is it possible to define in the same makefile a variable JPIJ equal to the expanded value of $(JPI)*$(JPJ)?

推荐答案

使用第一行是选择Bash shell来代替默认值(sh).通常,sh不支持算术扩展.但是在Ubuntu中,/bin/sh由 Dash提供,它支持此功能.这样该行可以跳过.

The first line is to choose the Bash shell instead of the default (sh). Typically, sh doesn't support arithmetic expansion. However in Ubuntu, /bin/sh is provided by Dash, which supports this feature. So that line could be skipped.

双美元符号是因为我们想要由外壳完成的扩展.注意:JPI和JPJ变量先由make扩展,然后将表达式传递给bash,如下所示:

The double dollar sign is because we want the expansion to be done by the shell. Note: the JPI and JPJ variables are expanded by make first, then the expression is passed to bash like this:

$(( 4 * 2 ))

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

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