On Mon, Nov 17, 2008 at 17:02, codeazure <[EMAIL PROTECTED]> wrote:
> Has anyone devised a makefile rule for the .protoc->.cc->.o sequence?
...
> This appears to work well, but I was hoping it is possible to define
> a .proto.cc rule to automate it by some cleverness. My project uses
> Automake & it is easy to define custom make rules for different
> extensions.

I've been using the following, which works well in GNU make[1].  I'm
using a non-recursive makefile[2], and have a separate directory tree
under $GENDIR for all generated files (.o, .pb.cc, etc).  I sort of
use that to good effect in making sure the regular rule for cc files
won't apply accidentally, because the pb.cc files are in a different
location.

==============================
# Make a directory unless it already exists
maybe-mkdir = $(if $(wildcard $1),,mkdir -p $1)

# C++ build rule.
$(GENDIR)/%.o: %.cc
        $(call maybe-mkdir, $(dir $@))
        $(CC) $(CFLAGS) -c $< -o $@

# Protobuffer code generation rules (note the first rule has multiple targets).
$(GENDIR)/%.pb.h $(GENDIR)/%.pb.cc: %.proto
        $(call maybe-mkdir, $(dir $@))
        $(PROTOC) -I. --cpp_out=$(GENDIR) $<

$(GENDIR)/%.pb.o: $(GENDIR)/%.pb.cc
        $(CC) $(PROTO_CFLAGS) -c $< -o $@
==============================

[1] Rule #1, http://make.paulandlesley.org/rules.html
[2] Recursive make considered harmful,
http://miller.emu.id.au/pmiller/books/rmch/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to