我想将cpputest作为 git 子模块包含在我的项目的源代码树中,但我对 autotools 并不十分熟悉。
我一直在看这个页面作为指南
我创建了以下 Makefile,cpputest 位于它下面的子目录中:
CPPUTEST_BUILD_DIR := cpputest/cpputest_build
CPPUTEST_LIBS := \
$(CPPUTEST_BUILD_DIR)/libCppUTest.a \
$(CPPUTEST_BUILD_DIR)/libCppUTestExt.a
CPPUTEST_TESTS := \
$(CPPUTEST_BUILD_DIR)/CppUTestTests \
$(CPPUTEST_BUILD_DIR)/CppUTestExtTests
cpputest: \
cpputest/configure \
$(CPPUTEST_BUILD_DIR)/Makefile \
$(CPPUTEST_LIBS) \
$(CPPUTEST_TESTS)
cpputest/configure: cpputest/configure.ac cpputest/autogen.sh
cd cpputest && ./autogen.sh
cpputest/cpputest_build/Makefile: cpputest/configure
cd $(CPPUTEST_BUILD_DIR) && ../configure
$(CPPUTEST_LIBS): $(CPPUTEST_BUILD_DIR)/Makefile
cd $(CPPUTEST_BUILD_DIR) && make
$(CPPUTEST_TESTS): $(CPPUTEST_LIBS)
cd $(CPPUTEST_BUILD_DIR) && make tdd
运行这个 makefile 可以满足我的要求,但我不确定依赖项有多强大。除了干净的规则之外,还有什么我应该考虑添加的吗?
这是John Bollinger 回答后我的最终 Makefile 。
它位于 CppUTest 目录的根目录中。
# This makefile will generate a platform specific makefile, build CppUTest
# library outputs, and build and run tests on CppUTest.
BUILD_DIR := cpputest_build
LIBS := $(BUILD_DIR)/lib/libCppUTest.a $(BUILD_DIR)/lib/libCppUTestExt.a
TESTS := $(BUILD_DIR)/CppUTestTests $(BUILD_DIR)/CppUTestExtTests
# All builds both libraries, to build and run all of the tests for CppUTest use
# the phony target run_tests.
all: $(LIBS)
.PHONY: all run_tests clean FORCE
# The Makefile rule depends on the "configure" shell script existing. If
# CppUTest is updated from upstream or configure doesn't exist then run
# autogen.sh or uncomment the rule below. All of the outputs autogen.sh should
# be tracked in the develop branch.
#
#configure: configure.ac autogen.sh
# ./autogen.sh
$(BUILD_DIR)/Makefile: configure
mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && ../configure
$(LIBS) : $(BUILD_DIR)/Makefile FORCE
cd $(BUILD_DIR) && make $(subst $(BUILD_DIR)/,,$@)
$(TESTS) : $(BUILD_DIR)/Makefile FORCE
cd $(BUILD_DIR) && make $(@F)
run_tests: $(TESTS)
for test in $(TESTS); do $$test -c || exit 1; done
clean:
rm -rf $(BUILD_DIR)