[PATCH 10/11] make: protobuf -- Switch to new build scheme

Cyrill Gorcunov gorcunov at openvz.org
Sun Jan 27 09:20:43 EST 2013


Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 Makefile          |   9 ++--
 protobuf/Makefile | 159 ++++++++++++++++++++++++++----------------------------
 2 files changed, 81 insertions(+), 87 deletions(-)

diff --git a/Makefile b/Makefile
index 9a0f24b..26f4225 100644
--- a/Makefile
+++ b/Makefile
@@ -82,7 +82,6 @@ endif
 
 CFLAGS		+= $(WARNINGS) $(DEFINES)
 SYSCALL-LIB	= $(SRC_DIR)/arch/$(ARCH)/syscalls.o
-PROTOBUF-LIB	= $(SRC_DIR)/protobuf/protobuf-lib.o
 
 export E Q CC ECHO MAKE CFLAGS LIBS ARCH DEFINES MAKEFLAGS
 export SRC_DIR SYSCALL-LIB SH RM ARCH_DIR OBJCOPY LDARCH LD
@@ -158,8 +157,10 @@ pie/%:: protobuf $(ARCH)
 pie: protobuf $(ARCH)
 	$(Q) $(MAKE) $(build)=pie all
 
+protobuf/%::
+	$(Q) $(MAKE) $(build)=protobuf $@
 protobuf:
-	$(Q) $(MAKE) -C protobuf/
+	$(Q) $(MAKE) $(build)=protobuf all
 
 $(ARCH):
 	$(Q) $(MAKE) -C arch/$(ARCH)/
@@ -169,7 +170,7 @@ $(eval $(call gen-i-rule-c,))
 $(eval $(call gen-s-rule-c,))
 $(eval $(call gen-d-rule-c,))
 
-$(PROGRAM): $(OBJS) $(SYSCALL-LIB) $(PROTOBUF-LIB)
+$(PROGRAM): $(SYSCALL-LIB) protobuf/built-in.o $(OBJS)
 	$(E) "  LINK    " $@
 	$(Q) $(CC) $(CFLAGS) $^ $(LIBS) -o $@
 
@@ -190,6 +191,7 @@ rebuild:
 clean:
 	$(E) "  CLEAN"
 	$(Q) $(MAKE) $(build)=pie clean
+	$(Q) $(MAKE) $(build)=protobuf clean
 	$(Q) $(RM) -f ./*.o
 	$(Q) $(RM) -f ./*.d
 	$(Q) $(RM) -f ./*.i
@@ -202,7 +204,6 @@ clean:
 	$(Q) $(RM) -rf ./gcov
 	$(Q) $(RM) -rf ./test/lib/
 	$(Q) $(RM) -rf ./test/lib64/
-	$(Q) $(MAKE) -C protobuf/ clean
 	$(Q) $(MAKE) -C arch/$(ARCH)/ clean
 	$(Q) $(MAKE) -C test/zdtm cleandep
 	$(Q) $(MAKE) -C test/zdtm clean
diff --git a/protobuf/Makefile b/protobuf/Makefile
index aae786f..37f1f95 100644
--- a/protobuf/Makefile
+++ b/protobuf/Makefile
@@ -1,99 +1,92 @@
-PROTO_LIBRARY	:= protobuf-lib.o
+CFLAGS		+= -I$(obj)/
 
-PROTO_FILES	+= core-x86.proto
-PROTO_FILES	+= core-arm.proto
-PROTO_FILES	+= core.proto
-PROTO_FILES	+= inventory.proto
-PROTO_FILES	+= fdinfo.proto
-PROTO_FILES	+= fown.proto
-PROTO_FILES	+= regfile.proto
-PROTO_FILES	+= ghost-file.proto
-PROTO_FILES	+= fifo.proto
-PROTO_FILES	+= remap-file-path.proto
-PROTO_FILES	+= eventfd.proto
-PROTO_FILES	+= eventpoll.proto
-PROTO_FILES	+= fh.proto
-PROTO_FILES	+= fsnotify.proto
-PROTO_FILES	+= signalfd.proto
-PROTO_FILES	+= fs.proto
-PROTO_FILES	+= pstree.proto
-PROTO_FILES	+= pipe.proto
-PROTO_FILES	+= tcp-stream.proto
-PROTO_FILES	+= sk-packet.proto
-PROTO_FILES	+= mnt.proto
-PROTO_FILES	+= pipe-data.proto
-PROTO_FILES	+= sa.proto
-PROTO_FILES	+= itimer.proto
-PROTO_FILES	+= mm.proto
-PROTO_FILES	+= sk-opts.proto
-PROTO_FILES	+= sk-unix.proto
-PROTO_FILES	+= sk-inet.proto
-PROTO_FILES	+= packet-sock.proto
-PROTO_FILES	+= ipc-var.proto
-PROTO_FILES	+= ipc-desc.proto
-PROTO_FILES	+= ipc-shm.proto
-PROTO_FILES	+= ipc-msg.proto
-PROTO_FILES	+= ipc-sem.proto
-PROTO_FILES	+= utsns.proto
-PROTO_FILES	+= creds.proto
-PROTO_FILES	+= vma.proto
-PROTO_FILES	+= netdev.proto
-PROTO_FILES	+= tty.proto
-PROTO_FILES	+= file-lock.proto
-PROTO_FILES	+= rlimit.proto
+obj-y		+= core.o
+obj-y		+= core-x86.o
+obj-y		+= core-arm.o
+obj-y		+= inventory.o
+obj-y		+= fdinfo.o
+obj-y		+= fown.o
+obj-y		+= regfile.o
+obj-y		+= ghost-file.o
+obj-y		+= fifo.o
+obj-y		+= remap-file-path.o
+obj-y		+= eventfd.o
+obj-y		+= eventpoll.o
+obj-y		+= fh.o
+obj-y		+= fsnotify.o
+obj-y		+= signalfd.o
+obj-y		+= fs.o
+obj-y		+= pstree.o
+obj-y		+= pipe.o
+obj-y		+= tcp-stream.o
+obj-y		+= sk-packet.o
+obj-y		+= mnt.o
+obj-y		+= pipe-data.o
+obj-y		+= sa.o
+obj-y		+= itimer.o
+obj-y		+= mm.o
+obj-y		+= sk-opts.o
+obj-y		+= sk-unix.o
+obj-y		+= sk-inet.o
+obj-y		+= packet-sock.o
+obj-y		+= ipc-var.o
+obj-y		+= ipc-desc.o
+obj-y		+= ipc-shm.o
+obj-y		+= ipc-msg.o
+obj-y		+= ipc-sem.o
+obj-y		+= utsns.o
+obj-y		+= creds.o
+obj-y		+= vma.o
+obj-y		+= netdev.o
+obj-y		+= tty.o
+obj-y		+= file-lock.o
+obj-y		+= rlimit.o
 
-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))
+proto		:= $(obj-y:.o=)
+proto-c		:= $(obj-y:.o=.pb-c.c)
+proto-h		:= $(obj-y:.o=.pb-c.h)
 
-.DEFAULT_GOAL	:= protobuf
+.SECONDARY:
+
+$(eval $(call gen-o-rule-c-rext,$(obj)/,.pb-c.c))
+$(eval $(call gen-d-rule-c-rext,$(obj)/,.pb-c.c))
+$(eval $(call gen-i-rule-c-rext,$(obj)/,.pb-c.c))
 
-%.proto.d: %.proto
-	$(E) "  PROTOBUF DEPS "$@
-	$(Q) grep "import" $^ | sed	  			  \
-		-e 's/^import//' 				  \
-		-e 's/[\";]//g'					  \
-		-e 's/.*/$^:&/'					| \
+$(obj)/%.proto.d: $(obj)/%.proto
+	$(E) "  PB DDEP " $@
+	$(Q) grep "^[[:blank:]]*import[[:blank:]]" $^ | sed	  		  \
+		-e 's/[[:blank:]]*import[[:blank:]]*//' 			  \
+		-e 's/[\";]//g'							  \
+		-e 's/.*/$(subst /,\/,$^):$(obj)\/&/'				| \
 		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,$^):&/'		| \
+$(obj)/%.proto.c.d: $(obj)/%.proto | $(obj)/%.proto.d
+	$(E) "  PB DEP  " $@
+	$(Q) grep "^[[:blank:]]*import[[:blank:]]" $< | sed	  		  \
+		-e 's/[[:blank:]]*import[[:blank:]]*//' 			  \
+		-e 's/.proto/.pb-c.c/'	  					  \
+		-e 's/[\";]//g'		  					  \
+		-e 's/.*/$(subst .proto,.pb-c.c,$(subst /,\/,$<)):$(obj)\/&/'	| \
 		uniq > $@
 
