I have a (GNU) makefile with an all target that looks like this:
.PHONY: all
all: $(unittest++_tests_exe) $(cmockery_tests_exe)
@echo Running UnitTest++ tests...
@./$(unittest++_tests_exe)
@echo Running Cmockery tests...
@./$(cmockery_tests_exe)
The UnitTest++ 开发者_JAVA百科tests run on both Linux and Mac OS X, and the Cmockery tests run only on Linux.
How do I modify the dependencies and rules so that make all
only builds and runs $(unittest++_tests_exe)
on Mac OS X?
T.E.D.'s answer triggered me to come up with the following:
ifeq ($(uname),Linux)
cmockery_tests_exe = cmockery_tests
else
cmockery_tests_exe = $()
endif
.PHONY: all
all: $(unittest++_tests_exe) $(cmockery_tests_exe)
@echo Running UnitTest++ tests...
@./$(unittest++_tests_exe)
ifeq ($(uname),Linux)
@echo Running Cmockery tests...
@./$(cmockery_tests_exe)
endif
It seems to work, but I welcome your suggestions.
I believe the Right Way to do this is to use something like autoconf.
If you want to hack it, try calling uname and putting the result in a symbol. You can then parse out the relevant parts
精彩评论