Check if a program exists from a Makefile

后端 未结 12 1099
时光取名叫无心
时光取名叫无心 2020-12-12 20:20

How can I check if a program is callable from a Makefile?

(That is, the program should exist in the path or otherwise be callable.)

It could be used to chec

12条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 20:24

    I am personally defining a require target which runs before all the others. This target simply runs the version commands of all requirements one at a time and prints appropriate error messages if the command is invalid.

    all: require validate test etc
    
    require:
        @echo "Checking the programs required for the build are installed..."
        @shellcheck --version >/dev/null 2>&1 || (echo "ERROR: shellcheck is required."; exit 1)
        @derplerp --version >/dev/null 2>&1 || (echo "ERROR: derplerp is required."; exit 1) 
    
    # And the rest of your makefile below.
    

    The output of the below script is

    Checking the programs required for the build are installed...
    ERROR: derplerp is required.
    makefile:X: recipe for target 'prerequisites' failed
    make: *** [prerequisites] Error 1
    

提交回复
热议问题