forked from alibaba/xoc
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathMakefile.xoc
150 lines (122 loc) · 3.88 KB
/
Makefile.xoc
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
$(info "====---- START Makefile.xoc ----====")
ifeq ($(TARG),)
$(error "NEED TARG INFO:e.g:make TARG=FOR_ARM TARG_DIR=arm")
endif
ifeq ($(TARG_DIR),)
$(error "NEED TARG_DIR INFO:e.g:make TARG=FOR_ARM TARG_DIR=arm")
endif
ifeq ($(THREAD_NUM),)
THREAD_NUM=1
endif
CFLAGS+=-Wall
OPT_DIR=opt
COM_DIR=com
READER_DIR=reader
MACH_DIR=mach
CURFILE=$(CURDIR)/Makefile.xoc
$(info "INCLUDE: IN $(CURFILE), INCLUDE $(READER_DIR)/Makefile.inc")
include $(READER_DIR)/Makefile.inc
$(info "INCLUDE: IN $(CURFILE), INCLUDE $(COM_DIR)/Makefile.inc")
include $(COM_DIR)/Makefile.inc
$(info "INCLUDE: IN $(CURFILE), INCLUDE $(OPT_DIR)/Makefile.inc")
include $(OPT_DIR)/Makefile.inc
$(info "INCLUDE: IN $(CURFILE), INCLUDE $(MACH_DIR)/Makefile.inc")
include $(MACH_DIR)/Makefile.inc
$(info "INCLUDE: IN $(CURFILE), INCLUDE Makefile.xoc.inc")
include Makefile.xoc.inc
$(info "INCLUDE: IN $(CURFILE), INCLUDE Makefile.option")
include Makefile.option
#SET DEFAULT CFLAGS.
CFLAGS+=\
-D$(TARG) \
-D_SUPPORT_C11_ \
-Wno-unknown-pragmas \
-Wno-write-strings \
-Wsign-promo \
-Wparentheses \
-Wformat \
-Wsign-compare \
-Wpointer-arith \
-Wno-multichar \
-Winit-self \
-Wswitch
#Disable -Wconversion to avoid too much complaints.
ifneq (,$(filter $(CC),g++ gcc))
CFLAGS+=-Wno-strict-aliasing -finline-limit=10000000
endif
INC=-I .
#Combine path of objects.
TMP_OPT_OBJS = $(foreach n,$(OPT_OBJS),$(OPT_DIR)/$(n))
TMP_READER_OBJS = $(foreach n,$(READER_OBJS),$(READER_DIR)/$(n))
ifeq ($(REF_TARGMACH_INFO),true)
TMP_MACH_OBJS = $(foreach n,$(MACH_OBJS),$(MACH_DIR)/$(n))
else
TMP_MACH_OBJS =
endif
#Display internal variables.
$(info "COMBINED OPT OBJS:$(TMP_OPT_OBJS)")
$(info "COMBINED READER OBJS:$(TMP_READER_OBJS)")
$(info "COMBINED MACH OBJS:$(TMP_MACH_OBJS)")
$(info "TARG:$(TARG)")
$(info "TARG_DIR:$(TARG_DIR)")
$(info "CURDIR:$(CURDIR)")
$(info "ROOT_DIR:$(ROOT_DIR)")
$(info "CC:$(CC)")
$(info "INC:$(INC)")
$(info "CFLAGS:$(CFLAGS)")
$(info "DEBUG:$(DEBUG)")
$(info "THREAD_NUM:$(THREAD_NUM)")
#Define rules.
$(XOC_OUTPUT): $(COM_OUTPUT) tmp_opt_objs tmp_reader_objs tmp_mach_objs
@echo "START BUILD $(XOC_OUTPUT)"
@echo "EXEC:"
ar rcs $(XOC_OUTPUT) $(COM_DIR)/$(COM_OUTPUT) $(TMP_OPT_OBJS) \
$(TMP_READER_OBJS) $(TMP_MACH_OBJS)
@echo "END BUILD $(XOC_OUTPUT)"
@echo "SUCCESS TO GENERATE $(XOC_OUTPUT)!!"
%.o:%.cpp
@echo "BUILD $<"
$(CC) $(CFLAGS) $(INC) -c $< -o $@
$(COM_OUTPUT):
@echo "BUILD $(COM_OUTPUT)"
@echo "EXEC:"
cd $(COM_DIR) && make -j$(THREAD_NUM) -f Makefile TARG=$(TARG) \
DEBUG=$(DEBUG) CFLAGS="$(CFLAGS)" THREAD_NUM=$(THREAD_NUM)
tmp_opt_objs: $(TMP_OPT_OBJS)
@echo "EXEC:tmp_opt_objs:$(TMP_OPT_OBJS)"
tmp_reader_objs: $(TMP_READER_OBJS)
@echo "EXEC:tmp_reader_objs:$(TMP_READER_OBJS)"
tmp_mach_objs: $(TMP_MACH_OBJS)
@echo "EXEC:tmp_mach_objs:$(TMP_MACH_OBJS)"
opt_objs: $(OPT_OBJS)
@echo "EXEC:opt_objs:$(OPT_OBJS)"
reader_objs: $(READER_OBJS)
@echo "EXEC:reader_objs:$(READER_OBJS)"
mach_objs: $(MACH_OBJS)
@echo "EXEC:mach_objs:$(MACH_OBJS)"
clean:
cd $(COM_DIR) && make clean -f Makefile TARG=$(TARG) DEBUG=$(DEBUG) \
CFLAGS="$(CFLAGS)"
@find ./ -name "*.gcda" | xargs rm -f
@find ./ -name "*.gcno" | xargs rm -f
@find ./ -name "*.o" | xargs rm -f
@find ./ -name "*.d" | xargs rm -f
@find ./ -name "*.a" | xargs rm -f
@find ./ -name "*.dot" | xargs rm -f
@find ./ -name "*.exe" | xargs rm -f
@find ./ -name "*.elf" | xargs rm -f
@find ./ -name "*.out" | xargs rm -f
@find ./ -name "*.tmp" | xargs rm -f
@find ./ -name "*.vcg" | xargs rm -f
@find ./ -name "*.cxx" | xargs rm -f
@find ./ -name "*.asm" | xargs rm -f
@find ./ -name "*.swp" | xargs rm -f
@find ./ -name "*.swo" | xargs rm -f
@find ./ -name "*.log" | xargs rm -f
@find ./ -name "*.LOGLOG" | xargs rm -f
@find ./ -name "LOGLOG" | xargs rm -f
-include $(READER_DIR)/*.d
-include $(COM_DIR)/*.d
-include $(OPT_DIR)/*.d
-include $(MACH_DIR)/*.d
$(info "====---- END Makefile.xoc ----====")