DEV Community

Romain Lespinasse
Romain Lespinasse

Posted on • Edited on

2 2

Create a wrapper task in Makefile

In makefile, you can define tasks and run them individually (e.g. make run-task1 run-task2 run-task3)

run-task1:
    @echo "run task 1"

run-task2:
    @echo "run task 2"

run-task3:
    @echo "run task 3"
Enter fullscreen mode Exit fullscreen mode

When you want to run tasks from another tasks (e.g. make run-all-tasks), you can

run-all-tasks: run-task1 run-task2 run-task3
Enter fullscreen mode Exit fullscreen mode
  • use sub-command line with $(MAKE)
run-all-tasks:
    @$(MAKE) run-task1
    @$(MAKE) run-task2
    @$(MAKE) run-task3
Enter fullscreen mode Exit fullscreen mode

You can also create a wrapper task to run all tasks with a specific naming.

This will enable you to don't known all task names.
Useful when using include mechanism in your makefile.

include makefile-with-run-tasks.mk

run-all-tasks:
    @grep -E '^[\.a-zA-Z0-9_%-]+:.*$$' $(MAKEFILE_LIST) \
        | cut -d ":" -f2 | grep "^run-task" | sort -u \
        | xargs $(MAKE)
Enter fullscreen mode Exit fullscreen mode

So when you run it, the run-all-tasks task will run all run-task tasks.

$ make run-all-tasks
run task 1
run task 2
run task 3
Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay