In make
, is it possible to define a pre- and post-recipe for every target?
I want to (implicitly) insert the pre-recipe just above the first line of the explicit recipe and then (implicitly) insert the post-recipe after the last line in the explicit recipe.
It would be pretty easy to do it using regular expressions to insert lines but implicit ones would be so much cleaner.
You can create a special helper shell that executes the desired pre- and post- actions before and after its input script and tell
make
to use that shell for executing the recipes (use theSHELL
variable to that end).Besides, if you are using multiline recipes, you will have to enable the
.ONESHELL
mode.Example:
pre-post-shell
makefile
Output:
You can have a target that you call using the
$(MAKE)
command on the same file making the call:This example Makefile will output something like: