-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
47 lines (35 loc) · 1.32 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
CXX = g++ -g
CPPFLAGS += `pkg-config --cflags protobuf grpc`
CXXFLAGS += -std=c++11
LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++`\
-pthread\
-Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed\
-ldl \
-lcppunit
PROTOC = protoc
GRPC_CPP_PLUGIN = grpc_cpp_plugin
GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
PROTOS_PATH = protos
TEST_EXEC := test_runner
all: $(TEST_EXEC)
SOURCE = $(wildcard *.cc)
PROTOS = $(wildcard $(PROTOS_PATH)/*proto)
OBJECTS = $(SOURCE:.cc=.o) $(PROTOS:.proto=.pb.o) $(PROTOS:.proto=.grpc.pb.o)
# Seems necessary to override the built-in target for .o
.SUFFIXES:
.PRECIOUS: $(PROTOS_PATH)/%.grpc.pb.cc
$(PROTOS_PATH)/%.grpc.pb.cc: $(PROTOS)
$(PROTOC) -I $(PROTOS_PATH) --grpc_out=$(PROTOS_PATH) --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $*.proto
.PRECIOUS: $(PROTOS_PATH)/%.pb.cc
$(PROTOS_PATH)/%.pb.cc: $(PROTOS)
$(PROTOC) -I $(PROTOS_PATH) --cpp_out=$(PROTOS_PATH) $*.proto
$(PROTOS_PATH)/%.pb.o: $($@:.o=.cc)
$(PROTOS_PATH)/%.grpc.pb.o: $($@:.o=.cc)
%.o : %.cc $(PROTOS:.proto=.grpc.pb.cc) $(PROTOS:.proto=.pb.cc)
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
$(TEST_EXEC): $(OBJECTS)
$(CXX) $^ -o $@ $(LDFLAGS)
test: $(TEST_EXEC)
./$(TEST_EXEC)
clean:
rm -f *.o $(PROTOS_PATH)/*.pb.cc $(PROTOS_PATH)/*.pb.h $(PROTOS_PATH)/*.o $(TEST_EXEC)