将 makefile 变量值分配给 bash 命令结果?
我试图将此命令的输出(位于我的 makefile 中)分配给 makefile HEADER var,如以下代码行所示:
HEADER = $(shell for file in `find . -name *.h`;do echo $file; done)
问题是,如果我使用以下命令在 makefile 中打印 HEADER:
print:
@echo $(HEADER)
我得到
ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile
如果我运行这个命令直接在控制台中,并且直接在我的makefile所在的位置:
myaccount$ for file in `find . -name *.h`;do echo $file; done
./engine/helper/crypto/tomcrypt/headers/._tomcrypt_pk.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_argchk.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_cfg.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_cipher.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_custom.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_hash.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_mac.h
....
所以我得到了所有的头文件。我这样做是为了避免在 makefile 中手动指定所有 .h 文件。
有什么想法吗?
I'm trying to assign the output of this command ( that is in my makefile ) to the makefile HEADER var like in this following line of code:
HEADER = $(shell for file in `find . -name *.h`;do echo $file; done)
The problem is that if I print HEADER in my makefile using:
print:
@echo $(HEADER)
I get
ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile
And if I run this command directly in the console, and directly where my makefile is:
myaccount$ for file in `find . -name *.h`;do echo $file; done
./engine/helper/crypto/tomcrypt/headers/._tomcrypt_pk.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_argchk.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_cfg.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_cipher.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_custom.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_hash.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_mac.h
....
So I get all my header files. I'm doing this to avoid manually specifying all my .h files manually in my makefile.
Any ideas ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在 shell 命令中对
$
字符进行双重转义:这里的问题是 make 会尝试将
$f
扩展为变量,并且因为它不这样做找不到任何东西,它只是将其替换为“”。这使得你的 shell 命令除了echo ile
之外什么也没有,它确实做到了。添加
$$
告诉 make 在该位置放置一个$
,这会导致 shell 命令看起来完全符合您想要的方式。You will need to double-escape the
$
character within the shell command:The problem here is that make will try to expand
$f
as a variable, and since it doesn't find anything, it simply replaces it with "". That leaves your shell command with nothing butecho ile
, which it faithfully does.Adding
$$
tells make to place a single$
at that position, which results in the shell command looking exactly the way you want it to.为什么不简单地做
Why not simply do
makefile 教程建议使用
通配符< /code> 获取目录中的文件列表。在你的情况下,这意味着:
The makefile tutorial suggested to use
wildcard
to get list of files in a directory. In your case, it means this :