-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
317 lines (243 loc) · 5.72 KB
/
makefile
File metadata and controls
317 lines (243 loc) · 5.72 KB
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
# _ _ _
# ___ ___ ___ _| |_|___| |_
# | | _ _| | | _ _|
# | _|_| |___ ___|_|___ |
# |_| |_|
# makefile (yupp, gcc)
# -- name of binary file without extension
TARGET = predict
# -- creating MAP file
MAP = 0
# -- platform
ifeq ($(OS),Windows_NT)
# MSDOS: __DJGPP__
# WIN32: __MINGW__
# UNIX: __UNIX__
PLATFORM = __MINGW__
else
# UNIX
PLATFORM = __UNIX__
endif
TOP = .
# -- compiler
ifeq ($(PLATFORM),__DJGPP__)
CC = $(DJGPP_HOME)/bin/gcc.exe
CXX = $(DJGPP_HOME)/bin/gxx.exe
LINK = $(CC)
else
CC = gcc
CXX = g++
LINK = $(CC)
endif
# -- yupp preprocessor
YUPP_HOME = $(TOP)/yupp
# -- perform preprocessing
SKIP_PP = 0
# -- skip preprocessing
# SKIP_PP = 1
ifeq ($(SKIP_PP),0)
PP = python -u $(YUPP_HOME)/yup.py
else
PP = @echo makefile: warning: preprocessing step is skipped,
endif
# -- command to create directories
MKDIR = mkdir -p
# -- output subdirectory
ifeq ($(PLATFORM),__DJGPP__)
D_PLATFORM = djgpp
else
ifeq ($(PLATFORM),__MINGW__)
D_PLATFORM = mingw
else
D_PLATFORM = .
endif
endif
D_SOU = source
# -- import directories for yupp
D_YU = $(D_SOU)/app $(D_SOU)/app/ut $(D_SOU)/app/dep \
$(D_SOU)/core $(D_SOU)/core/ut $(D_SOU)/core/dep \
$(D_SOU)/platform/$(D_PLATFORM)
# -- source directories
D_C = $(D_YU)
D_CXX = $(D_C)
D_ASM = $(D_SOU)
# -- include directories
D_H = $(D_C) $(YUPP_HOME)/lib
# -- binary file directory
D_BIN = $(TOP)/bin
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 -Wno-unbound $(addprefix -d, $(D_YU))
# -- compiler flags
CFLAGS = $(addprefix -I, $(D_H)) -O2 -std=gnu99 -W -Wall -Wno-comment
CXXFLAGS = $(addprefix -I, $(D_H)) -O2 -ffast-math -funroll-loops -fno-exceptions -fomit-frame-pointer -g -W -Wall -Wno-comment
ASMFLAGS = -Wall
# -- platform specific options
ifeq ($(PLATFORM),__DJGPP__)
BUFSIZE = 16k
MINSTACK = 1024k
endif
# ---------------------------------
# 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
# ---------------------------------
_BASH = 1
ifeq ($(OS),Windows_NT)
ifdef ComSpec
_BASH = 0
endif
endif
ifeq ($(_BASH),0)
# -- cmd
RM = cmd /c del /f
else
# -- sh (MSYS)
RM = rm -rf
endif
# -- 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
ifeq ($(PLATFORM),__DJGPP__)
define final
stubedit $1 minstack=$(MINSTACK) bufsize=$(BUFSIZE)
endef
else
define final
endef
endif
# -- 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 ($(_BASH),0)
# -- cmd
CLEAN = cmd /c del /f $(subst /,\,$(R))
CLEAN_BIN = cmd /c del /f $(R_BIN)
else
# -- sh (MSYS)
CLEAN = rm -rf $(R)
CLEAN_BIN = rm -rf $(R_BIN)
endif
# -- 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: bindirs $(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 $@)
# -- create 'object' and 'bin' directories
bindirs: $(D_OBJ) $(D_BIN)
$(D_OBJ):
${MKDIR} ${D_OBJ}
$(D_BIN):
${MKDIR} ${D_BIN}
# -- perform preprocessing only
.PHONY: yupp
yupp: $(G_C) $(G_CXX) $(G_H)
# -- 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