forked from in4lio/ev3dev-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.Debug
274 lines (207 loc) · 5.11 KB
/
Makefile.Debug
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
# _ _ _
# ___ ___ ___ _| |_|___| |_
# | | _ _| | | _ _|
# | _|_| |___ ___|_|___ |
# |_| |_|
# makefile (yupp, gcc)
# -- name of binary file equals to the folder name
TARGET = $(notdir $(shell pwd))
# -- creating MAP file
MAP = 0
# -- platform
ifeq ($(OS),Windows_NT)
# WIN32
PLATFORM = __MINGW__
else
# UNIX
PLATFORM = __UNIX__
endif
TOP = ../..
# -- compiler
ifeq ($(PLATFORM),__UNIX__)
CC = arm-linux-gnueabi-gcc
CXX = arm-linux-gnueabi-g++
else
CC = gcc
CXX = g++
endif
LINK = $(CC)
# -- build on EV3 BRICK
ifeq ($(PLATFORM),__UNIX__)
EV3 = $(if $(shell $(CC) -dM -E - < /dev/null | grep __ARM_ARCH_4T__),1,0)
else
EV3 = 0
endif
# -- yupp preprocessor
YUPP_HOME = $(TOP)/yupp
# -- perform preprocessing anywhere
# SKIP_PP = 0
# -- skip preprocessing on the EV3 brick (it's a bit slow), would be better to use pre-generated sources
SKIP_PP = $(EV3)
# -- skip preprocessing anywhere
# SKIP_PP = 1
ifeq ($(SKIP_PP),0)
PP = python -u $(YUPP_HOME)/yup.py
else
PP = @echo makefile: warning: preprocessing step is skipped,
endif
# -- output subdirectory
ifeq ($(PLATFORM),__MINGW__)
D_PLATFORM = mingw
else
D_PLATFORM =
endif
# -- import directories for yupp
D_YU = $(TOP)/source/ev3
# -- source directories
D_C = . $(TOP)/source/ev3 $(TOP)/3d_party
ifeq ($(EV3),0)
D_C := $(D_C) $(TOP)/source/ev3/ev3_link
endif
D_CXX = $(D_C)
D_ASM = $(TOP)/source
# -- include directories
D_H = $(D_C)
# -- binary file directory
D_BIN = Debug
D_BIN := $(if $(D_PLATFORM), $(D_BIN)/$(D_PLATFORM), $(D_BIN))
# -- object directory
D_OBJ = $(TOP)/object
D_OBJ := $(if $(D_PLATFORM), $(D_OBJ)/$(D_PLATFORM), $(D_OBJ))
# -- LIST and MAP directories
D_MAP = $(TOP)/object
D_LIST = $(TOP)/object
# -- source code suffix
E_YU = .yu
E_YUH = .yu-h
E_YUC = .yu-c
E_YUCXX = .yu-cpp
E_H = .h
E_C = .c
E_CXX = .cpp
E_ASM = .asm
# -- object suffix
E_OBJ = .o
# -- binary file suffix
ifeq ($(OS),Windows_NT)
E_BIN = .exe
else
E_BIN =
endif
# -- full name of binary file
F_BIN = $(D_BIN)/$(TARGET)$(E_BIN)
# -- LIST and MAP suffixes
E_MAP = .map
E_LIST = .listing
# -- link options
LIBS = -lm
ifeq ($(PLATFORM),__MINGW__)
LIBS := $(LIBS) -lws2_32
endif
LFLAGS =
ifeq ($(MAP),1)
LFLAGS := $(LFLAGS) -Wl,-Map,$(D_MAP)/$(TARGET)$(E_MAP)
endif
# -- preprocessor flags
PPFLAGS = -q --pp-browse $(addprefix -d, $(D_YU))
# -- compiler flags
CFLAGS = $(addprefix -I, $(D_H)) -O2 -std=gnu99 -W -Wall -Wno-comment
CXXFLAGS = $(addprefix -I, $(D_H)) -O2 -g -W -Wall -Wno-comment
ASMFLAGS = -Wall
# ---------------------------------
# files lists
# ---------------------------------
S_YU = $(wildcard $(addsuffix /*$(E_YU), $(D_YU)))
S_YUH = $(wildcard $(addsuffix /*$(E_YUH), $(D_H)))
S_YUC = $(wildcard $(addsuffix /*$(E_YUC), $(D_C)))
S_YUCXX = $(wildcard $(addsuffix /*$(E_YUCXX), $(D_CXX)))
G_CXX = $(addsuffix $(E_CXX), $(basename $(S_YUCXX)))
G_C = $(addsuffix $(E_C), $(basename $(S_YUC)))
G_H = $(addsuffix $(E_H), $(basename $(S_YUH)))
S_C = $(sort $(wildcard $(addsuffix /*$(E_C), $(D_C))) $(G_C))
S_CXX = $(sort $(wildcard $(addsuffix /*$(E_CXX), $(D_CXX))) $(G_CXX))
S_ASM = $(wildcard $(addsuffix /*$(E_ASM), $(D_ASM)))
O_CXX = $(addprefix $(D_OBJ)/, $(addsuffix $(E_OBJ), $(basename $(notdir $(S_CXX)))))
O_C = $(addprefix $(D_OBJ)/, $(addsuffix $(E_OBJ), $(basename $(notdir $(S_C)))))
O_ASM = $(addprefix $(D_OBJ)/, $(addsuffix $(E_OBJ), $(basename $(notdir $(S_ASM)))))
O = $(O_CXX) $(O_C) $(O_ASM)
# ---------------------------------
# commands
# ---------------------------------
# -- wrap compiler arguments
ifeq ($(OS),Windows_NT)
# -- too long command line workaround
define wrap
echo $2 > args
$1 @args
-rm args
endef
else
define wrap
$1 $2
endef
endif
# -- optional final tools
define final
endef
# -- removal list
R_BIN = $(F_BIN) $(O)
R = $(R_BIN)
ifeq ($(SKIP_PP),0)
R := $(R) $(G_H) $(G_C) $(G_CXX)
endif
ifeq ($(MAP),1)
R := $(R) $(D_MAP)/$(TARGET)$(E_MAP)
endif
ifeq ($(OS),Windows_NT)
#CLEAN = cmd /c "del $(subst /,\,$(R))"
CLEAN = rm -rf $(R)
else
CLEAN = rm -rf $(R)
endif
CLEAN_BIN = rm -rf $(R_BIN)
# -- install
define install
endef
# ---------------------------------
# make rules
# ---------------------------------
vpath %$(E_CXX) $(D_CXX)
vpath %$(E_C) $(D_C)
vpath %$(E_ASM) $(D_ASM)
vpath %$(E_YUCXX) $(D_CXX)
vpath %$(E_YUC) $(D_C)
# -- build binary file
.PHONY: default
default: $(F_BIN)
$(F_BIN): $(O)
$(call wrap,$(LINK),$^ -o $@ $(LIBS) $(LFLAGS))
$(call final,$@)
@echo "*** $(F_BIN) ***"
$(G_C) $(G_CXX) $(G_H): $(S_YU)
$(G_C): %$(E_C): %$(E_YUC)
$(call wrap,$(PP),$(PPFLAGS) $<)
$(G_CXX): %$(E_CXX): %$(E_YUCXX)
$(call wrap,$(PP),$(PPFLAGS) $<)
$(G_H): %$(E_H): %$(E_YUH)
$(call wrap,$(PP),$(PPFLAGS) $<)
$(S_C) $(S_CXX): $(G_H)
$(O_C): $(D_OBJ)/%$(E_OBJ): %$(E_C)
$(call wrap,$(CC),$(CFLAGS) -c $< -o $@)
$(O_CXX): $(D_OBJ)/%$(E_OBJ): %$(E_CXX)
$(call wrap,$(CXX),$(CXXFLAGS) -c $< -o $@)
$(O_ASM): $(D_OBJ)/%$(E_OBJ): %$(E_ASM)
$(call wrap,$(CC),$(ASMFLAGS) -c $< -o $@)
# -- remove temporary files
.PHONY: clean
clean:
$(CLEAN)
# -- remove binary and object files
.PHONY: clean-binary
clean-binary:
$(CLEAN_BIN)
# -- install
.PHONY: install
install:
$(call install)
# -- EOF