-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
256 lines (219 loc) · 7.56 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
include config.mk
ifdef VERBOSE
AT =
else
AT = @
endif
export BIN = $(TARGET)
export LIBTARGET_A = lib$(TARGET).a
export LIBTARGET_SO = lib$(TARGET).so
LIBTARGET_SO_MM = $(LIBTARGET_SO).$(MAJOR).$(MINOR)
LIBTARGET_SO_MMM = $(LIBTARGET_SO).$(MAJOR).$(MINOR).$(MICRO)
BIN_MMM = $(BIN).$(MAJOR).$(MINOR).$(MICRO)
BUILD_SRC_DIR = $(BUILD_DIR)/$(SRC_DIR)
OBJ_A = $(BUILD_SRC_DIR)/$(LIBTARGET_A)
OBJ_SO = $(BUILD_SRC_DIR)/$(LIBTARGET_SO)
OBJ_BIN = $(BUILD_SRC_DIR)/$(BIN)
BUILD_INCLUDE_DIR = $(BUILD_DIR)/include/$(TARGET)
BUILD_LIB_DIR = $(BUILD_DIR)/lib
BUILD_BIN_DIR = $(BUILD_DIR)/bin
BUILD_DOC_DIR = $(BUILD_DIR)/doc
BUILD_A = $(BUILD_LIB_DIR)/$(LIBTARGET_A)
BUILD_SO = $(BUILD_LIB_DIR)/$(LIBTARGET_SO)
BUILD_SO_MM = $(BUILD_LIB_DIR)/$(LIBTARGET_SO_MM)
BUILD_SO_MMM = $(BUILD_LIB_DIR)/$(LIBTARGET_SO_MMM)
BUILD_BIN = $(BUILD_BIN_DIR)/$(BIN)
BUILD_BIN_MMM = $(BUILD_BIN_DIR)/$(BIN_MMM)
BUILD_DOC = $(BUILD_DOC_DIR)/$(TARGET)
INSTALL_INCLUDE_DIR = $(INSTALL_DIR)/include/$(TARGET)
INSTALL_LIB_DIR = $(INSTALL_DIR)/lib
INSTALL_BIN_DIR = $(INSTALL_DIR)/bin
INSTALL_DOC_DIR = $(INSTALL_DIR)/doc
INSTALL_A = $(INSTALL_LIB_DIR)/$(LIBTARGET_A)
INSTALL_SO = $(INSTALL_LIB_DIR)/$(LIBTARGET_SO)
INSTALL_SO_MM = $(INSTALL_LIB_DIR)/$(LIBTARGET_SO_MM)
INSTALL_SO_MMM = $(INSTALL_LIB_DIR)/$(LIBTARGET_SO_MMM)
INSTALL_BIN = $(INSTALL_BIN_DIR)/$(BIN)
INSTALL_BIN_MMM = $(INSTALL_BIN_DIR)/$(BIN_MMM)
INSTALL_DOC = $(INSTALL_DOC_DIR)/$(TARGET)
CONFIG_SRC = $(SRC_DIR)/$(TARGET).h.in
CONFIG_DST = $(BUILD_INCLUDE_DIR)/$(TARGET).h
CONFIG_DEFINES =
CONFIG_DEFINES += "$(ABBR)_MAJOR_VERSION ($(MAJOR))"
CONFIG_DEFINES += "$(ABBR)_MINOR_VERSION ($(MINOR))"
CONFIG_DEFINES += "$(ABBR)_MICRO_VERSION ($(MICRO))"
ifeq ($(WITH_CUDA), yes)
CONFIG_DEFINES += "$(ABBR)_CUDA"
endif
ifeq ($(WITH_CUDNN), yes)
CONFIG_DEFINES += "$(ABBR)_CUDNN"
endif
ifeq ($(WITH_TENSORRT), yes)
CONFIG_DEFINES += "$(ABBR)_TENSORRT"
endif
ifeq ($(WITH_DPU), yes)
CONFIG_DEFINES += "$(ABBR)_DPU"
endif
ifeq ($(WITH_PYTHON), yes)
PYTHON_TARGET = py$(TARGET)
PYTHON_DIR = tools/py$(TARGET)
ifeq ($(PYTHON_USER), yes)
INSTALL_PYTHON = (cd $(PYTHON_DIR) && $(PYTHON_CMD) setup.py install --user --record .install-log)
else
INSTALL_PYTHON = (cd $(PYTHON_DIR) && $(PYTHON_CMD) setup.py install --prefix $(PYTHON_PREFIX) --record .install-log)
endif
UNINSTALL_PYTHON = perl $(BUILDTOOLS_DIR)/uninstallpy.pl $(PYTHON_DIR)/.install-log $(PYTHON_TARGET)
else
INSTALL_PYTHON =
UNINSTALL_PYTHON =
endif
ifneq ($(WITH_PLUGIN), yes)
make-plugin = @echo "$(TARGET) not configured with plugin support"
make-plugin-test = @echo "$(TARGET) not configured with plugin support"
make-plugin-cmd = @echo "$(TARGET) not configured with plugin support"
else
CONFIG_DEFINES += "$(ABBR)_PLUGIN"
ifeq ("$(origin P)", "command line")
make-plugin = $(AT)+$(MAKE) P=$(P) -C $(SRC_DIR) ext-plugin
make-plugin-test = $(AT)+$(MAKE) P=$(P) -C $(TEST_DIR) ext-plugin-test
define make-plugin-cmd
$(AT)+$(MAKE) P=$(P) -C $(SRC_DIR) ext-plugin-cmd
$(AT)+$(MAKE) P=$(P) -C $(TEST_DIR) ext-plugin-cmd
endef
else
make-plugin = @echo "must set P=dir to specify the directory of external plugin to build"
make-plugin-test = @echo "must set P=dir to specify the directory of external plugin to build"
make-plugin-cmd = @echo "must set P=dir to specify the directory of external plugin to build"
endif
endif # WITH_PLUGIN
ifeq ($(DOC), yes)
MAKE_DOC_CMD = mkdocs build -c -d $(BUILD_DOC)
INSTALL_DOC_CMD = if [ -d $(BUILD_DOC) ]; then cp -r $(BUILD_DOC) $(INSTALL_DOC); fi
UNINSTALL_DOC_CMD = rm -rf $(INSTALL_DOC)
else
MAKE_DOC_CMD =
INSTALL_DOC_CMD =
UNINSTALL_DOC_CMD =
endif
ifeq ($(HAS_EXTRA_BINS), yes)
MAKE_EXTRA_BINS_CMD = cp -L $(EXTRA_BINS) $(BUILD_BIN_DIR)
INSTALL_EXTRA_BINS_CMD = cp $(BUILD_EXTRA_BINS) $(INSTALL_BIN_DIR)
UNINSTALL_EXTRA_BINS_CMD = rm -f $(INSTALL_EXTRA_BINS)
else
MAKE_EXTRA_BINS_CMD =
INSTALL_EXTRA_BINS_CMD =
UNINSTALL_EXTRA_BINS_CMD =
endif
define make-build-dir
$(AT)if [ ! -d $(BUILD_DIR) ]; then mkdir -p $(BUILD_DIR); fi
$(AT)if [ ! -d $(BUILD_INCLUDE_DIR) ]; then mkdir -p $(BUILD_INCLUDE_DIR); fi
$(AT)if [ ! -d $(BUILD_LIB_DIR) ]; then mkdir -p $(BUILD_LIB_DIR); fi
$(AT)if [ ! -d $(BUILD_BIN_DIR) ]; then mkdir -p $(BUILD_BIN_DIR); fi
$(AT)if [ ! -d $(BUILD_DOC_DIR) ]; then mkdir -p $(BUILD_DOC_DIR); fi
$(AT)find $(SRC_DIR) -type d -print0 | xargs -0 -I{} mkdir -p $(BUILD_DIR)/{}
$(AT)find $(TEST_DIR) -type d -print0 | xargs -0 -I{} mkdir -p $(BUILD_DIR)/{}
endef
define make-install-dir
$(AT)if [ ! -d $(INSTALL_DIR) ]; then mkdir -p $(INSTALL_DIR); fi
$(AT)if [ ! -d $(INSTALL_INCLUDE_DIR) ]; then mkdir -p $(INSTALL_INCLUDE_DIR); fi
$(AT)if [ ! -d $(INSTALL_LIB_DIR) ]; then mkdir -p $(INSTALL_LIB_DIR); fi
$(AT)if [ ! -d $(INSTALL_BIN_DIR) ]; then mkdir -p $(INSTALL_BIN_DIR); fi
$(AT)if [ ! -d $(INSTALL_DOC_DIR) ]; then mkdir -p $(INSTALL_DOC_DIR); fi
$(AT)if [ ! -d $(PKGCONFIG_DIR) ]; then mkdir -p $(PKGCONFIG_DIR); fi
endef
define pre-make-config
$(AT)perl $(BUILDTOOLS_DIR)/add_config.pl $(CONFIG_SRC) $(CONFIG_DST) -d $(CONFIG_DEFINES) -i
endef
define make-lib
$(AT)cp $(EXPORT_HEADERS) $(BUILD_INCLUDE_DIR)
$(AT)cp $(OBJ_A) $(BUILD_A)
$(AT)cp $(OBJ_SO) $(BUILD_SO_MMM)
$(AT)ln -sf $(LIBTARGET_SO_MMM) $(BUILD_SO_MM)
$(AT)ln -sf $(LIBTARGET_SO_MMM) $(BUILD_SO)
endef
define make-bin
$(AT)cp $(OBJ_BIN) $(BUILD_BIN_MMM)
$(AT)ln -sf $(BIN_MMM) $(BUILD_BIN)
$(AT)$(MAKE_EXTRA_BINS_CMD)
endef
define make-doc
$(AT)$(MAKE_DOC_CMD)
endef
define make-install
cp -r $(BUILD_INCLUDE_DIR)/* $(INSTALL_INCLUDE_DIR)
cp $(BUILD_A) $(INSTALL_A)
cp $(BUILD_SO_MMM) $(INSTALL_SO_MMM)
ln -sf $(LIBTARGET_SO_MMM) $(INSTALL_SO_MM)
ln -sf $(LIBTARGET_SO_MMM) $(INSTALL_SO)
cp $(BUILD_BIN_MMM) $(INSTALL_BIN_MMM)
ln -sf $(BIN_MMM) $(INSTALL_BIN)
$(INSTALL_EXTRA_BINS_CMD)
$(INSTALL_DOC_CMD)
perl $(BUILDTOOLS_DIR)/gen_pkgconfig.pl $(TARGET) $(INSTALL_DIR) $(MAJOR).$(MINOR).$(MICRO) $(PKGCONFIG_DIR) "$(REQUIRES)" "A light-weight neural network compiler for different software/hardware backends."
$(INSTALL_PYTHON)
endef
define make-uninstall
rm -rf $(INSTALL_INCLUDE_DIR)
rm -f $(INSTALL_A)
rm -f $(INSTALL_SO)
rm -f $(INSTALL_SO_MM)
rm -f $(INSTALL_SO_MMM)
rm -f $(INSTALL_BIN)
rm -f $(INSTALL_BIN_MMM)
$(UNINSTALL_EXTRA_BINS_CMD)
$(UNINSTALL_DOC_CMD)
rm -f $(PKGCONFIG_DIR)/$(TARGET).pc
$(UNINSTALL_PYTHON)
endef
define make-clean
$(AT)$(MAKE) -C $(SRC_DIR) clean; $(MAKE) -C $(TEST_DIR) clean
rm -rf $(BUILD_DIR)
endef
.PHONY: all lib bin test plugin cmd doc clean info help install uninstall
all: lib bin
install:
$(call make-install-dir)
$(call make-install)
bin: lib
$(AT)$(MAKE) -C $(SRC_DIR) bin
$(call make-bin)
lib:
$(call make-build-dir)
$(call pre-make-config)
$(AT)$(MAKE) -C $(SRC_DIR) lib
$(call make-lib)
test: lib
$(AT)$(MAKE) -C $(TEST_DIR) all
cmd:
$(call make-build-dir)
$(call pre-make-config)
$(AT)$(MAKE) -C $(SRC_DIR) cmd
$(AT)$(MAKE) -C $(TEST_DIR) cmd
plugin:
$(call make-plugin)
plugin-test:
$(call make-plugin-test)
plugin-cmd:
$(call make-plugin-cmd)
doc:
$(call make-build-dir)
$(call make-doc)
clean:
$(call make-clean)
uninstall:
$(call make-uninstall)
info:
@echo "Available make targets:"
@echo " all: make lib, bin"
@echo " lib: make libraries"
@echo " bin: make executables"
@echo " test: make lib, test and run test"
@echo " plugin: make plugin library; should use P=dir to specify plugin directory"
@echo " cmd: generate $(BUILD_DIR)/compile_commands.json for clang tooling;"
@echo " use 'cmd' before 'all/lib/bin/test' for the initial generation"
@echo " doc: make documents"
@echo " install: install to $(INSTALL_DIR)"
@echo " clean: remove all the files generated by the build"
@echo " uninstall: uninstall installed files"
@echo " info/help: show this infomation"
help: info