Make是这样的技术之一,无论我是否理解它,我都会在这些技术之间来回交流。
这当然是我知道我做错了什么的一个例子,因为Make是为了减少这些任务的重复性而开发的。
all: 24.1 24.2 24.3
24.1:
evm install emacs-24.1-bin || true
emacs --version
emacs --batch -L . -l ert -l test/tests.el -f ert-run-tests-batch-and-exit
24.2:
evm install emacs-24.2-bin || true
emacs --version
emacs --batch -L . -l ert -l test/tests.el -f ert-run-tests-batch-and-exit
24.3:
evm install emacs-24.3-bin || true
emacs --version
emacs --batch -L . -l ert -l test/tests.el -f ert-run-tests-batch-and-exit如何编辑这个Makefile,使其只列出一次测试序列,却能够针对多个版本进行测试?
发布于 2014-11-09 11:28:21
试试这个:
VERSIONS = 24.1 24.2 24.3
all :: $(VERSIONS)
$(VERSIONS) ::
evm install emacs-$@-bin || true
emacs --version
emacs --batch -L . -l ert -l test/tests.el -f ert-run-tests-batch-and-exit::是一种特殊的规则,它将目标作为假的(并且还具有其他属性)。
发布于 2014-11-08 22:14:20
不如:
all: 24.1 24.2 24.3
%:
evm install emacs-$@-bin || true
emacs --version
emacs --batch -L . -l ert -l test/tests.el -f ert-run-tests-batch-and-exit发布于 2014-11-08 23:51:17
我不得不承认,求助于“最后手段”的策略总是让我感到不舒服:这感觉似乎违背了工具的本质。另一方面,BSD make允许显式循环构造,因此消除重复规则是很简单的:
VERSIONS = 24.1 24.2 24.3
all: ${VERSIONS}
.for VERSION in ${VERSIONS}
${VERSION}:
evm install emacs-${VERSION}-bin || true
emacs --version
emacs --batch -L . -l ert -l test/tests.el -f ert-run-tests-batch-and-exit
.endfor我很清楚,这个解决方案几乎肯定不会对您有任何帮助;切换make实现几乎是不可能的。然而,BSD make的代表严重不足,因此我认为其他人可能会对另一种方法进行文档化。
正如MadScientist正确指出的那样,GNU不支持像.for这样的“点结构”,这对于BSD来说是特别的。然而,这个问题提出了其他一些可能适用于GNU的循环技术:How to write loop in a Makefile?
https://stackoverflow.com/questions/26822036
复制相似问题