Is it possible to perform some operations on variables in a makefile? For instance, defining
JPI=4 JPJ=2
is it possible to define in the same makefile a variable JPIJ
equal to the expanded value of $(JPI)*$(JPJ)
?
+= is used for appending more text to variables e.g. objects=main.o foo.o bar.o. objects+=new.o. which will set objects to 'main.o foo.o bar.o new.o' = is for recursively expanded variable.
$$ means be interpreted as a $ by the shell. the $(UNZIP_PATH) gets expanded by make before being interpreted by the shell.
Using Bash arithmetic expansion:
SHELL=/bin/bash JPI=4 JPJ=2 all: echo $$(( $(JPI) * $(JPJ) ))
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.
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 ))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With