Pre-build step in makefile

前端 未结 5 1128
广开言路
广开言路 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:34

    Thank you for answers. ndim helped me much, asveikau. The final file is one binary executable, so I can use now something like this:

    run-script:
        myscript
    $(AXF_FILE): run-script $(OBJ_DIRS) $(OBJ_FILES)
        $(LINK) #......
    

    It will run myscript once. {AXF_FILE} value depends on myscript and I must run it before. And in this case myscript runs always, not only when rebuild is needed. After, The Simplest Answer came to my mind:

    all: run-script $(AXF_FILE)
    

    That's all ;) (Of course, any target can be used instead of "all")


    Edit: this method execute script after $(AXF_FILE) is calculated too. So it's possible to get wrong value of AXF_FILE. Now only the first answer by ndim works as I need.

提交回复
热议问题