forked from cnplab/cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
374 lines (286 loc) · 10.7 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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
################################################################################
# Basic configurations
################################################################################
verbose ?= n
debug ?= n
# The domain helper: one of [none, xcl, xl]
DOMLIB ?= none
DOM_NONE := n
DOM_XCL := n
DOM_XL := n
ifeq ($(DOMLIB),none)
DOM_NONE := y
else ifeq ($(DOMLIB),xcl)
DOM_XCL := y
else ifeq ($(DOMLIB),xl)
DOM_XL := y
else
$(error Invalid domain helper $(DOMLIB))
endif
ifneq (,$(filter $(DOMLIB),xcl xl))
ifndef XEN_ROOT
$(error "Define XEN_ROOT to build with DOMLIB=$(DOMLIB)")
endif
endif
XEN_HOST_VERSION := $(shell xl info | grep -E "(xen_major|xen_minor|xen_extra)" | \
cut -d: -f2 | tr -d ' ' | tr -d '.' | tr '\n' '.' | \
awk -F '.' '{ split($$3, a, "-"); printf "%01x%02x%02x", $$1, $$2, a[1]; }')
XEN_ROOT_VERSION := $(shell cd $(XEN_ROOT); make --no-print-directory -C xen xenversion | \
awk -F '.' '{ split($$3, a, "-"); printf "%01x%02x%02x", $$1, $$2, a[1]; }')
define XEN_VERSION_ERR
Version mismatch between your host and the sources you are using:
host-xenversion=$(XEN_HOST_VERSION)
build-xenversion=$(XEN_ROOT_VERSION)
endef
ifneq (,$(filter $(DOMLIB),xcl xl))
ifneq ($(XEN_HOST_VERSION), $(XEN_ROOT_VERSION))
$(error $(XEN_VERSION_ERR))
endif
endif
XEN_VERSION := $(XEN_HOST_VERSION)
PYTHON_VERSION ?= 2.7
V8_SWIG ?= swig
V8_VERSION ?= 3.15.5.9
V8_INCLUDE ?= /root/apps/node-v0.10.18/deps/v8/include
.PHONY:
default: all
################################################################################
# Base commands and functions
################################################################################
CP = cp -a
MV = mv -f
LN = ln -sf
RM = rm -f
MKDIR = mkdir -p
RMDIR = rm -rf
TOUCH = touch
ASCOMPILE = $(CC) $(ASDEFINES) $(CDEFINES) $(CINCLUDES) $(ASFLAGS)
COMPILE = $(CC) $(CDEFINES) $(CINCLUDES) $(CPPFLAGS) $(CFLAGS)
CCLD = $(CC)
CCLINK = $(CCLD) $(CFLAGS) $(1) $(LDFLAGS) -o $@
CXXCOMPILE = $(CXX) $(CDEFINES) $(CINCLUDES) $(CPPFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(CXXLD) $(CXXFLAGS) $(1) $(LDFLAGS) -o $@
SWIG = swig
SWIGCOMPILE = $(SWIG) $(SWIGFLAGS) $(SWIGINCLUDES)
XXD ?= xxd
ifneq ($(verbose),y)
ascompile = @/bin/echo ' ' $(2) $< && $(ASCOMPILE) $(1)
ccompile = @/bin/echo ' ' $(2) $< && $(COMPILE) $(1)
cclink = @/bin/echo ' ' $(2) $@ && $(CCLINK)
cxxcompile = @/bin/echo ' ' $(2) $< && $(CXXCOMPILE) $(1)
cxxlink = @/bin/echo ' ' $(2) $< && $(CXXLINK)
swig = @/bin/echo ' ' $(2) $< && $(SWIGCOMPILE) $(1)
archive = @/bin/echo ' ' $(2) $@ && $(AR) cr $(1)
x_verbose_cmd = $(if $(2),/bin/echo ' ' $(2) $(3) &&,) $(1) $(3)
verbose_cmd = @$(x_verbose_cmd)
else
ascompile = $(ASCOMPILE) $(1)
ccompile = $(COMPILE) $(1)
cclink = $(CCLINK)
cxxcompile = $(CXXCOMPILE) $(1)
cxxlink = $(CXXLINK)
swig = $(SWIGCOMPILE) $(1)
archive = $(AR) crv $(1)
x_verbose_cmd = $(1) $(3)
verbose_cmd = $(1) $(3)
endif
################################################################################
# Build directory structure
################################################################################
ROOT_DIR ?= $(realpath .)
SOURCE_DIR ?= $(ROOT_DIR)/src
INCLUDE_DIR ?= $(ROOT_DIR)/include
BUILD_DIR ?= $(ROOT_DIR)/build
DIST_DIR ?= $(ROOT_DIR)/dist
BIN_DIR ?= $(DIST_DIR)/bin
LIB_DIR ?= $(DIST_DIR)/lib
BUILD_DIRS += $(BUILD_DIR)
BUILD_DIRS += $(DIST_DIR)
BUILD_DIRS += $(BIN_DIR)
BUILD_DIRS += $(LIB_DIR)
################################################################################
# Configure building
################################################################################
CDEFINES += -DXEN_VERSION=$(XEN_VERSION)
CINCLUDES += -I$(INCLUDE_DIR)
CFLAGS += -std=gnu99
CFLAGS += -fno-strict-aliasing
CFLAGS += -fPIC
CFLAGS += -Wall -Wstrict-prototypes
CFLAGS += -Wno-format-zero-length
LDFLAGS += -lxenctrl
LDFLAGS += -lxenguest
LDFLAGS += -lxenstore
LDFLAGS += -luuid -ldl -lutil
ifeq ($(debug),y)
CFLAGS += -O0 -g
endif
################################################################################
# libxcl
################################################################################
LIBXCL_VERSION := 0.1.0
LIBXCL_VERSION_MAJOR := 0
LIBXCL_BUILD_DIR = $(BUILD_DIR)/libxcl
LIBXCL_SOURCE_DIR = $(SOURCE_DIR)/xcl
LIBXCL_OBJS0 = \
xcl_dom.o \
xcl_net.o
LIBXCL_OBJS = $(addprefix $(LIBXCL_BUILD_DIR)/,$(LIBXCL_OBJS0))
BUILD_DIRS += $(LIBXCL_BUILD_DIR)
$(LIBXCL_BUILD_DIR)/%.o: CINCLUDES += -I$(INCLUDE_DIR)/xcl
$(LIBXCL_BUILD_DIR)/%.o: CINCLUDES += -I$(XEN_ROOT)/tools/libxl
$(LIBXCL_BUILD_DIR)/%.o: CINCLUDES += -I$(XEN_ROOT)/tools/libxc
$(LIBXCL_BUILD_DIR)/%.o: CINCLUDES += -I$(XEN_ROOT)/tools/include
$(LIBXCL_BUILD_DIR)/%.o: $(LIBXCL_SOURCE_DIR)/%.c | bootstrap
$(call ccompile,-c $< -o $@,'CC ')
$(LIB_DIR)/libxcl.so: LDFLAGS += -shared
$(LIB_DIR)/libxcl.so: $(LIBXCL_OBJS) | bootstrap
$(call verbose_cmd,$(LN) libxcl.so,'LN ',$@.$(LIBXCL_VERSION))
$(call verbose_cmd,$(LN) libxcl.so,'LN ',$@.$(LIBXCL_VERSION_MAJOR))
$(call cclink,$^,'LD ')
.PHONY: libxcl
libxcl: $(LIB_DIR)/libxcl.so
.PHONY: clean-libxcl
clean: clean-libxcl
clean-libxcl:
$(call verbose_cmd,$(RM) $(LIBXCL_BUILD_DIR)/*.o,'CLN $(LIBXCL_BUILD_DIR)/*.o')
.PHONY: distclean-libxcl
distclean: distclean-libxcl
distclean-libxcl: clean-libxcl
$(call verbose_cmd,$(RMDIR),'CLN',$(LIBXCL_BUILD_DIR))
$(call verbose_cmd,$(RM) $(LIB_DIR)/libxcl.so*,'CLN $(LIB_DIR)/libxcl.so')
################################################################################
# libxl
################################################################################
LIBXL_CINCLUDES = -I$(XEN_ROOT)/tools/libxl
LIBXL_LDFLAGS = -lxenlight -lxlutil -lyajl
################################################################################
# libcosmos
################################################################################
LIBCOSMOS_VERSION := 0.1.0
LIBCOSMOS_VERSION_MAJOR := 0
LIBCOSMOS_BUILD_DIR = $(BUILD_DIR)/libcosmos
LIBCOSMOS_SOURCE_DIR = $(SOURCE_DIR)
LIBCOSMOS_OBJS0-y = \
clickos.o
LIBCOSMOS_OBJS0-$(DOM_NONE) += domain_none.o
LIBCOSMOS_OBJS0-$(DOM_XCL) += domain_xcl.o
LIBCOSMOS_OBJS0-$(DOM_XL) += domain_xl.o
LIBCOSMOS_OBJS = $(addprefix $(LIBCOSMOS_BUILD_DIR)/,$(LIBCOSMOS_OBJS0-y))
LIBCOSMOS_CFLAGS-y :=
LIBCOSMOS_CFLAGS-$(DOM_XCL) += -DHAVE_XCL
LIBCOSMOS_CFLAGS-$(DOM_XL) += -DHAVE_XL
LIBCOSMOS_CFLAGS = $(LIBCOSMOS_CFLAGS-y)
LIBCOSMOS_CINCLUDES-y :=
LIBCOSMOS_CINCLUDES-$(DOM_XCL) += $(LIBXCL_CINCLUDES)
LIBCOSMOS_CINCLUDES-$(DOM_XL) += $(LIBXL_CINCLUDES)
LIBCOSMOS_CINCLUDES = $(LIBCOSMOS_CINCLUDES-y)
LIBCOSMOS_LDFLAGS-y :=
LIBCOSMOS_LDFLAGS-$(DOM_XCL) += $(LIBXCL_LDFLAGS)
LIBCOSMOS_LDFLAGS-$(DOM_XL) += $(LIBXL_LDFLAGS)
LIBCOSMOS_LDFLAGS = $(LIBCOSMOS_LDFLAGS-y)
BUILD_DIRS += $(LIBCOSMOS_BUILD_DIR)
$(LIBCOSMOS_BUILD_DIR)/%.o: CFLAGS += $(LIBCOSMOS_CFLAGS)
$(LIBCOSMOS_BUILD_DIR)/%.o: CINCLUDES += $(LIBCOSMOS_CINCLUDES)
$(LIBCOSMOS_BUILD_DIR)/%.o: $(LIBCOSMOS_SOURCE_DIR)/%.c | bootstrap
$(call ccompile,-c $< -o $@,'CC ')
$(LIB_DIR)/libcosmos.so: LDFLAGS += -shared
$(LIB_DIR)/libcosmos.so: $(LIBCOSMOS_OBJS) | bootstrap
$(call verbose_cmd,$(LN) libcosmos.so,'LN ',$@.$(LIBCOSMOS_VERSION))
$(call verbose_cmd,$(LN) libcosmos.so,'LN ',$@.$(LIBCOSMOS_VERSION_MAJOR))
$(call cclink,$^,'LD ')
.PHONY: libcosmos
libcosmos: $(LIB_DIR)/libcosmos.so
.PHONY: clean-libcosmos
clean: clean-libcosmos
clean-libcosmos:
$(call verbose_cmd,$(RM) $(LIBCOSMOS_BUILD_DIR)/*.o,'CLN $(LIBCOSMOS_BUILD_DIR)/*.o')
.PHONY: distclean-libcosmos
distclean: distclean-libcosmos
distclean-libcosmos: clean-libcosmos
$(call verbose_cmd,$(RMDIR),'CLN',$(LIBCOSMOS_BUILD_DIR))
$(call verbose_cmd,$(RM) $(LIB_DIR)/libcosmos.so*,'CLN $(LIB_DIR)/libcosmos.so')
################################################################################
# cosmos
################################################################################
COSMOS_APP = $(BIN_DIR)/cosmos
COSMOS_BUILD_DIR = $(BUILD_DIR)/cosmos
COSMOS_OBJS0 = \
main.o
COSMOS_OBJS-y = $(addprefix $(COSMOS_BUILD_DIR)/,$(COSMOS_OBJS0))
COSMOS_OBJS-y += $(LIBCOSMOS_OBJS)
COSMOS_OBJS-$(DOM_XCL) += $(LIBXCL_OBJS)
COSMOS_OBJS = $(COSMOS_OBJS-y)
BUILD_DIRS += $(COSMOS_BUILD_DIR)
$(COSMOS_BUILD_DIR)/%.o: CFLAGS += $(LIBCOSMOS_CFLAGS)
$(COSMOS_BUILD_DIR)/%.o: CINCLUDES += $(LIBCOSMOS_CINCLUDES)
$(COSMOS_BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c | bootstrap
$(call ccompile,-c $< -o $@,'CC ')
$(COSMOS_APP): LDFLAGS+=$(LIBCOSMOS_LDFLAGS)
$(COSMOS_APP): $(COSMOS_OBJS) | bootstrap
$(call cclink,$^,'LD ')
.PHONY: cosmos
all: cosmos
cosmos: $(BIN_DIR)/cosmos
.PHONY: clean-cosmos
clean: clean-cosmos
clean-cosmos:
$(call verbose_cmd,$(RM) $(COSMOS_BUILD_DIR)/*.o,'CLN $(COSMOS_BUILD_DIR)/*.o')
.PHONY: distclean-cosmos
distclean: distclean-cosmos
distclean-cosmos: clean-cosmos
$(call verbose_cmd,$(RM),'CLN',$(COSMOS_APP))
################################################################################
# bindings
################################################################################
BINDING_CFLAGS = -fPIC
BINDING_LDFLAGS = -L$(LIB_DIR) -lcosmos
SWIGFLAGS = -DBINDING_SWIG
SWIGINCLUDES = -I$(INCLUDE_DIR)
python-binding: BINDING_CINCLUDES += -I/usr/include/python$(PYTHON_VERSION)
js-binding: SWIG = $(V8_SWIG)
js-binding: SWIGFLAGS += -c++ -v8
js-binding: BINDING_CFLAGS += $(V8_INCLUDE)
# So that make doesn't delete intermediary files (in which the target is included)
.SECONDARY:
%-binding: LDFLAGS += -shared
%-binding: $(LIB_DIR)/%-cosmos.so
@#
$(LIB_DIR)/%-cosmos.so: $(BUILD_DIR)/%/cosmos_wrap.o $(LIBCOSMOS_OBJS)
$(call cclink, $^,'LD ')
$(BUILD_DIR)/%/cosmos_wrap.o: CFLAGS = $(BINDING_CFLAGS)
$(BUILD_DIR)/%/cosmos_wrap.o: CINCLUDES = $(BINDING_CINCLUDES)
ifneq (,$(filter $(MAKECMDGOALS),js-binding))
$(BUILD_DIR)/%/cosmos_wrap.o: $(BUILD_DIR)/%/cosmos_wrap.cxx
$(call cxxcompile, -c $< -o $@,'CXX')
else
$(BUILD_DIR)/%/cosmos_wrap.o: $(BUILD_DIR)/%/cosmos_wrap.c
$(call ccompile, -c $< -o $@,'CC ')
endif
ifneq (,$(filter $(MAKECMDGOALS),js-binding))
$(BUILD_DIR)/%/cosmos_wrap.cxx: $(BUILD_DIR)/%/cosmos.i
else
$(BUILD_DIR)/%/cosmos_wrap.c: $(BUILD_DIR)/%/cosmos.i
endif
$(call swig, -includeall -$* $<,'SWG')
$(BUILD_DIR)/%/cosmos.i: $(SOURCE_DIR)/cosmos.i | bootstrap
$(call verbose_cmd, $(MKDIR), MKD, $(dir $@))
$(call verbose_cmd, $(CP), 'CP ',$< $@)
################################################################################
# Targets
################################################################################
.PHONY: all
all:
@#
.PHONY: bootstrap
bootstrap: $(BUILD_DIRS)
$(BUILD_DIRS):
$(call verbose_cmd,$(MKDIR),'MKD',$@)
.PHONY:clean
clean:
@#
.PHONY: distclean
distclean: clean
$(call verbose_cmd,$(RMDIR),'CLN',$(BUILD_DIR))
$(call verbose_cmd,$(RMDIR),'CLN',$(DIST_DIR))