将 makefile 变量值分配给 bash 命令结果?

发布于 2024-08-23 20:27:12 字数 1120 浏览 0 评论 0原文

我试图将此命令的输出(位于我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

看春风乍起 2024-08-30 20:27:12

您需要在 shell 命令中对 $ 字符进行双重转义:

HEADER = $(shell for file in `find . -name *.h`;do echo $file; done)

这里的问题是 make 会尝试将 $f 扩展为变量,并且因为它不这样做找不到任何东西,它只是将其替换为“”。这使得你的 shell 命令除了 echo ile 之外什么也没有,它确实做到了。

添加 $$ 告诉 make 在该位置放置一个 $ ,这会导致 shell 命令看起来完全符合您想要的方式。

You will need to double-escape the $ character within the shell command:

HEADER = $(shell for file in `find . -name *.h`;do echo $file; done)

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 but echo 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.

难以启齿的温柔 2024-08-30 20:27:12

为什么不简单地做

HEADER = $(shell find . -name '*.h')

Why not simply do

HEADER = $(shell find . -name '*.h')
╰沐子 2024-08-30 20:27:12

makefile 教程建议使用通配符< /code> 获取目录中的文件列表。在你的情况下,这意味着:

HEADERS=$(wildcard *.h)

The makefile tutorial suggested to use wildcard to get list of files in a directory. In your case, it means this :

HEADERS=$(wildcard *.h)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文