0

I have a Makefile, to which I have added the following two targets that run Symfony commands inside a Docker container:

amqp-poll: ## Start amqp polling
    @$(DOCKER_COMPOSE) exec -it $(SERVICE_CONTAINER) /bin/bash -c "php /code/backend/app-new/console amqp:poll"

amqp-purge: ## Purge amqp queues
    @$(DOCKER_COMPOSE) exec -it $(SERVICE_CONTAINER) /bin/bash -c "php /code/backend/app-new/console amqp:poll --purge"

Is it possible to pass in a flag so that I am, for example, running make amqp-poll --purge rather than make amqp-purge?

In other words, I would like to merge these two targets, with the use of a double-dash flag selectively triggering the logic in the second target.

(I looked into ifdef, but it looks like that requires a value, right? I'm more interested in a simple flag.)

Is this possible?

  • 3
    The only possible syntax is `make amqp-poll my_flags=--purge`. – HolyBlackCat Mar 08 '23 at 10:28
  • If the goal is to be DRY, you can use a [canned recipe](https://www.gnu.org/software/make/manual/html_node/Canned-Recipes.html) with [target-specific variable values](https://www.gnu.org/software/make/manual/html_node/Target_002dspecific.html). – rveerd Mar 09 '23 at 15:52
  • Does this answer your question? [Passing arguments to "make run"](https://stackoverflow.com/questions/2214575/passing-arguments-to-make-run) – tripleee Mar 10 '23 at 08:47

1 Answers1

1

Yes, it is possible. Makefile:

# Optional default initialization to suppress warnings
AMQP_FLAGS ?=

amqp-poll: ## Start amqp polling
    @$(DOCKER_COMPOSE) exec -it $(SERVICE_CONTAINER) /bin/bash -c "php /code/backend/app-new/console amqp:poll $(AMQP_FLAGS)"

Command-line:

make amqp-poll AMPQ_FLAGS=--purge
Andreas
  • 5,086
  • 3
  • 16
  • 36