读取 MinGW Makefile 中的 cmd.exe 变量
我正在 Makefile 中编写安装,需要在其中设置 PATH 环境。多变的。
在它的 Windows 部分,我发现了以下内容:
set
:通过set PATH="%PATH%;%CD%"
我可以更改PATH< /code> 运行环境中。这样做有两个问题:
- 环境是由 make 生成的
cmd.exe
,它的变量会受到影响,并且一旦关闭,效果就会被删除 - 即使之前的问题可以解决,但调用
make
的cmd.exe
有一天会关闭,修改后的PATH
也会丢失.
- 环境是由 make 生成的
setx
:一个可以永久改变环境的微软工具。变量。根据微软本身,这是唯一的命令行选项来执行此操作。但是,使用setx PATH "%PATH%;%CD%" -m
会将路径转换为文字%PATH%;%CD%
并且不会将变量替换为他们的内容!
请注意,我是从 cmd.exe
调用 make
,而不是 cygwin 或其他行为更像 Linux 的修改后的 Windows shell。我的意思是,虽然我可以在 makefile 中使用 $(PATH)
(而不是 %PATH%
),但我不能使用 pwd
(而不是 %CD%
)
另请注意,如果在 cmd 本身中我运行:
setx PATH "%PATH%;%CD%" -m
它工作得很好。不知何故,我需要让 make
执行这个命令。
您知道如何解决这个问题,或者我有什么解决方法吗?
PS 郑重声明一下,Makefile 中的 echo "%PATH%;%CD%"
也会回显文字 "%PATH%;%CD%"
而不是让 cmd .exe 处理它
I am writing installation in a Makefile in which I need to set the PATH env. variable.
In the windows part of it, I found the following:
set
: Withset PATH="%PATH%;%CD%"
I can change thePATH
inside the running environment. There are two problems with this:- The environment is a spawned
cmd.exe
by make which gets its variable affected and the effect removed as soon as it closes - Even if the previous problem could be solved, still the
cmd.exe
that callsmake
would close one day and the modifiedPATH
lost.
- The environment is a spawned
setx
: A microsoft tool that can permanently change env. variables. According to microsoft itself, this is the only command-line option to do this. Usingsetx PATH "%PATH%;%CD%" -m
however, turns path into the literal%PATH%;%CD%
and doesn't replace the variables by their contents!
Note that I am calling make
from cmd.exe
not cygwin or other modified windows shells that act more like linux. What I'm saying is that, although I can use $(PATH)
in my makefile (instead of %PATH%
), I can't use pwd
(instead of %CD%
)
Also note that if in cmd itself I run:
setx PATH "%PATH%;%CD%" -m
it works perfectly. Somehow I need to make make
execute this command.
Do you have any idea how to fix this, or what workaround do I have?
P.S. Just for the record, echo "%PATH%;%CD%"
in the Makefile also echoes the literal "%PATH%;%CD%"
rather than let cmd.exe handle it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那时,Borland C++ 免费命令行工具包含一个 make 版本,它可以与 dos/windows 命令行很好地配合。可能还在某个地方漂浮着。
Back in the day i Borland C++ Free Command Line tools included a version of make which played well with the dos/windows command line. Probably still floating around somewhere.
解决方法:
创建一个
.bat
文件,将命令放在那里,然后从 Makefile 中调用它。不过,我仍然对 Makefile 中的直接修复感兴趣。
Workaround:
Create a
.bat
file, put the command there, and invoke it from the Makefile.I still am interested in a direct fix in the Makefile though.