Makefile - 将多个文件夹中的头文件复制到一个包含依赖项的包含文件夹中
我在不同的文件夹中有多个文件,需要将它们复制到一个包含文件夹中:
在 make
之前
../security/security_features.h
../this/this_features.h
[etc]
../that/that_features.h
make
之后
./include/security_features.h
./include/this_features.h
[etc]
./include/that_features.h
./include 文件夹中的文件都需要依赖于各个文件夹中的文件。
Makefile 对我来说有点神秘,我尝试阅读手册并了解如何建立依赖关系:
./include/security_features.h: ../security/security_features.h
@cp -av $< $@
但我必须对我的所有文件执行此操作 - 还有另一种更优雅的方法吗?
理想情况下,我只想编写分散文件夹中各种文件的 Makefile 变量,并且 makefile 知道将该变量中的所有文件复制到包含文件夹中。
有没有 Makefile 专家?
谢谢,
马特
更新:
我已经成功地完成了这样的文件列表:
INCLUDES_SRC := ../security/security_features.h ../this/this_features.h
INCLUDES_DST := $(addprefix ./include/,$(notdir $(INCLUDES_SRC)))
并且可以使一个依赖于另一个:
$(INCLUDES_DST): $(INCLUDES_SRC)
@cp -av $< $@
但是,这只是复制第一个先决条件(../security/security_features.h
)两次到两个目标(./include/security_features.h
,./include/this_features.h
):
'../security/security_features.h' -> './include/security_features.h'
'../security/security_features.h' -> './include/this_features.h'
所以我现在有一个 src 和destination 的 make 变量列表文件位置 - 有人知道如何依次复制所有文件吗?
谢谢马特
I have multiple files in various folders that I need to copy to one include folder:
Before make
../security/security_features.h
../this/this_features.h
[etc]
../that/that_features.h
After make
./include/security_features.h
./include/this_features.h
[etc]
./include/that_features.h
The files in the ./include folder all need to be dependent on the files in the various folders.
Makefiles are a bit of a mystery to me, I have tried to read the manuals and understand how to make dependencies:
./include/security_features.h: ../security/security_features.h
@cp -av lt; $@
But I'll have to do this for all my files - is there another more elegant way?
Ideally I'd just like to write a Makefile variable of the various files in the scattered folders and the makefile know to copy all the files in that variable to the include folder.
Any Makefile gurus out there?
Thanks,
Matt
UPDATE:
I have managed to do the list of files as such:
INCLUDES_SRC := ../security/security_features.h ../this/this_features.h
INCLUDES_DST := $(addprefix ./include/,$(notdir $(INCLUDES_SRC)))
And can make one dependent on the other:
$(INCLUDES_DST): $(INCLUDES_SRC)
@cp -av lt; $@
However this just copying the first prerequisite (../security/security_features.h
) both times to the two targets (./include/security_features.h
, ./include/this_features.h
):
'../security/security_features.h' -> './include/security_features.h'
'../security/security_features.h' -> './include/this_features.h'
So I now have a make variable list of src and destination locations for files - anyone know how to copy all the files in turn?
Thanks
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的规则的问题
在于:它使每个源标头成为每个目标标头的先决条件,并且仅复制第一个标头(使用
$<
)。这样就可以了:
粗略翻译,这意味着“制作
include/something
,找到something
并将其复制到include/
,当查找时对于xh
形式的文件,请查看security/
和this/
。”(请注意,如果您有两个同名的标头,则会错过其中一个,但在这种情况下,无论如何您都无法将它们都放入
include
中。)如果您有很多源目录如果您不想将它们全部输入,Make 可以跟踪它们:
The trouble with your rule:
is that it makes every source header a prerequisite of every destination header, and copies only the first one (with
$<
).This will do it:
Roughly translated, this means "to make
include/something
, findsomething
and copy it toinclude/
, and when looking for a file of the formx.h
, look insecurity/
andthis/
."(Note that if you have two headers with the same name this will miss one of them, but in that case you couldn't get them both into
include
anyway.)If you have a lot of source directories and you don't want to type them all in, Make can keep track of them:
这是一个棘手的问题。我发现的最佳解决方案是这样的:
更新:也许我应该解释一下这里发生的情况:
include/a_feature.h
。$(HEADERS): include/%_feature.h: %
行让所有头文件依赖于它们的基本功能名称,即它替换 *include/SOMETHING_feature.h*与一些东西。不幸的是,它不检查 ../FEATURE 目录中头文件的时间戳。
干杯,
马丁。
that's a tricky one. Best solution I found is this:
Update: Maybe I should explain a little bit what happens here:
include/a_feature.h
.$(HEADERS): include/%_feature.h: %
lets all header files depend on their base feature names, i. e. it replaces *include/SOMETHING_feature.h* with SOMETHING.Unfortunately, it doesn't check timestamps of the header files in the ../FEATURE directory.
Cheers,
Martin.