From 37d1e657e5e79bc240ea036cfb8da377b1640490 Mon Sep 17 00:00:00 2001
From: Toni Uhlig <matzeton@googlemail.com>
Date: Sun, 16 Jul 2023 13:48:42 +0200
Subject: Makefile cosmetics and example protobuffer recreated with a newer
 protoc-c executable.

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
---
 Makefile | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

(limited to 'Makefile')

diff --git a/Makefile b/Makefile
index 998f7aa..e02b4f5 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,9 @@ endif
 
 include $(DPP_ROOT)/Makefile.inc
 
+PROTOBUF_OBJECT = protobuf-build/protobuf-c.o
+PROTOBUF_CFLAGS_PRIVATE = -Wno-unused-but-set-variable
+
 FLATBUFFERS_LIB = flatbuffers-build/lib/libflatccrt.a
 FLATBUFFERS_CFLAGS = -Iflatbuffers-build/include -Wno-misleading-indentation
 FLATBUFFERS_FLATC = flatbuffers-flatcc-build/bin/flatcc
@@ -13,11 +16,11 @@ DRIVER0_OBJECTS = examples/$(DRIVER0_NAME).o ksocket/ksocket.o ksocket/berkeley.
 DRIVER0_TARGET = $(DRIVER0_NAME).sys
 
 DRIVER1_NAME = driver-protobuf-c
-DRIVER1_OBJECTS = examples/$(DRIVER1_NAME).o protobuf-c/protobuf-c.o examples/example.pb-c.o
+DRIVER1_OBJECTS = examples/$(DRIVER1_NAME).o examples/example.pb-c.o $(PROTOBUF_OBJECT)
 DRIVER1_TARGET = $(DRIVER1_NAME).sys
 
 DRIVER2_NAME = driver-protobuf-c-tcp
-DRIVER2_OBJECTS = examples/$(DRIVER2_NAME).o ksocket/ksocket.o ksocket/berkeley.o protobuf-c/protobuf-c.o examples/example.pb-c.o
+DRIVER2_OBJECTS = examples/$(DRIVER2_NAME).o ksocket/ksocket.o ksocket/berkeley.o examples/example.pb-c.o $(PROTOBUF_OBJECT)
 DRIVER2_TARGET = $(DRIVER2_NAME).sys
 
 DRIVER3_NAME = driver-flatbuffers
@@ -29,12 +32,12 @@ USERSPACE0_OBJECTS = examples/$(USERSPACE0_NAME).o
 USERSPACE0_TARGET = $(USERSPACE0_NAME).exe
 
 USERSPACE1_NAME = userspace_client_protobuf
-USERSPACE1_OBJECTS = examples/$(USERSPACE1_NAME).o protobuf-c/protobuf-c.o examples/example.pb-c.o
+USERSPACE1_OBJECTS = examples/$(USERSPACE1_NAME).o examples/example.pb-c.o $(PROTOBUF_OBJECT)
 USERSPACE1_TARGET = $(USERSPACE1_NAME).exe
 
 # mingw-w64-dpp related
-CFLAGS_protobuf-c/protobuf-c.o = -Wno-unused-but-set-variable
-CUSTOM_CFLAGS = -I. -Iexamples $(FLATBUFFERS_CFLAGS) -Wl,--exclude-all-symbols -DNDEBUG
+CFLAGS_$(PROTOBUF_OBJECT) = $(PROTOBUF_CFLAGS_PRIVATE)
+CUSTOM_CFLAGS = -I. -Iexamples -Werror $(FLATBUFFERS_CFLAGS) -Wl,--exclude-all-symbols -DNDEBUG
 DRIVER_LIBS += -lnetio
 USER_LIBS += -lws2_32
 
@@ -46,6 +49,10 @@ all: deps $(DRIVER0_TARGET) $(DRIVER1_TARGET) $(DRIVER2_TARGET) $(DRIVER3_TARGET
 %.o: %.c
 	$(call BUILD_C_OBJECT,$<,$@)
 
+$(PROTOBUF_OBJECT): protobuf-c/protobuf-c.c
+	mkdir -p '$(dir $(PROTOBUF_OBJECT))'
+	$(call BUILD_C_OBJECT,$<,$@)
+
 $(DRIVER0_TARGET): $(DRIVER0_OBJECTS)
 	$(call LINK_CPP_KERNEL_TARGET,$(DRIVER0_OBJECTS),$@)
 
@@ -71,7 +78,7 @@ $(FLATBUFFERS_LIB):
 		-DCMAKE_INSTALL_PREFIX=/ \
 		-DCMAKE_C_COMPILER="$(realpath $(CC))" \
 		-DCMAKE_SYSTEM_NAME="Windows" \
-		-DCMAKE_C_FLAGS='$(CFLAGS)' \
+		-DCMAKE_C_FLAGS='$(CFLAGS) $(FLATBUFFERS_CFLAGS_PRIVATE)' \
 		-DCMAKE_BUILD_TYPE=Release \
 		-DFLATCC_ALLOW_WERROR=ON -DFLATCC_COVERAGE=OFF -DFLATCC_CXX_TEST=OFF \
 		-DFLATCC_REFLECTION=OFF -DFLATCC_RTONLY=ON -DFLATCC_TEST=OFF -DFLATCC_INSTALL=ON \
@@ -88,7 +95,9 @@ $(FLATBUFFERS_FLATC):
 	cmake --build flatbuffers-flatcc-build
 	make -C flatbuffers-flatcc-build install DESTDIR="$(realpath .)/flatbuffers-flatcc-build"
 
-generate:
+generate: $(FLATBUFFERS_FLATC)
+	@echo 'Generating flatbuffer files..'
+	$(FLATBUFFERS_FLATC) -a -o examples examples/monster.fbs
 	@echo '=========================================='
 	@echo '= You need protobuf-c to make this work! ='
 	@echo '=========================================='
-- 
cgit v1.2.3