I'm looking for a way to bail out of a makefile if a certain string is not found when checking the version of a tool.
The grep expression I'm looking to match is:
dplus -VV | grep 'build date and time: Nov 1 2009 19:31:28'
which returns a matching line if the proper version of dplus is ins开发者_开发问答talled.
How do I work a conditional into my makefile based upon this expression?
Here's another way that works in GNU Make:
DPLUSVERSION = $(shell dplus -VV | grep 'build date and time: Nov 1 2009 19:31:28')
target_of_interest: do_things do_things_that_uses_dplus
do_things:
...
do_things_that_uses_dplus:
ifeq ($(DPLUSVERSION),)
$(error proper version of dplus not installed)
endif
...
This target can be something real, or just a PHONY target on which the real ones depend.
Here is one way:
.PHONY: check_dplus
check_dplus:
dplus -VV | grep -q "build date and time: Nov 1 2009 19:31:28"
If grep finds no match, it should give
make: *** [check_dplus] Error 1
Then have your other targets depend on the check_dplus target.
If this is gnu make, you can do
your-target: $(objects)
ifeq (your-condition)
do-something
else
do-something-else
endif
See here for Makefile contionals
If your make doesn't support conditionals, you can always do
your-target:
dplus -VV | grep -q "build date and time: Nov 1 2009 19:31:28" || $(MAKE) -s another-target; exit 0
do-something
another-target:
do-something-else
加载中,请稍侯......
精彩评论