测试是否在GNU make中找到二进制符号链接

时间:2015-08-18 22:30:00

标签: makefile gnu-make gnu

我有一个看起来像这样的GNU makefile

SOME_BINARY := $(shell `which some-binary` --help 2> /dev/null)

all: test_if_some_binary_exists

test_if_some_binary_exists:
ifdef SOME_BINARY
    @echo "some-binary found!"
else
    @$(error 'some-binary' not found!)
endif

假设我已经有一个名为some-binary的二进制文件,它使用选项--help并将帮助消息写入标准错误:

$ some-binary --help 
Some-Binary v1.2.3 (c) 2015 Foo Bar Baz
...

但是,它实际上是位于文件系统其他位置的文件的符号链接:

$ ls -l `which some-binary`
lrwxr-xr-x  1 alexpreynolds  admin  34 Aug 18 15:01 /usr/local/bin/some-binary -> ../Cellar/some-binary/1.2.3/bin/some-binary

当我运行make allmake test_if_some_binary_exists时,我得到一个错误,好像二进制文件不存在(事实上它确实存在):

$ make test_if_some_binary_exists
makefile:9: *** 'some-binary' not found!.  Stop.

如何在GNU makefile中正确测试二进制的存在 - 可能是符号链接?

0 个答案:

没有答案