makefile:如何 运行 WSL 中的单个命令

makefile: How to run a single command in WSL

我打算 运行 make 在 Windows 上安装了 WSL。

通常,我可以 运行 在 CMD 或 Powershell 中说 wsl date 暂时 运行 WSL 中的单个命令,但我无法在 Makefile 中执行相同的操作.

我试过普通的 wsl date,结果是

process_begin: CreateProcess(NLL, wsl date, ...) failed.
make (e=2): The system cannot find the file specified.

我尝试使用 $(wsl) date,它 运行 是 CMD 版本 date,而不是预期的 Linux 版本。

有谁知道正确的方法吗?谢谢!


一个最小的案例:

##### Call the WSL to run a command
call-wsl:
    C:\Windows\System32\wsl.exe date

运行 make call-wsl, 它给出

C:\Windows\System32\wsl.exe date
process_begin: CreateProcess(NULL, C:\Windows\System32\wsl.exe date, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [makefile:3: call-wsl] Error 2

Chocolatey 安装的 GNU Make 是一个 32 位程序。所以我们必须使用C:\Windows\sysnative\wsl.exe才能正确调用wsl.exe.