在每个子目录中运行make [英] Run make in each subdirectory

查看:92
本文介绍了在每个子目录中运行make的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个目录(root_dir),其中包含许多子目录(subdir1, subdir2, ...).

I have a directory (root_dir), that contains a number of sub-directories (subdir1, subdir2, ...).

我想使用放置在其中的Makefile在root_dir中的每个目录中运行make. (显然,每个subdir...都有其自己的Makefile).

I want to run the make in each directory in root_dir, using a Makefile placed in it. (Obviously supposed that each of subdir... has inside its own Makefile).

所以本质上有两个问题:

So there are essentially two questions:

  1. 如何自动获取Makefile中的目录列表?
  2. 如何为make文件中的每个目录运行make?

我知道要在特定目录中运行make时,我注意执行以下操作:

As I knwow in order to run make in a specific directory I heed to do the following:

$(MAKE) -C subdir

推荐答案

在单个配方中的for循环中执行sub-make时会遇到各种问题.做多个子目录的最佳方法是这样的:

There are various problems with doing the sub-make inside a for loop in a single recipe. The best way to do multiple subdirectories is like this:

SUBDIRS := $(wildcard */.)

all: $(SUBDIRS)
$(SUBDIRS):
        $(MAKE) -C $@

.PHONY: all $(SUBDIRS)

(只需指出这是GNU make特定的;您没有提到对所使用的make版本的任何限制).

(Just to point out this is GNU make specific; you didn't mention any restrictions on the version of make you're using).

ETA 这是一个支持多个顶级目标的版本.

ETA Here's a version which supports multiple top-level targets.

TOPTARGETS := all clean

SUBDIRS := $(wildcard */.)

$(TOPTARGETS): $(SUBDIRS)
$(SUBDIRS):
        $(MAKE) -C $@ $(MAKECMDGOALS)

.PHONY: $(TOPTARGETS) $(SUBDIRS)

这篇关于在每个子目录中运行make的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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