我有一个看起来像这样的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 all
或make test_if_some_binary_exists
时,我得到一个错误,好像二进制文件不存在(事实上它确实存在):
$ make test_if_some_binary_exists
makefile:9: *** 'some-binary' not found!. Stop.
如何在GNU makefile
中正确测试二进制的存在 - 可能是符号链接?