Reputation: 321
I set this array in my Makefile:
PROJECTS=auth core-connect customization forward hook simulation webhook
And I want to do something like this:
foreach (PROJECTS as var) {
if (var == 'simulation' || var = 'webhook') {
do something
} else {
do else
}
}
I know how to write a foreach
in a Makefile:
analyze:
$(foreach var,$(PROJECTS),docker exec -it api_php7_1 bash -c "cd apps/"$(var)" && vendor/bin/phpstan";)
But I don't know where to place the if
condition inside the loop.
UPDATE :
composer-install:
for var in $(PROJECTS); do \
case $$var in \
(simulation|webhook) $(RUN_8) composer install -n --working-dir=apps/$$var ;; \
(*) $(RUN_7) composer install -n --working-dir=apps/$$var ;; \
esac; \
done
Upvotes: 0
Views: 204
Reputation: 100836
Each recipe for a rule is a set of one or more shell commands (POSIX sh). So, the syntax you use to write recipes is the same as you'd use to write a shell script (or write shell commands at your shell prompt).
Also each logical line of the recipe is run in a different shell. So if you want to write your loop across multiple physical lines you need to add backslashes at the end to turn them into a single logical line. This may also mean you need semicolons so that the shell will understand what you want (this is all related to writing shell scripts, not makefiles). And, any time you want a $
to appear in your shell script you have to write it as $$
in your makefile, to escape the $
from make.
So one example:
analyze:
for var in $(PROJECTS); do \
case $$var in \
(simulation|webhook) do something ;; \
(*) do something else ;; \
esac; \
done
Upvotes: 1