Suppose you have the following project structure:
.
├── Makefile
└── src
└── 1.py
The program 1.py
creates multiple (0, 1, or more) files in the directory build/1
. This generalizes to arbitrary numbers, i.e. a program x.py
where x
is some natural number would create multiple files in the directory build/x
. The project can consist of many python(3) files.
A makefile for the specific scenario above could look like this:
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
Running make
with the above project structure and makefile results in the following project structure:
.
├── Makefile
├── build
│ └── 1
│ └── test.txt
└── src
└── 1.py
How do I generalize the rule head build/1/test.txt: src/1.py
to handle projects with any number of python programs (or, equivalently, build subdirectories) and any number of output files per python program?