【问题标题】:exec basename not working from windows makefileexec basename 不能从 Windows makefile 工作
【发布时间】:2019-09-07 07:00:11
【问题描述】:

我正在制作一个包含以下语句的 windows make 文件

Win10_SDK_Version := $(shell find $(WROOT_WIN10_SDK)/Include -maxdepth 1 -type d -path $(WROOT_WIN10_SDK)/Include/[0-9.]* -exec basename {}\; 2> output.txt | sort | tail -n 1)

但是,我看到变量 Win10_SDK_Version 未填充。为了调试,我在此行之前打印了变量 $(WROOT_WIN10_SDK) 并按预期填充了它

WROOT_WIN10_SDK=["E:/Myscpetre20/depot/sim/sim-20fq1/build/gobuild/compcache/cayman_msvc_desktop/ob-11144741/windows2016-clean/win/Program Files/Windows Kits/10"]

而且output.txt文件的内容说语句失败--find: basename: No such file or directory

如果我将上面的语句缩短到下面,不包括 exec basename---

Win10_SDK_Version := $(shell find $(WROOT_WIN10_SDK)/Include -maxdepth 1 -type d -path $(WROOT_WIN10_SDK)/Include/[0-9.]* 2> output.txt | sort | tail -n 1)

上面的语句执行得很好,所以确定这是我使用“-exec basename {}\;”的方式有问题。我还尝试在 basename 中包含单引号,如下所示--

Win10_SDK_Version := $(shell find $(WROOT_WIN10_SDK)/Include -maxdepth 1 -type d -path $(WROOT_WIN10_SDK)/Include/[0-9.]* -exec 'basename {}'\; 2> output.txt | sort | tail -n 1)

但即使这样失败了,谁能指导我如何在上述语句中正确包含 exec basename ?

【问题讨论】:

    标签: windows makefile build gnu-make


    【解决方案1】:

    一般来说,在处理 make 和 makefile 时,您应该避免使用包含空格的路径。很难做到。

    如果您需要使用WROOT_WIN10_SDK 变量的唯一位置是在recipes 和shell 命令内部,那么可以这样做,但您必须记住正确引用该变量。

    这样写你的命令可能会更简单:

    Win10_SDK_Version := $(shell (cd '$(WROOT_WIN10_SDK)/Include' && ls -1 [0-9.]*) 2> output.txt | sort | tail -n 1)
    

    【讨论】:

    • 我明白你的意思,不要使用包含空格的路径,但出于遗留原因,我需要使用这一行。基本上想知道如何更正我的命令的 exec basename 部分。
    • 我想告诉你的是,这不是你的命令的基本名称部分是错误的。您遇到的问题是,因为您没有引用包含空格的变量,shell 会错误地解析它。您可以从 shell 提示符(UNIX shell,而不是 command.com)运行此命令并遇到同样的问题。它根本不相关(在这种情况下)。如果你想在 shell 命令中使用带有空格的路径,你必须引用它们。
    • 现在明白了谢谢
    猜你喜欢
    • 2013-05-19
    • 1970-01-01
    • 2017-01-15
    • 1970-01-01
    • 2012-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多