1

我有一个问题,我想创建一个看起来像这样的变量,

INCDIRS = -I dir0 -I dir1 -Idir2 -I dir3 ... -I dirN

其中dir1, ... , dirN是某个基目录base_dir的所有子目录的名称。

我将如何构建这个变量?最初,我认为我可以执行以下操作,

INCDIRS = $(shell for x in `find base_dir -type -d -print`; do echo -I $x; done;)

但这只会导致

INCDIRS = -I -I -I -I ... -I

如果有人能解释如何做到这一点,或者解释为什么我的原始命令得到了它的输出,我将不胜感激。谢谢!

4

2 回答 2

2

You could first get the list of directories, then add -I in front of each one:

SOURCE_DIRS := $(shell find base_dir -type d -print)
INCDIRS      = $(addprefix -I,$(SOURCE_DIRS))

which may be better if you need $(SOURCE_DIRS) for something else.

于 2012-11-21T17:45:32.493 回答
2

你的INCDIRS作业中有两个错误。一是在find命令中。它应该是find -type d -print(或只是find -type d-print这里是多余的)。使用的另一个错误$x。你需要$用另一个来逃避$

INCDIRS = $(shell for x in `find base_dir -type d -print`; do echo -I $$x; done;)
于 2012-11-21T02:33:49.603 回答