/
Tubsengine
302 lines (228 loc) · 8.73 KB
/
Tubsengine
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
INCLUDE := -I Include -I aweblibs/include -I aweb/include
NETINCLUDE := -I /gg/netinclude
NETINCLUDE2 :=
SSLINCLUDE := -I /gg/amissl-sdk/include
ALPHALIB :=
CC := m68k-amigaos-gcc
AR := m68k-amigaos-ar
BUILD_CC := gcc
BUILDDATE= $(shell build/builddate)
MODULELIB = linklibs/libmoduleinit.a
CFLAGS := -g -mcrt=nix20 -fomit-frame-pointer -m68000 -Werror-implicit-function-declaration \
-Wall -Wno-parentheses -D__AMIGADATE__='$(BUILDDATE)'
CPPFLAGS := -Dstpbrk=strpbrk $(INCLUDE)
LDFLAGS = -noixemul -specs tools/gcc.spec -Ldistribution/linklibs/ -lawebclib -ldebug
RM = rm -f -R $(1)
MKDIRS = mkdir -p $(1)
ECHO = echo $(1)
COPY = cp $(1) $(2)
FCAT = compcat $(1) $(2) $(3)
DISTDIR := distribution/
BUILDDIR := build/
ALL_MODULES :=
ALL_DEPS :=
build/module/executable/common/language := C
ifeq ($(TERM),amiga)
_Y := 37
_G := 35
_R := 34
else
_Y := 33
_G := 32
_R := 31
endif
WARN = 1
#################################################
# Handle logging of building activities. #
# To be used only inside build macros. #
# #
# $(1) - the action being performed #
# $(2) - the log file to use #
# $(3) - the command to execute #
# $(4) - the log level. If empty, then the #
# value $(LOGLEVEL) will be used #
#################################################
define build/log
@$(call ECHO, -n "$(1)... "); { $(3); } 2>$(2); res=$$$$?; \
if [ "$$$$res" != "0" ]; then \
$(call ECHO, -e "\\033[1;$(_R)m"FAILED"\\033[0;39m"); \
$(call ECHO, $(3)); \
cat $(2); \
exit $$$$res; \
else \
if [ -s $(2) ]; then \
$(call ECHO, -e "\\033[1;$(_Y)m"PASSED"\\033[0;39m"); \
if [ $(WARN) != "1" ]; then \
$(call ECHO, -n ""); \
else \
$(call ECHO, ""); \
cat $(2); \
$(call ECHO, ""); \
fi; \
else \
$(call ECHO, -e "\\033[1;$(_G)m"OK"\\033[0;39m"); \
fi; \
fi
endef
##################################
define build/module/executable/common/language/C
$(1)/OBJS += $($(1)/CFILES:%=$(BUILDDIR)$(1)/%.o)
$(1)/OBJS/CDEPS := $($(1)/CFILES:%=$(BUILDDIR)$(1)/%.d)
$(BUILDDIR)$(1)/%.o : $$($(1)/SRCDIR)%.c | $(BUILDDIR)$(1)
$(call build/log,Compiling [$(1)] $$<,$$@.err, \
$(CC) -c $(CFLAGS) $$($(1)/CFILES/CFLAGS) $$($(1)/CFILES/$$*/CFLAGS) \
$$($(1)/CFILES/$$*/CPPFLAGS) $$($(1)/CFILES/CPPFLAGS) $(CPPFLAGS) \
-I $$($(1)/SRCDIR)include $$< -o $$@ \
)
ifeq (,$(filter true, $(NOCDEPS) $($(1)/NOCDEPS)))
$(BUILDDIR)$(1)/%.d : $$($(1)/SRCDIR)%.c | $(BUILDDIR)$(1)
$(call build/log,Generating dependency list for $$<,$$@.err, \
$(CC) -M $$($(1)/CFILES/$$*/CPPFLAGS) $$($(1)/CFILES/CPPFLAGS) $(CPPFLAGS) \
-I $$($(1)/SRCDIR)include $$< | sed 's;^.*\.o:;$$(dir $$@)&;' > $$@ \
)
ifeq (,$(filter clean distclean $(1)-clean $(1)-distclean $(notdir $(1))-clean $(notdir $(1))-distclean,$(MAKECMDGOALS)))
ifneq (,$(filter all $(1) $(notdir $(1)) $(BUILDDIR)$(1)/%.o $(DISTDIR)$(1),$(if $(ALL_DEPS),$(ALL_DEPS),$(1))))
-include $$($(1)/OBJS/CDEPS)
endif
endif
endif
endef
##################################
##################################
define build/module/executable/common
$(1)/OBJS :=
$$(foreach lang,$(build/module/executable/common/language),$$(eval $$(call build/module/executable/common/language/$$(lang),$(1))))
$(DISTDIR)$(1) : $$($(1)/DEPS)
endef
##################################
##################################
define build/module/executable/application
$(eval $(call build/module/executable/common,$(1)))
$(DISTDIR)$(1): $$($(1)/OBJS) | $(dir $(DISTDIR)$(1))
$(call build/log,Linking $$@,$(BUILDDIR)$(1).err, \
$(CC) -o $$@ $$($(1)/OBJS) $(LDFLAGS) $$($(1)/LDFLAGS) \
)
endef
##################################
##################################
define build/module/executable/library/amigashared
$(1)/LDFLAGS += -nostartfiles -lgcc -lm -lmoduleinit
$(eval $(call build/module/executable/application,$(1)))
endef
##################################
##################################
define build/module/executable/library/link
$(eval $(call build/module/executable/common,$(1)))
$(DISTDIR)$(1): $$($(1)/OBJS) | $(dir $(DISTDIR)$(1))
$(call build/log,Making link library $$@,$(BUILDDIR)$(1).err, \
$(AR) cr $$@ $$? \
)
endef
##################################
#default module type is executable/application
build/module/ = $(build/module/executable/application)
##################################
ifneq ($($(BUILDDIR)/__DIRECTORYMADE__),yes)
$(BUILDDIR)/__DIRECTORYMADE__:=yes
$(BUILDDIR) :
$(call MKDIRS, $@)
endif
ifneq ($($(DISTDIR)/__DIRECTORYMADE__),yes)
$(DISTDIR)/__DIRECTORYMADE__:=yes
$(DISTDIR) :
$(call MKDIRS, $@)
endif
##################################
define build/module
#FIXME: this is not really good, because these targets might conflict with the $(BUILDDIR)/%
#ones.
$(1): $(DISTDIR)$(1)
$(1)-clean: $(DISTDIR)$(1)-clean
$(1)-distclean: $(DISTDIR)$(1)-distclean
$(notdir $(1)): $(DISTDIR)$(1)
$(notdir $(1))-clean: $(DISTDIR)$(1)-clean
$(notdir $(1))-distclean: $(DISTDIR)$(1)-distclean
$(DISTDIR)$(1)-clean:
$(call RM, $(BUILDDIR)$(1)); \
$$(if "$$(wildcard $(dir $(BUILDDIR)$(1))*)",,$(call RM, $(dir $(BUILDDIR)$(1))))
$(DISTDIR)$(1)-distclean: $(DISTDIR)$(1)-clean
$(call RM, $(DISTDIR)$(1)); \
$$(if "$$(wildcard $(dir $(DISTDIR)$(1))*)",,$(call RM, $(dir $(DISTDIR)$(1))))
.PHONY: $(1)-clean $(1)-distclean $(notdir $(1))-clean $(notdir $(1))-distclean
.ALIAS: $(1) $(notdir $(1))
ifneq ($($(BUILDDIR)$(1)/__DIRECTORYMADE__),yes)
$(BUILDDIR)$(1)/__DIRECTORYMADE__:=yes
$(BUILDDIR)$(1) :
$$(call MKDIRS, $$@)
endif
ifneq ($($(DISTDIR)$(dir $(1))/__DIRECTORYMADE__),yes)
$(DISTDIR)$(dir $(1))/__DIRECTORYMADE__:=yes
$(DISTDIR)$(dir $(1)) :
$$(call MKDIRS, $$@)
endif
$(eval $(call build/module/$($(1)/TYPE),$(1)))
endef
##################################
##################################
define build/module/document
$(1)/DOCS := $(addprefix $($(1)/SRCDIR),$($(1)/FILES))
$(DISTDIR)$(1): $$($(1)/DOCS) | $(DISTDIR)$(dir $(1))
$(call COPY, $$($(1)/DOCS), $(DISTDIR)$(dir $(1)))
endef
##################################
define build/module/catalog
$(1)/CATS := $(addprefix $(DISTDIR)$(dir $(1)),$(foreach ap, $($(1)/APPS), $(addsuffix /$(ap).catalog,$($(1)/LANGUAGES))))
$(1)/CDS := $(addsuffix .cd, $($(1)/APPS))
$(DISTDIR)$(1): $$($(1)/CATS)
# this next is not so good the catalogs should only depend on their own .cd file but
# I can't find a way to do this
$$($(1)/CATS): $$($(1)/CDS)
$(DISTDIR)$(dir $(1))%.catalog : $$($(1)/SRCDIR)%.ct
mkdir -p $$(dir $$@)
FlexCat FILL $$(basename $$(notdir $$@)).cd $$< catalog=$$@; ret=$$$$?; if [ $$$$ret -ge 10 ]; then exit 1; else exit 0; fi;
endef
##################################
# 1) include a given makefile
# 2) add the modules it defines to the global modules list
# 3) set the SRCDIR variable for each module if it's not defined already
define add_modules
#make sure MODULES is initialized to an empty value, in case something goes wrong in the
#included makefile
MODULES :=
include $(1)
ALL_MODULES += $$(MODULES)
$$(foreach m,$$(MODULES),$$(eval $$(if $$($$(m)/SRCDIR), , $$(m)/SRCDIR := $$(dir $(1)))))
endef
########################################################################################
#The real makefile begins --here--
#This is the first target in the makefile. It just redirects to all_modules which
#does the real job. It's here so that even if the included makefiles define some
#other targets, __all_modules__ always gets executed first (unless otherwise specified
#in the command line)
all: __all_modules__
include $(BUILDDIR)Tubsfiles
$(warning Adding modules...)
$(foreach t,$(TUBSFILES),$(eval $(call add_modules,$(t))))
#The two functions below work together to calculate the complete list
#of all dependencies of the modules to build, given on the command line.
#In case no modules are given by the user then the list will be empty,
#however the real list should be filled with ALL dependencies of ALL
#available modules, but we optimize this out so that the build is faster
define getdeplist_1
$(foreach m,$(1),$(if $(filter $(m),$(__ALLDEPS__)),,$(eval __ALLDEPS__ += $(m)) \
$(call getdeplist_1,$($(m)/DEPS))))
endef
getdeplist = $(eval __ALLDEPS__ :=) $(call getdeplist_1,$(1)) $(__ALLDEPS__)
$(warning Finding out modules dependencies...)
ALL_DEPS := $(strip $(call getdeplist,$(MAKECMDGOALS)))
__all_modules__: $(ALL_MODULES:%=$(DISTDIR)%)
#invoke build/module on every module
#build module recursively invokes some other functions which take care
#of everything on the basis of the module's type.
$(warning Building modules...)
$(foreach m,$(ALL_MODULES),$(eval $(call build/module,$(m))))
clean:
@$(call RM,$(BUILDDIR))
distclean: clean
@$(call RM,$(DISTDIR))
.PHONY: all __all_modules__ clean