'=' 的转义字符是什么? GNU make 中的符号?

发布于 2024-12-13 02:45:43 字数 298 浏览 6 评论 0原文

我想通过将环境变量 CPU_TYPE 及其值 -mcpu=603 作为命令行参数传递给该 makefile 来调用 makefile。我正在输入以下命令

make -f make_file CPU_TYPE=-mcpu=603

但它给出了错误,因为环境变量值具有 = 符号。如何在环境值中转义这个等号。

注意:我无法在 make_file 中添加此环境变量或任何其他变量。我必须仅将其作为命令行参数传递。

I want to call a makefile by passing the environment variable CPU_TYPE and its value -mcpu=603 as command line argument to that makefile. I am entering the below command

make -f make_file CPU_TYPE=-mcpu=603

But its given error because environment variable value is having = symbol. How to escape this equal symbol in the environment value.

Note : I cant add this environment variable or any other variable inside make_file. I have to pass it as command line arugments only.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

呆橘 2024-12-20 02:45:43

不太可能

应该不会有任何问题,但也许您遇到了很少使用的 shell 功能。

如果您在正在运行的 shell 中使用 set -k 或使用 sh -k 运行 shell,它会将任何看起来像环境变量的内容视为环境变量。

您可能已经知道,C shell 系列以外的 shell 可以通过在命令之前添加环境变量来为单个命令设置环境变量:

PATH="/somewhere/else:$PATH" cmdname -opts file1 file2

命令本身会看到修改后的环境; shell 对 cmdname 的搜索不会改变。但是,在 set -k 生效后,任何看起来像环境变量的变量都会被视为环境变量:

cmdname -opts PATH="/somewhere/else:$PATH" file1 file2

例如,您可以使用 env 作为命令来验证这一点。有充分的理由(例如 dd 命令)不将此设置为默认行为。

反对这个假设

反对这个假设,我不知道有哪个 shell 会反对环境值中的“=”。如果有这样的限制,那就太麻烦了。

普通 GNU Make 是可以的

但是,我可以这样做:

make CFLAGS='-Dxyz=pqr' progname

并且,在 set -k 生效的情况下,我还可以这样做:

make -e CFLAGS='-Dxyz=pqr' progname

在这两种情况下,编译都会采用通过命令行指定的值覆盖 makefile 中的设置。

make看不到单引号;当然,它们会被外壳去除。你完全可以忽略它们,我得到相同的结果。我在 MacOS X 上使用 bash 运行,但我希望在任何使用任何标准 POSIX-ish shell(Bourne、Korn、Bash)的类 Unix 系统上得到相同的结果。

Improbable possibility

There shouldn't be any problem, but maybe you are running afoul of a seldom-used shell feature.

If you use set -k in a running shell, or use sh -k to run a shell, it will treat anything that looks like an environment variable as an environment variable.

You probably already know that shells other than the C shell family can set an environment variable for a single command by adding it before the command:

PATH="/somewhere/else:$PATH" cmdname -opts file1 file2

The command itself sees the modified environment; the shell's search for cmdname is not altered. However, with set -k in effect, anything that looks like an environment variable is treated as one:

cmdname -opts PATH="/somewhere/else:$PATH" file1 file2

You can validate this by using env, for example, as the command. There are sound reasons (such as the dd command) for not making this the default behaviour.

Against the hypothesis

Against this hypothesis, I don't know of a shell that objects to the '=' in the environment value. It would be a nuisance if there was such a restriction.

Plain GNU Make is OK

However, I'm able to do:

make CFLAGS='-Dxyz=pqr' progname

and, with set -k in effect, I can also do:

make -e CFLAGS='-Dxyz=pqr' progname

In both cases, the compilation takes the value specified via the command line as overriding what is set in the makefile.

The single quotes aren't seen by make; they are removed by the shell, of course. You can perfectly well omit them and I get the same result. I'm running using bash on MacOS X, but I'd expect the same results on any Unix-like system using any of the standard POSIX-ish shells (Bourne, Korn, Bash).

骄傲 2024-12-20 02:45:43

我不确定是否有直接的方法来实现你想要的。

但也许您可以修改您的Makefile,以便它通过例如读取文件来设置CPU_TYPE。您可以在 make_file 中放入类似的内容

CPU_TYPE=$(shell cat $(CPU_TYPE_FILE))

,然后使用eg创建一个文件my603.cputype

echo '-mcpu=603' > my603.cputype

,最后运行 make 作为

make -f make_file CPU_TYPE_FILE=my603.cputype

I'm not sure there is a direct way to achieve what you want.

But perhaps you might modify your Makefile so that it sets the CPU_TYPE by e.g. reading a file. You might put in your make_file something like

CPU_TYPE=$(shell cat $(CPU_TYPE_FILE))

and then create a file my603.cputype with e.g.

echo '-mcpu=603' > my603.cputype

and finally run make as

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