ice*_*man 5 makefile wildcard find
TL;DR:我如何使用find
inMakefile
来识别相关的源文件(例如,所有.c
文件)?我知道如何使用 awildcard
但我无法find
开始工作。
更长的版本:
我将 aMakefile
作为共享库练习的一部分;我注意到,当我使用以下几行为.c
我的共享库指定源文件和目标文件(即文件)时,运行make
( gcc fatal error: no input files
)后出现错误:
SRC=$(find src/ -maxdepth 1 -type f -regex ".*\.c")
OBJ=$(patsubst %.c,%.o,$(SRC))
*rest-of-makefile*
Run Code Online (Sandbox Code Playgroud)
但是,当我使用wildcard
而不是find
:
SRC=$(wildcard src/*.c)
OBJ=$(patsubst %.c,%.o,$(SRC))
*rest-of-makefile*
Run Code Online (Sandbox Code Playgroud)
(作为参考,下面包括确认该find
命令在从 shell 运行时确实返回了预期的文件。)
使用find
命令(在 my 中Makefile
)搜索我的源文件(如果可能的话)的正确语法是什么?
(为什么我更喜欢使用 find?:我喜欢这样一个事实,即我可以find
通过从 shell 运行命令来快速复查语句的结果;我不能用 来做到这一点wildcard
。另外,我想依靠如果可能,在正则表达式上。)
作为参考,下面是相关的树结构。正如您所看到的(从下面的第二个代码块),运行find
Makefile 中指定的命令(即,从上面)确实返回了预期的文件 ( src/libex29.c
)。换句话说,上述问题不是因为find
选项或正则表达式中的语法问题。
.
??? build
??? Makefile
??? src
? ??? dbg.h
? ??? libex29.c
? ??? minunit.h
??? tests
??? libex29_tests.c
??? runtests.sh
Run Code Online (Sandbox Code Playgroud)
find
从.
上面的文件夹运行的结果:
~/lchw30$ find src/ -maxdepth 1 -type f -regex ".*\.c"
src/libex29.c
Run Code Online (Sandbox Code Playgroud)
PS 我知道这篇文章在技术上违反了规则all posted code must compile
- 我只是认为包括源文件Makefile
和libex29.c
源文件的整个代码会过大。如果情况并非如此,请告诉我 - 如果人们愿意,很乐意完整发布文件。
make 没有find
函数。您必须使用该shell
函数来运行查找。此外,出于性能原因,您应该始终使用:=
not =
for shell
(并且wildcard
,就此而言)。为了清楚起见,您应该在 make 中的作业周围放置空格:
SRC := $(shell find src/ -maxdepth 1 -type f -regex ".*\.c")
Run Code Online (Sandbox Code Playgroud)
我也不明白你为什么要在find
这里使用。 find
如果您想搜索包含多个级别的整个子目录结构,这是很好的,但wildcard
对于简单的目录查找来说效率更高。
归档时间: |
|
查看次数: |
7938 次 |
最近记录: |