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 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) ?
If you're using GNU make
and have bc
installed on your system, you can use something like this:
JPI=4
JPJ=2
FOO=$(shell echo $(JPI)\*$(JPJ) | bc)
all:
echo $(FOO)
It's clumsy (or brilliant, depending on your perspective), but you can do arithmetic directly in GNU make. See Learning GNU Make Functions with Arithmetic. Be aware though that this method doesn't scale well. It will work wonderfully for small numbers as you have shown in your question, but it doesn't do well when you're working with numbers with a large magnitude (greater than 10,000,000).