-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
107 lines (94 loc) · 2.54 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#Compiler Directives
CXX=g++
CPPFLAGS= -std=c++11
#-v \
#-ftime-report
LDFLAGS= -L/usr/local/lib
LIBS= -ldwfobj \
-ldwf \
-lthrift
#Directories
IDIR=backend/include
LDIR=backend/lib
ODIR=backend/obj
IDL_DIR=idl
GEN_CPP_DIR=backend/gen-cpp
GEN_JS_DIR=frontend/gen-js
#Paths
INCLUDE_PATHS= -I$(IDIR) \
-I$(GEN_CPP_DIR)
#Files
# Call thrift with the MAIN_IDL
_MAIN_IDL= Device.thrift
MAIN_IDL=$(patsubst %,$(IDL_DIR)/%,$(_MAIN_IDL))
_IDL= AnalogInput.thrift \
DigitalInput.thrift \
Config.thrift \
$(_MAIN_IDL)
IDL=$(patsubst %,$(IDL_DIR)/%,$(_IDL))
_GEN_SRC_CONST=$(_IDL:.thrift=_constants.cpp)
_GEN_SRC_TYPES=$(_IDL:.thrift=_types.cpp)
_GEN_SRC_MAIN=$(_MAIN_IDL:.thrift=.cpp)
_GEN_SRC=$(_GEN_SRC_CONST) $(_GEN_SRC_TYPES) $(_GEN_SRC_MAIN)
GEN_SRC=$(patsubst %,$(GEN_CPP_DIR)/%,$(_GEN_SRC))
_GEN_OBJ=$(_GEN_SRC:.cpp=.o)
GEN_OBJ=$(patsubst %,$(ODIR)/%,$(_GEN_OBJ))
_GEN_DEPS=$(_GEN_SRC:.cpp=.h)
GEN_DEPS=$(patsubst %,$(GEN_CPP_DIR)/%,$(_GEN_DEPS))
_GEN_JS_TYPES=$(_IDL:.thrift=_types.js)
_GEN_JS_MAIN=$(_MAIN_IDL:.thrift=.js)
_GEN_JS=$(_GEN_JS_TYPES) $(_GEN_JS_MAIN)
GEN_JS=$(patsubst %,$(GEN_JS_DIR)/%,$(_GEN_JS))
BINFILE= run
SRC= main.cpp
_OBJ=$(SRC:.cpp=.o)
OBJ=$(patsubst %,$(ODIR)/%,$(_OBJ)) $(GEN_OBJ)
_DEPS=
DEPS=$(patsubst %,$(IDIR)/%,$(_DEPS)) $(GEN_DEPS)
#Flag Handling
ifdef DEBUG
CPPFLAGS := $(CPPFLAGS) -g
endif
ifdef VERBOSE
Q =
E = @true
else
Q = @
E = @echo
endif
.PHONY: all help clean nuke
all: $(BINFILE)
generate: $(GEN_DEPS) $(GEN_SRC) $(GEN_JS)
help:
$(E)
$(E)Helpful Comments
$(E)
$(GEN_CPP_DIR):
mkdir -p $(GEN_CPP_DIR)
# Do command in either case
$(GEN_DEPS): $(IDL) $(GEN_CPP_DIR)
thrift -r -out $(GEN_CPP_DIR) --gen cpp $(MAIN_IDL)
$(GEN_SRC): $(IDL) $(GEN_CPP_DIR)
thrift -r -out $(GEN_CPP_DIR) --gen cpp $(MAIN_IDL)
$(GEN_JS_DIR):
mkdir -p $(GEN_JS_DIR)
$(GEN_JS): $(IDL) $(GEN_JS_DIR)
thrift -r -out $(GEN_JS_DIR) --gen js $(MAIN_IDL)
$(ODIR)/%.o: $(GEN_CPP_DIR)/%.cpp $(GEN_DEPS)
$(E)C++-compiling generated: $<
$(Q)if [ ! -d `dirname $@` ]; then mkdir -p `dirname $@`; fi
$(Q)$(CXX) -o $@ -c $< $(CPPFLAGS) $(INCLUDE_PATHS)
$(ODIR)/%.o: $(LDIR)/%.cpp $(DEPS)
$(E)C++-compiling $<
$(Q)if [ ! -d `dirname $@` ]; then mkdir -p `dirname $@`; fi
$(Q)$(CXX) -o $@ -c $< $(CPPFLAGS) $(INCLUDE_PATHS)
$(BINFILE): $(OBJ) $(DEPS)
$(E)Linking $@
$(Q)$(CXX) -o $@ $(INCLUDE_PATHS) $^ $(CPPFLAGS) $(LIBS) $(LDFLAGS)
clean:
$(E)Removing Files
$(Q)rm -f $(ODIR)/*.o $(BINFILE)
$(Q)if [ -d $(ODIR) ]; then rmdir $(ODIR); fi
nuke: clean
$(E)Nuking
$(Q)rm -rf $(GEN_CPP_DIR) $(GEN_JS_DIR)