Executing a Make target inside a target

Published on 2023-03-15 • Modified on 2023-03-15

This snippet shows how to execute a given Make target inside a target. When you want to run a target before another, you can put a target in the requirements. For example, here, hello1 will run before hello2. But, if you want to run it after, the syntax is different: you have to use the particular MAKE variable, which contains the current path of the Make executable for the current context. Then you can specify the target you want to run as you would do with the command line. In the example, hello3 will run after hello2. The final output for make hello2 will be:
hello 1
hello 2
hello 3


hello1:
    @echo "hello 1"

hello2: hello1
    @echo "hello 2"
    $(MAKE) hello3

hello3:
    @echo "hello 3"

 More on Stackoverflow   Read the doc  Random snippet

  Work with me!