传播多个make命令

时间:2014-09-11 23:54:14

标签: c makefile gnu

我有一个基本上看起来像这样的makefile:

testa:
  make -C dog/ testa
  make -C cat/ testa
testb:
  make -C dog/ testb
  make -C cat/ testb

有多个文件夹1 ... 10。当我在顶层运行'make testa'时,它逐个遍历所有子目录,并在下面的所有文件夹上运行命令'make testa'。有没有更好的方法来实现这一点,而不是使用相同make -C folderx/ testy的几行? 感谢

2 个答案:

答案 0 :(得分:1)

您可以使用target-specific values

将目标名称与子目录分离
testa: TARG:=testa
testb: TARG:=testb

testa testb:
    make -C dog/ $(TARG)
    make -C cat/ $(TARG)

然后将工作委托给以子目录命名的目标:

testa: TARG:=testa
testb: TARG:=testb

SUBDIRS := dog cat

testa testb: $(SUBDIRS)

.PHONY: $(SUBDIRS)
 $(SUBDIRS):
        make -C $@ $(TARG)

答案 1 :(得分:0)

这是一个解决方案:

TARGETS := testa testb
DIRS := dog cat

define TARGETS_TO_DIRS

$(foreach target, $1, $(eval $(target): $(addsuffix /$(target), $2)))
$(foreach dir, $2, $(foreach target, $1, $(dir)/$(target))):
    $(MAKE) -C $$(@D) $$(@F)

endef

$(eval $(call TARGETS_TO_DIRS, $(TARGETS), $(DIRS)))
相关问题