Force Makefile to execute script before building targets

后端 未结 4 1340
予麋鹿
予麋鹿 2020-12-08 10:26

I am using Makefiles.

However, there is a command (zsh script) I want executed before any targets is executed. How do I do this?

Thanks!

4条回答
  •  醉梦人生
    2020-12-08 10:42

    There is a solution without modifying your existing Makefile (main difference with the accepted answer). Just create a makefile containing:

    .PHONY: all
    
    all:
        pre-script
        @$(MAKE) -f Makefile --no-print-directory $(MAKECMDGOALS) MAKE='$(MAKE) -f Makefile'
        post-script
    
    $(MAKECMDGOALS): all ;
    

    The only drawback is that the pre- and post- scripts will always be run, even if there is nothing else to do. But they will not be run if you invoke make with one of the --dry-run options (other difference with the accepted answer).

提交回复
热议问题