Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write a makefile to run a shell command after all targets in the file have been processed?

Tags:

makefile

I have a single makefile that runs a group of tests involving various files and writes the results to log files. Is it possible to write the makefile so that it will run the same set of shell commands after all other targets in the file have been processed, regardless of errors that occurred.

I know I could use a shell script that calls the makefile and then the shell commands, but I'm wondering if it's possible to do this from within the makefile itself, without using some phony target like make print (for example).

like image 502
Ricardo Altamirano Avatar asked Jan 20 '26 21:01

Ricardo Altamirano


1 Answers

You could try something like this:

   .PHONY: test1 test2 test3 finale

    all: finale

    finale: test1 test2 test3

    test1:
        - exit 1

    test2:
        - exit 2

    test3:
        - exit 3

    finale:
            echo "And the winner is..."

You make your script, the target "finale", dependent on the other targets, and you use the "-" operator to ignore the non-zero return codes from the tests.

like image 83
Jonathan Ben-Avraham Avatar answered Jan 23 '26 09:01

Jonathan Ben-Avraham