读取 MinGW Makefile 中的 cmd.exe 变量

发布于 2025-01-01 09:55:30 字数 1165 浏览 8 评论 0原文

我正在 Makefile 中编写安装,需要在其中设置 PATH 环境。多变的。

在它的 Windows 部分,我发现了以下内容:

  • set:通过 set PATH="%PATH%;%CD%" 我可以更改 PATH< /code> 运行环境中。这样做有两个问题:
    • 环境是由 make 生成的 cmd.exe,它的变量会受到影响,并且一旦关闭,效果就会被删除
    • 即使之前的问题可以解决,但调用 makecmd.exe 有一天会关闭,修改后的 PATH 也会丢失.
  • 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: With set PATH="%PATH%;%CD%" I can change the PATH 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 calls make would close one day and the modified PATH lost.
  • setx: A microsoft tool that can permanently change env. variables. According to microsoft itself, this is the only command-line option to do this. Using setx 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 技术交流群。

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

发布评论

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

评论(2

戏舞 2025-01-08 09:55:30

那时,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.

静谧幽蓝 2025-01-08 09:55:30

解决方法:

创建一个 .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.

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