-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
203 lines (142 loc) · 5.08 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# makefile for cdsl
include version
-include .config
ifeq ($(CLANG),)
CLANG:=clang
endif
VERSION=-D__MAJOR__=$(MAJOR) -D__MINOR__=$(MINOR)
CC=$(CLANG)
CXX=g++
AR=llvm-ar
PYTHON=python2
PIP=pip
MKDIR=mkdir
DBG_CFLAG = -O0 -g3 -fmessage-length=0 $(CFLAG) -D__DBG $(VERSION)
REL_CFLAG = -O2 -g0 -fmessage-length=0 $(CFLAG) $(VERSION)
DYNAMIC_FLAG = -fPIC
LIBDIR=/usr/local/lib
INCDIR=/usr/local/include/cdsl
PROJECT_ROOT_DIR=$(CURDIR)
HEADER_ROOT=$(PROJECT_ROOT_DIR)/include
SOURCE_ROOT=$(PROJECT_ROOT_DIR)/source
TOOL_DIR=$(PROJECT_ROOT_DIR)/tools
CONFIG_PY=$(TOOL_DIR)/jconfigpy
TEST_TARGET=cdsl
DEV_TEST_TARGET=cdsl_dev
DBG_STATIC_TARGET=libcdsld.a
DBG_DYNAMIC_TARGET=libcdsld.so
REL_STATIC_TARGET=libcdsl.a
REL_DYNAMIC_TARGET=libcdsl.so
VPATH=$(SRC-y)
INCS=$(INC-y:%=-I%)
LIBS=$(LIB-y:%=-l%)
DBG_TEST_OBJS=$(TEST_OBJ-y:%=$(DBG_CACHE_DIR)/%.do)
REL_TEST_OBJS=$(TEST_OBJ-y:%=$(REL_CACHE_DIR)/%.o)
DBG_OBJS=$(OBJ-y:%=$(DBG_CACHE_DIR)/%.do)
REL_OBJS=$(OBJ-y:%=$(REL_CACHE_DIR)/%.o)
DBG_SH_OBJS=$(OBJ-y:%=$(DBG_CACHE_DIR)/%.s.do)
REL_SH_OBJS=$(OBJ-y:%=$(REL_CACHE_DIR)/%.s.o)
DBG_CACHE_DIR=Debug
REL_CACHE_DIR=Release
CONFIG_DIR=./configs
SILENT+= $(REL_STATIC_TARGET) $(REL_DYNAMIC_TARGET) $(DBG_OBJS)
SILENT+= $(DBG_STATIC_TARGET) $(DBG_DYNAMIC_TARGET) $(REL_OBJS)
SILENT+= $(DBG_SH_OBJS) $(REL_SH_OBJS)
SILENT+= $(TEST_TARGET) $(REL_CACHE_DIR)/main.o $(DEV_TEST_TARGET) $(DBG_CACHE_DIR)/main.do
.SILENT : $(SILENT) clean reset
PHONY+= all debug release clean test
all : debug
debug : $(DBG_CACHE_DIR) $(DBG_STATIC_TARGET) $(DBG_DYNAMIC_TARGET)
release : $(REL_CACHE_DIR) $(REL_STATIC_TARGET) $(REL_DYNAMIC_TARGET)
test : $(REL_CACHE_DIR) $(DBG_CACHE_DIR) $(TEST_TARGET) $(DEV_TEST_TARGET)
defconf : $(CONFIG_DIR)
cp -rf .config $(CONFIG_DIR)/$(ARCH)_$(SUB_ARCH)_$(CONFIG_TARGET)_config
ifeq ($(DEFCONF),)
config : $(CONFIG_PY) $(TOOL_DIR)
$(PYTHON) $(CONFIG_PY) -c -i config.json
else
config : $(CONFIG_PY)
@echo 'config path $(CONFIG_DIR)'
$(PYTHON) $(CONFIG_PY) -s -i $(CONFIG_DIR)/$(DEFCONF)_config -t ./config.json -o ./.config
endif
$(CONFIG_PY):
$(PIP) install jconfigpy -t $(TOOL_DIR)
$(DBG_CACHE_DIR) $(REL_CACHE_DIR) $(CONFIG_DIR) :
$(MKDIR) $@
$(DBG_STATIC_TARGET) : $(DBG_OBJS)
@echo 'Generating Archive File for $(ARCH) ....$@'
$(AR) rcs $@ $(DBG_OBJS)
ifneq ($(CONFIG_BAREMETAL),y)
$(DBG_DYNAMIC_TARGET) : $(DBG_SH_OBJS)
@echo 'Generating Share Library File for $(ARCH) .... $@'
$(CC) $(TARGET_TRIPPLE) -o $@ -shared $(DBG_CFLAG) $(DYNAMIC_FLAG) $(DBG_SH_OBJS)
else
PHONY+=$(DBG_DYNMAIC_TARGET)
$(DBG_DYNAMIC_TARGET) :
@echo 'Shared Object is skipped for baremetal'
endif
$(REL_STATIC_TARGET) : $(REL_OBJS)
@echo 'Generating Archive File for $(ARCH) ....$@'
$(AR) rcs $@ $(REL_OBJS)
ifneq ($(CONFIG_BAREMETAL),y)
$(REL_DYNAMIC_TARGET) : $(REL_SH_OBJS)
@echo 'Generating Share Library File for $(ARCH) .... $@'
$(CC) $(TARGET_TRIPPLE) -o $@ -shared $(REL_CFLAG) $(DYNAMIC_FLAG) $(REL_SH_OBJS)
else
PHONY+=$(REL_DYNAMIC_TARGET)
$(REL_DYNAMIC_TARGET) :
@echo 'Shared Object is skipped for baremetal'
endif
$(TEST_TARGET) : $(REL_CACHE_DIR)/main.o $(REL_SH_OBJS) $(REL_TEST_OBJS)
@echo 'Building unit-test executable... for $(ARCH) $@'
$(CXX) -o $@ $(REL_CFLAG) $< $(REL_SH_OBJS) $(REL_TEST_OBJS) $(LIBS)
$(DEV_TEST_TARGET) : $(DBG_CACHE_DIR)/main.do $(DBG_SH_OBJS) $(DBG_TEST_OBJS)
@echo 'Building unit-test executable... for $(ARCH) $@'
$(CXX) -o $@ $(DBG_CFLAG) $< $(DBG_SH_OBJS) $(DBG_TEST_OBJS) $(LIBS)
$(DBG_CACHE_DIR)/%.do : %.c
@echo '$(ARCH) compile...$@'
$(CC) -c -o $@ $(DBG_CFLAG) -fPIC $< $(INCS)
$(REL_CACHE_DIR)/%.o : %.c
@echo '$(ARCH) compile...$@'
$(CC) -c -o $@ $(REL_CFLAG) -fPIC $< $(INCS)
$(DBG_CACHE_DIR)/%.s.do : %.c
@echo '$(ARCH) compile...$@'
$(CC) -c -o $@ $(DBG_CFLAG) $< $(INCS) $(DYNAMIC_FLAG)
$(REL_CACHE_DIR)/%.s.o : %.c
@echo '$(ARCH) compile...$@'
$(CC) -c -o $@ $(REL_CFLAG) $< $(INCS) $(DYNAMIC_FLAG)
$(DBG_CACHE_DIR)/%.do : %.cpp
@echo '$(ARCH) compile...$@'
$(CXX) -c -o $@ $(DBG_CFLAG) -fPIC $< $(INCS)
$(REL_CACHE_DIR)/%.o : %.cpp
@echo '$(ARCH) compile...$@'
$(CXX) -c -o $@ $(REL_CFLAG) -fPIC $< $(INCS)
$(DBG_CACHE_DIR)/%.s.do : %.cpp
@echo '$(ARCH) compile...$@'
$(CXX) -c -o $@ $(DBG_CFLAG) $< $(INCS) $(DYNAMIC_FLAG)
$(REL_CACHE_DIR)/%.s.o : %.cpp
@echo '$(ARCH) compile...$@'
$(CXX) -c -o $@ $(REL_CFLAG) $< $(INCS) $(DYNAMIC_FLAG)
install : install_include install_lib
install_include :
install -d $(INCDIR)
install ./include/*.* $(INCDIR)
install ./$(AUTOGEN_DIR)/autogen.h $(INCDIR)
install_lib : $(REL_STATIC_TARGET)
install $(REL_STATIC_TARGET) $(LIBDIR)
uninstall : uninstall_lib uninstall_include
uninstall_lib :
rm $(LIBDIR)/$(REL_STATIC_TARGET)
uninstall_include:
rm -rf $(INCDIR)
check : $(TEST_TARGET)
./$<
PHONY += clean
clean :
rm -rf $(DBG_CACHE_DIR) $(DBG_STATIC_TARGET) $(DBG_DYNAMIC_TARGET)\
$(REL_CACHE_DIR) $(REL_STATIC_TARGET) $(REL_DYNAMIC_TARGET)\
$(TEST_TARGET) $(REL_SH_OBJS) $(DBG_SH_OBJS) $(DEV_TEST_TARGET)
reset : clean
@echo 'reset config ... '
rm -rf $(CONFIG_TARGET) $(CONFIG_AUTOGEN) $(AUTOGEN_DIR) $(TOOL_DIR) $(REPO-y) $(LDIR-y) .config
.PHONY = $(PHONY)