仅当文件存在时才作为目标

Awa*_*ias 0 unix bash makefile

在我的makefile文件中,我想执行以下操作:

all: foo bar python

python:
    if /usr/bin/someprogram
        do some stuff
    else
        echo "not doing some stuff, coz someprogram ain't there"
    endif
Run Code Online (Sandbox Code Playgroud)

最简单的方法是什么?

dev*_*ull 5

一种简单的方法是使用test

python:
    @test -s /usr/bin/someprogram && echo "someprogram exists" || echo "someprogram does not exist"
    @test -s /bin/ls && echo "ls exists" || echo "ls does not exist"
Run Code Online (Sandbox Code Playgroud)

就像@MadScientist所说的那样,如果您想做很多事情,您可能需要一个if语句:

python:
        if [ -s /bin/ls ]; then \
          echo "ls exists"; \
        fi;
Run Code Online (Sandbox Code Playgroud)