Pre-build step in makefile

前端 未结 5 1032
广开言路
广开言路 2021-01-31 09:04

How can I run a script, which must execute before all other makefile commands? And it will be nice (but not mandatory) to the script is not executed if there is nothing to build

5条回答
  •  别那么骄傲
    2021-01-31 09:32

    You could add a special target to your Makefile and have all your build rules depend on that:

    run-script:
        myscript
    
    .o.c: run-script
         $(CC) $(CFLAGS) -o $@ $<
    
    .o.S: run-script
         $(AS) $(AFLAGS) -o $@ $<
    

    Depending on what your script actually does, putting it to run once in a stage before the Makefile (configure stage in autoconf terms) could make even more sense (and be less work).

提交回复
热议问题