Commit 008457e1 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

make: protobuf -- Order .c files generation

This patch introduce dependencies on .c files
generation parsing import keywords in .proto
files.

In particular, the core.proto file refers to
core-x86.proto which means we need to generate
.[c|h] files from core-x86.proto earlier than
handlig of core.proto.

A positive side effect of this patch is that
the compilation is independent now of order the
proto files are declated in the make file.

Instead of currently present manual order

PROTO_FILES	+= core-x86.proto
PROTO_FILES	+= core-arm.proto
PROTO_FILES	+= core.proto

one can write it in any arrangement, say

PROTO_FILES     += core.proto
PROTO_FILES     += core-arm.proto
PROTO_FILES     += core-x86.proto

and it still be resolved correctly.

BUT beware of circular import directives,
we can't handle them now.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent d701221e
......@@ -43,6 +43,7 @@ PROTO_FILES += file-lock.proto
PROTO_FILES += rlimit.proto
PROTO_DEPS := $(patsubst %.proto,%.proto.d,$(PROTO_FILES))
PROTO_CDEP := $(patsubst %.proto,%.d,$(PROTO_FILES))
PROTO_HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES))
PROTO_SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES))
PROTO_OBJS := $(patsubst %.c,%.o,$(PROTO_SRCS))
......@@ -57,6 +58,15 @@ PROTO_OBJS := $(patsubst %.c,%.o,$(PROTO_SRCS))
sed -e 's/.*/$^:&/' | \
uniq > $@
%.d: %.proto
$(E) " PROTOBUF ORDS "$@
$(Q) grep "import" $^ | sed \
-e 's/^import//' \
-e 's/.proto/.pb-c.c/' \
-e 's/[\";]//g' \
-e 's/.*/$(subst .proto,.pb-c.c,$^):&/' | \
uniq > $@
%.pb-c.c %.pb-c.h: %.proto %.proto.d
$(E) " PROTOBUF "$@
$(Q) protoc-c --c_out=./ $<
......@@ -81,8 +91,9 @@ protobuf: $(PROTO_LIBRARY) $(PROTO_SRCS) $(PROTO_HDRS)
clean:
$(E) " CLEAN PROTOBUF"
$(Q) rm -f $(PROTO_SRCS) $(PROTO_HDRS) $(PROTO_OBJS) $(PROTO_LIBRARY)
$(Q) rm -f $(PROTO_DEPS)
$(Q) rm -f $(PROTO_DEPS) $(PROTO_CDEP)
ifneq ($(MAKECMDGOALS),clean)
-include $(PROTO_DEPS)
-include $(PROTO_CDEP)
endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment