akaJames akaJames - 11 months ago 85
Linux Question

Rename generated files in Makefile

I have to modify a Makefile such that the intermediate files with extension

are moved to
before building the
files. My modified Makefile looks like below.

all: client_grpc pb

client_grpc: abc.pb.o abc.grpc.pb.o client_grpc.o
$(CXX) $^ $(LDFLAGS) -o $@

pb: %.pb.cc
mv $^ $@

%.grpc.pb.cc: %.proto
$(PROTOC) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<

%.pb.cc: %.proto
$(PROTOC) --cpp_out=. $<

rm -f *.o *.pb.cc *.pb.h client_gqegrpc

is a compiler that generates
files. How to make targets so that after generating the
files those are move to
and then the
is built using the
files ?

Answer Source

The usual way to do this would be to have your rule produce .cpp files:

%.pb.cpp: %.proto
        $(PROTOC) --cpp_out=. $<
        mv $*.pb.cc $*.pb.cpp