如何使用 gnuwin32 Makefile 执行 powershell/cmd 命令?
How to execute powershell/cmd commands using gnuwin32 Makefiles?
我尝试使用以下 makefile 处理器在 Windows 中的 makefile 中使用 curl、rm、start 等命令:http://gnuwin32.sourceforge.net/packages/make.htm
这似乎是不可能的,而且我似乎对命令非常有限。有哪些方法可以扩展我的命令集?
如有任何帮助,我将不胜感激。谢谢
您可以通过在相应命令前加上powershell 来使用powershell 的强大功能。
示例:
.PHONY: psStuff
psStuff:
powershell <your command>
powershell curl google.de
powershell rm -r folder
powershell start yourwebsite.de
如果您满足于Windows-仅解决方案 ,您可以直接从 Makefile
调用 powershell.exe
,如 .
但是,我强烈建议避免使用类似 Unix 的 PowerShell 别名,例如 curl
用于 Invoke-WebRequest
和rm
用于 Remove-Item
,因为虽然它们的目的在抽象上相似,但它们的 语法通常非常不同 。只需 使用 PowerShell 的 本地命令名称 以避免歧义。
请注意,使用 Shell := <default shell executable>
似乎会被您 link 的 make
的 Windows 端口忽略。
如果想要跨平台兼容性:
要么:使用WSL,它为您提供了 Linux 发行版的选择,其中 make
和 标准的 Unix 实用程序是本机可用的 - 然后您既不需要 cmd.exe
也不需要 PowerShell。
and/or: 使用 PowerShell Core 并按如下方式调用您的命令:
pwsh -noprofile -command <your command>
- 在 Windows 上使用 WSL 的跨平台解决方案中,您可以通过在
MakeFile
顶部声明 SHELL := pwsh -NoProfile
来简化调用,之后您可以调用 PowerShell (核心)直接命令。
我尝试使用以下 makefile 处理器在 Windows 中的 makefile 中使用 curl、rm、start 等命令:http://gnuwin32.sourceforge.net/packages/make.htm
这似乎是不可能的,而且我似乎对命令非常有限。有哪些方法可以扩展我的命令集?
如有任何帮助,我将不胜感激。谢谢
您可以通过在相应命令前加上powershell 来使用powershell 的强大功能。
示例:
.PHONY: psStuff
psStuff:
powershell <your command>
powershell curl google.de
powershell rm -r folder
powershell start yourwebsite.de
如果您满足于Windows-仅解决方案 ,您可以直接从 Makefile
调用 powershell.exe
,如
但是,我强烈建议避免使用类似 Unix 的 PowerShell 别名,例如 curl
用于 Invoke-WebRequest
和rm
用于 Remove-Item
,因为虽然它们的目的在抽象上相似,但它们的 语法通常非常不同 。只需 使用 PowerShell 的 本地命令名称 以避免歧义。
请注意,使用 Shell := <default shell executable>
似乎会被您 link 的 make
的 Windows 端口忽略。
如果想要跨平台兼容性:
要么:使用WSL,它为您提供了 Linux 发行版的选择,其中
make
和 标准的 Unix 实用程序是本机可用的 - 然后您既不需要cmd.exe
也不需要 PowerShell。and/or: 使用 PowerShell Core 并按如下方式调用您的命令:
pwsh -noprofile -command <your command>
- 在 Windows 上使用 WSL 的跨平台解决方案中,您可以通过在
MakeFile
顶部声明SHELL := pwsh -NoProfile
来简化调用,之后您可以调用 PowerShell (核心)直接命令。
- 在 Windows 上使用 WSL 的跨平台解决方案中,您可以通过在