【发布时间】:2019-11-23 19:49:58
【问题描述】:
假设您有以下项目结构:
.
├── Makefile
└── src
└── 1.py
程序1.py 在目录build/1 中创建多个(0、1 或更多)文件。这推广到任意数字,即程序x.py,其中x 是某个自然数,将在目录build/x 中创建多个文件。该项目可以包含许多 python(3) 文件。
上述特定场景的生成文件可能如下所示:
PYTHON_FILES := $(shell find src -name '*.py')
TXT_FILES := build/1/test.txt
.PHONY: clean all
all: $(TXT_FILES)
build/1/test.txt: src/1.py
mkdir -p build/1
touch build/1/test.txt # emulates: python3 src/1.py
echo "success!"
clean:
rm -rf build
使用上述项目结构和 makefile 运行 make 会产生以下项目结构:
.
├── Makefile
├── build
│ └── 1
│ └── test.txt
└── src
└── 1.py
我如何概括规则头 build/1/test.txt: src/1.py 以处理具有任意数量的 python 程序(或等效地,构建子目录)和每个 python 程序任意数量的输出文件的项目?
【问题讨论】:
标签: makefile