windows - 有没有办法用/代替 Gnu Make 命令目标?

标签 windows makefile portability gnu-make

我在 Windows 上运行递归 make,使用每个目录的目标,使用正斜杠分隔路径组件。如果有人跑

> make foo/bar

它会正常运行。但是如果有人跑

> make foo\bar

它找不到要构建的目标:

make: Nothing to be done for `foo\bar'.

如果我能在我的顶级 Makefile 中添加这样的东西,我会很高兴:

MAKECMDGOALS = $(subst \,/,$(MAKECMDGOALS))

但是这样的事情是行不通的。 MAKECMDGOALS 只能读取。或者即使我可以像这样为所有常规目标制作反斜杠目标:

$(DIRS): %: $(subst /,\,%)

但这也行不通。最好的解决方法是什么?

最佳答案

我想出了一个相当不错的方法来处理这个问题,而无需借助脚本来包装 make:

# $(call bstarget, foo foo/bar baz frob/niz)
# will result in the following targets being defined in place:
#   foo\bar: foo/bar
#   brob\niz: from/niz
bstarget = $(eval \
    $(foreach TARGET, $1, \
        $(if $(findstring /, $(TARGET)), \
            $(call bstargeteval, $(subst /,\,$(TARGET)), $(TARGET)))))
define bstargeteval
$1: $2

endef

然后可以在我的 Makefile 中使用 $(call bstarget, $(DIRS)) 调用它

关于windows - 有没有办法用/代替 Gnu Make 命令目标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3339891/

相关文章:

c++ - C 和 C++ .lib 文件是否可移植?

windows - 升级期间文件替换

C Makefile 给出具有多个定义的链接器错误

c - 在 Makefile 中获取源代码结构

c - "int"和 "int_fast16_t"有什么区别?

c - 是否有必要包含 <stdint.h> 以保证 C99 新类型的可移植性?

windows - 如何提取存储在 exe 中的路径(pdb 文件)?

windows - 笔记本电脑和 PC 之间的 git 服务器(MS Windows 7)

c# - 如何捕获 Windows 窗体组合框中的回车键

c - 海湾合作委员会 : Compiling with basic debbuging information added (flag -g) what are the effects on the performance?