I use the following Makefile section:
.PHONY: all
all: _MyModule.so
_%.so: %.pb.cc %.pb.h
python setup.py build
%.pb.cc %.pb.h: %.proto
protoc --cpp_out=. $^ # Generate these two files together
I would expect make to create the _MyModule.so file and remove the intermediates MyModule.pb.cc and MyModule.pb.h. What happens in practice is that only one of the files is deleted(.h or .cpp). I also noticed that it depends on the order of their appearance in the _%.so dependencies list.
Could anyone explain this behavior?
How could I elegantly remove all the intermediates?
How peculiar. I’ll go out on a limb and say this looks like a bug in GNUMake. A pattern rule with multiple targets has special behavior, and it seems that this behavior doesn’t dovetail correctly with the treatment of intermediate files (and
.INTERMEDIATEdoesn’t help).I wouldn’t call this an elegant solution, but it works:
P.S. Turns out this is a known bug.