Trying to write a Makefile that compiles python gRPC protos but only when the source proto file changed. I ran through it multiple times and can't figure out why I'm getting that error (when running make build
). Supposedly it's because a file is matching multiple targets, but I don't see how:
# All proto source files
PROTOS_SRC = $(wildcard api/*.proto)
# The three types of generated files per proto source
PROTOS_PY = $(patsubst api/%.proto, api/%_pb2.py, $(PROTO_SRC))
PROTOS_GRPC_PY = $(patsubst api/%.proto, api/%_pb2_grpc.py, $(PROTO_SRC))
PROTOS_PYI = $(patsubst api/%.proto, api/%_pb2.pyi, $(PROTO_SRC))
# All the generated files we have to depend on
PROTOS_OUT = $(PROTOS_PY) $(PROTOS_GRPC_PY) $(PROTOS_PYI)
# How to obtain generated sources from a proto file
api/%_pb2.py api/%_pb2_grpc.py api/%_pb2.pyi: api/%.proto:
python -m grpc_tools.protoc -I./api --python_out=./api --grpc_python_out=./api --mypy_out=./api $<
build: $(PROTOS_OUT)
clean:
rm -rf api/*_pb2.py api/*_pb2_grpc.py
.PHONY: clean
The proto source code is in the api/
subdirectory and that's where I'm outputting the generated code too.
I wrote the conversion rule based on this, so i think it's correct: GNU Makefile rule generating a few targets from a single source file