-%.pb-c.c %.pb-c.h: %.proto %.proto.d
-	$(E) "  PROTOBUF "$@
-	$(Q) protoc-c --c_out=./ $<
+$(obj)/%.pb-c.c $(obj)/%.pb-c.h: $(obj)/%.proto $(obj)/%.proto.c.d
+	$(E) "  PBCC    " $@
+	$(Q) protoc-c --proto_path=$(obj)/ --c_out=$(obj)/ $<
 ifeq ($(ARCH),arm)
 	$(Q) sed -i 's/4294967295/0xFFFFFFFF/g' $@ $(patsubst %c,%h,$@)
 endif
 
-%.o: %.c %.h
-	$(E) "  CC       "$@
-	$(Q) $(CC) -c $(CFLAGS) $< -o $@
-
-.SECONDARY:
-
-$(PROTO_LIBRARY): $(PROTO_OBJS)
-	$(E) "  LINK     "$@
-	$(Q) $(LD) -r -o $@ $(PROTO_OBJS)
+ifneq ($(MAKECMDGOALS),clean)
+-include $(addprefix $(obj)/,$(obj-y:.o=.proto.d))
+-include $(addprefix $(obj)/,$(obj-y:.o=.proto.c.d))
+endif
 
-.PHONY: protobuf
+cleanup-y += $(obj)/*.o $(obj)/*.d $(obj)/*.c.d $(obj)/*.i
+cleanup-y += $(obj)/*.pb-c.c $(obj)/*.pb-c.h
+cleanup-y += $(obj)/*.built-in.o
 
-protobuf: $(PROTO_LIBRARY) $(PROTO_SRCS) $(PROTO_HDRS)
+all: $(obj)/built-in.o
 
 clean:
-	$(E) "  CLEAN PROTOBUF"
-	$(Q) rm -f $(PROTO_SRCS) $(PROTO_HDRS) $(PROTO_OBJS) $(PROTO_LIBRARY)
-	$(Q) rm -f $(PROTO_DEPS) $(PROTO_CDEP)
-
-ifneq ($(MAKECMDGOALS),clean)
--include $(PROTO_DEPS)
--include $(PROTO_CDEP)
-endif
+	$(E) "  CLEANUP " $(obj)
+	$(Q) $(RM) $(cleanup-y)
-- 
1.8.1


--x+6KMIRAuhnl3hBn--


More information about the CRIU mailing list