-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
56 lines (40 loc) · 1.48 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
48
49
50
51
52
53
54
55
56
LIBRARY := libGMX.a
PROTO_DIR := codegen/
CXXFLAGS := -I$(PROTO_DIR) -std=c++11 -Wall -Wextra -Wpedantic -g
SRC_DIR := .
OBJ_DIR := .eobjs
rwildcard=$(wildcard $1/$2) $(foreach d,$(wildcard $1/*),$(call rwildcard,$d,$2))
PROTOS := $(call rwildcard,$(SRC_DIR),*.proto)
PROTO_OUT := $(patsubst $(SRC_DIR)/%, $(PROTO_DIR)/%, $(patsubst %.proto, %.pb, $(PROTOS)))
$(PROTO_DIR)/%.pb: $(SRC_DIR)/%.proto | obj_dirs
protoc -I=./ --cpp_out=$(PROTO_DIR) $<
SOURCES := $(call rwildcard,$(SRC_DIR),*.cpp)
OBJECTS := $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(patsubst %.cpp, %.o, $(SOURCES)))
PROTO_SOURCES = $(call rwildcard,$(SRC_DIR),*.pb.cc)
PROTO_OBJECTS = $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(patsubst %.pb.cc, %.o, $(PROTO_SOURCES)))
OBJDIRS = $(sort $(OBJ_DIR) $(dir $(PROTO_OBJECTS)) $(dir $(OBJECTS)))
DEPENDS = $(PROTO_OBJECTS:.o=.d) $(OBJECTS:.o=.d)
lib:
make codegen
make $(LIBRARY)
codegen: $(PROTO_OUT)
# Old make has a bug which requires this nonsense...
obj_dirs: $(OBJDIRS) $(PROTO_DIR)
clean:
rm -rf $(LIBRARY) $(OBJ_DIR)
$(LIBRARY): $(PROTO_OBJECTS) $(OBJECTS)
ar rvs $@ $^
# Create the object directories
$(OBJDIRS):
mkdir -p $@
$(PROTO_DIR):
mkdir -p $@
# Generate rules for new (unbuilt) files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.pb.cc | obj_dirs
$(CXX) $(CXXFLAGS) -MMD -c -o $@ $<
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | obj_dirs
$(CXX) $(CXXFLAGS) -MMD -c -o $@ $<
# Include rules for known (previously-built) files
-include $(DEPENDS)
.SUFFIXES:
.PHONY: lib codegen clean obj_dirs