makefile - makefile 中的 subst for-loop 元素?

标签 makefile

假设我的Makefile如下:

FILES = hello.py
PHONY: hi
hi:
    -@for file in $(FILES); do \
            (echo $$file; \
            echo $(subst py,xml,$$file); \
            echo $(subst py,xml,hello.py)); \
    done

当调用 make 时,将打印以下内容:

hello.py
hello.py
hello.xml

我可以知道为什么 echo $(subst py,xml,$$file);不按我想要的方式工作(回显 hello.xml 而不是 hello.ph)? 另外,如果您对如何修改此 for 循环元素有任何建议,请告诉我?

最佳答案

它不起作用的原因是 Make 扩展 $(subst...) 以生成文本,然后将其传递到 shell,并且您尝试根据 shell 将生成的文本进行替换当它展开“$file”时。处理这个问题的一个简单方法是在 shell 中进行所有扩展:

FILES = hello.py
PHONY: hi
hi:
    -@for file in $(FILES); do \
            echo $$file; \
            echo $${file%py}xml; \
    done

关于makefile - makefile 中的 subst for-loop 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10424340/

相关文章:

生成文件语法

目录下的 Makefile 和 Files

c++ - 从 Eclipse 自动生成的依赖项中排除文件夹?

c++ - 有没有办法减少 GNU make 中重复的先决条件模式?

java - netbeans makefile java 执行

ios - 在 iOS 开发的上下文中,什么是配置/makefile 脚本的好书或引用?

c++ - 如何在 C++ 中定义 vector ?

生成文件: wildcard and different dependencies

makefile - 库链接

variables - Makefile 变量初始化和导出