如何使Makefile规则执行其先决条件? [英] How do I make a makefile rule execute its prerequisites?

查看:117
本文介绍了如何使Makefile规则执行其先决条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个makefile,其中包含构建系统,测试和运行它们的规则.最后一项仅通过调用shell脚本执行.除其他外,这使我无法并行运行测试.

I have a makefile containing rules to build the system, tests, and run them. The last item is executed by just calling a shell script. Among other things, this prevents me from running the tests in parallel.

我有以下变量:

TEST_SRC=$(wildcard tests/*.c)
TESTS=$(patsubst %.c,%,${TEST_SRC})

并使用规则构建测试

$(TESTS): %: %.c
    $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<

是否可以(如果可以,如何?)创建规则测试",该规则在运行时将执行$TESTS变量中的每个项目?

Is it possible (and if so, how?) to create a rule "tests" that, when run, will execute each item in the $TESTS variable?

推荐答案

您可以这样做:

# a separate target to run each test
RUN_TESTS = $(addprefix run_, $(TESTS))

# a pattern rule for those targets, which will remake the test iff neccessary
.PHONY: $(RUN_TESTS)
$(RUN_TESTS):run_%:%
  ./$<

# One Rule to Ring Them All, One Rule to... sorry.
.PHONY: tests
tests: $(RUN_TESTS)

这篇关于如何使Makefile规则执行其先决条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