Here is part of my makefile :
LISTEINC = $(DEST)/file.inc $(DEST)/otherfile.inc $(DEST)/anotherfile.inc
compteur = 1
$(DEST)/file: $(LISTEINC)
#action
$(DEST)/%.inc: $(DEST)/%.jpg
./script $< $compteur $(DEST) > $@
How to have the variable compteur at 1 for file, 2 for otherfile, 3 for anotherfile?
$((compteur++)) would work in bash script, but here I really don't know what the equivalent is. I tried many combination of $$ () ++ +1 etc... Nothing worked. Anyone could help me please?
Increment Bash Variable with + Operator The bash variable can be incremented by summing it with the 1. By default, the + operator has a different meaning than the sum for the bash shell. The $((…)) operators are used to express the + operator is used arithmetic operation.
In addition to the basic operators explained above, bash also provides the assignment operators += and -= . These operators are used to increment/decrement the value of the left operand with the value specified after the operator.
Incremental Variables. Incremental variables allow you to generate a sequence of numbers or dates to use in user scenarios. Each incremental variable has an initial value and an increment step and updates its value at certain times (for example, on each use).
It can be done with eval
:
$(eval compteur=$(shell echo $$(($(compteur)+1))))
From the manual :
The eval function is very special: it allows you to define new makefile constructs that are not constant; which are the result of evaluating other variables and functions. The argument to the eval function is expanded, then the results of that expansion are parsed as makefile syntax. The expanded results can define new make variables, targets, implicit or explicit rules, etc
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