supe345
supe345

Reputation: 141

Force execution in makefile

I am actually trying to modify a Makefile and I want at the end of this makefile add a command that will be run even if the rest of the make fails and I would also like to know if it would be possible to run this command even if the user hits ctrl + c. I searched a bit on the web but couldn't find an answer to my question.

Thank you so much in advance.

Upvotes: 0

Views: 182

Answers (2)

MadScientist
MadScientist

Reputation: 100816

It is basically not possible to define something in a makefile that will always be run as the very last thing.

The best I can suggest is that you create a wrapper script that people invoke instead of make, and that the wrapper script run the command you want after make exits. The script can capture SIGINT (^C) even.

If you really must do it with make the only way to do it is create a "wrapper makefile" that essentially invokes a sub-make on the real makefile to do the work, then can do more things when that sub-make finishes. There's no way to catch SIGINT in this situation. This is also complicated because there's not really any such thing as "perfect forwarding" in makefiles, so getting the makefile wrapper to behave identically as when there is no wrapper is tricky or even impossible.

Upvotes: 2

Renaud Pacalet
Renaud Pacalet

Reputation: 28965

If you want to run a command every time make is called you can call the shell function:

DUMMY := $(shell myCommand &)

Put it at the beginning of the Makefile such that it is one of the first things make will do. Normally stopping make with CTRL-C, unless you are super fast and hit CTRL-C before make executed the command, should not stop the child process.

Upvotes: 0

Related Questions