forked from scummvm/scummvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
engines.awk
executable file
·394 lines (336 loc) · 10.8 KB
/
engines.awk
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#!/bin/awk -f
function get_values(var, arr) {
return split(ENVIRON[var], arr, " ")
}
# Add a line of data to config.mk.
function add_line_to_config_mk(line) {
print(line) >> config_mk
}
function add_to_config_h_if_yes(value, define) {
if (value == "yes")
print(define) >> config_h
else
print("/* " define " */") >> config_h
}
#
# Feature handling functions
#
# Get the name of the feature
function get_feature_name(feature) {
return ENVIRON["_feature_" feature "_name"]
}
# Check whether the feature is enabled
function get_feature_state(feature) {
get_values("_feature_" feature "_settings", settings)
for (i in settings) {
if (ENVIRON[settings[i]] == "yes")
return "yes"
}
return "no"
}
#
# Engine handling functions
#
# Get the name of the engine
function get_engine_name(engine) {
return ENVIRON["_engine_" engine "_name"]
}
# Will this engine be built?
function get_engine_build(engine) {
return ENVIRON["_engine_" engine "_build"]
}
# Was this engine set to be built by default?
function get_engine_build_default(engine) {
return ENVIRON["_engine_" engine "_build_default"]
}
# Get the subengines
function get_engine_subengines(engine, subengines) {
return get_values("_engine_" engine "_subengines", subengines)
}
# Get the dependencies
function get_engine_dependencies(engine, deps) {
return get_values("_engine_" engine "_deps", deps)
}
# Get the base engine game support description
function get_engine_base(engine) {
return ENVIRON["_engine_" engine "_base"]
}
# Ask if this is a subengine
function get_engine_sub(engine) {
subeng = ENVIRON["_engine_" engine "_sub"]
if (subeng == "")
subeng = "no"
return subeng
}
# Get a subengine's parent (undefined for non-subengines)
function get_subengine_parent(engine) {
return ENVIRON["_engine_" engine "_parent"]
}
function disable_engine(engine) {
ENVIRON["_engine_" engine "_build"] = "no"
}
function check_engine_deps(engine) {
unmet_deps = ""
# Check whether the engine is enabled
if (get_engine_build(engine) != "no") {
# Collect unmet dependencies
depcount = get_engine_dependencies(engine, deps)
for (d = 1; d <= depcount; d++) {
if (get_feature_state(deps[d]) == "no")
unmet_deps = unmet_deps get_feature_name(deps[d]) " "
}
# Check whether there is any unmet dependency
if (unmet_deps) {
print("WARNING: Disabling engine " get_engine_name(engine) " because the following dependencies are unmet: " unmet_deps)
disable_engine(engine)
}
}
}
# Prepare the strings about the engines to build
function prepare_engine_build_strings(engine) {
if (string = get_engine_build_string(engine, "static"))
_engines_built_static[++_static] = string
if (string = get_engine_build_string(engine, "dynamic"))
_engines_built_dynamic[++_dynamic] = string
if (string = get_engine_build_string(engine, "no"))
_engines_skipped[++_skipped] = string
if (string = get_engine_build_string(engine, "wip"))
_engines_built_wip[++_wip] = string
}
# Get the string about building an engine
function get_engine_build_string(engine, request_status) {
engine_build = get_engine_build(engine)
engine_build_default = get_engine_build_default(engine)
show = 0
# Convert static/dynamic to yes to ease the check of subengines
if (engine_build == "no")
subengine_filter = "no"
else
subengine_filter = "yes"
# Check if the current engine should be shown for the current status
if (engine_build == request_status) {
show = 1
} else {
# Test for disabled sub-engines
if (request_status == "no") {
get_engine_subengines(engine, subengines)
for (subeng in subengines) {
if (get_engine_build(subengines[subeng]) == "no") {
# In this case we to display _disabled_ subengines
subengine_filter = "no"
show = 1
break
}
}
}
# Test for enabled wip sub-engines
if (request_status == "wip") {
get_engine_subengines(engine, subengines)
for (subeng in subengines) {
if (get_engine_build(subengines[subeng]) != "no" && get_engine_build_default(subengines[subeng]) == "no") {
show = 1
break
}
}
}
}
# Check if it is a wip engine
if (request_status == "wip" && engine_build != "no" && engine_build_default == "no")
show = 1
# The engine should be shown, build the string
if (show)
return get_engine_name(engine) " " get_subengines_build_string(engine, subengine_filter, request_status)
}
# Get the string about building subengines
function get_subengines_build_string(parent_engine, subengine_filter, request_status) {
parent_engine_build_default = get_engine_build_default(parent_engine)
subengine_string = ""
# If the base engine isn't built at all, no need to list subengines
# in any of the possible categories.
if (get_engine_build(parent_engine) == "no")
return
all = 1
subeng_count = get_engine_subengines(parent_engine, subengines)
# If there are no subengines, never display "[all games]" (for brevity).
if (!subeng_count)
all = 0
# If the base engine does not fit the category we're displaying here
# (WIP or Skipped), we should never show "[all games]"
if (request_status == "wip" && parent_engine_build_default == "yes")
all = 0
if (request_status == "no") {
# If we're here, the parent engine is built, so no need to check that.
all = 0
}
# In the static/dynamic categories, also display the engine's base games.
if (subeng_count && request_status != "no" && request_status != "wip")
subengine_string = "[" get_engine_base(parent_engine) "]"
for (s = 1; s <= subeng_count; s++) {
subeng = subengines[s]
subengine_build = get_engine_build(subeng)
subengine_build_default = get_engine_build_default(subeng)
# Display this subengine if it matches the filter, unless it is
# a stable subengine in the WIP request.
if ((subengine_build == subengine_filter) && !(request_status == "wip" && subengine_build_default == "yes")) {
name = "[" get_engine_name(subeng) "]"
if (subengine_string)
subengine_string = subengine_string " " name
else
subengine_string = name
} else {
all = 0
}
}
# Summarize the full list, where applicable
if (all)
subengine_string = "[all games]"
return subengine_string
}
function print_engines(headline, engines, count) {
if (!count)
return
print("\n" headline)
for (e = 1; e <= count; e++)
print(" " engines[e])
}
BEGIN {
config_mk = "config.mk.engines"
config_h = "config.h.engines"
# Clear previous contents if any
printf("") > config_h
printf("") > config_mk
}
END {
engine_count = get_values("_engines", engines)
for (e = 1; e <= engine_count; e++) {
engine = engines[e]
check_engine_deps(engine)
if (get_engine_sub(engine) == "no") {
# It's a main engine
if (get_engine_build(engine) == "no") {
isbuilt = "no"
} else {
# If dynamic plugins aren't supported, mark
# all the engines as static
if (ENVIRON["_dynamic_modules"] == "no") {
ENVIRON["_engine_" engine "_build"] = "static"
} else {
# If it wasn't explicitly marked as static or
# dynamic, use the configured default
if (get_engine_build(engine) == "yes")
ENVIRON["_engine_" engine "_build"] = ENVIRON["_plugins_default"]
}
# Prepare the defines
if (get_engine_build(engine) == "dynamic") {
isbuilt = "DYNAMIC_PLUGIN"
} else {
ENVIRON["_engine_" engine "_build"] = "static"
isbuilt = "STATIC_PLUGIN"
}
}
} else {
# It's a subengine, just say yes or no
if (get_engine_build(engine) == "no")
isbuilt = "no"
else
isbuilt = "1"
}
# Save the settings
defname = "ENABLE_" toupper(engine)
if (isbuilt == "no")
add_line_to_config_mk("# " defname)
else
add_line_to_config_mk(defname " = " isbuilt)
}
# Sort engines to place our headline engine at start...
# No technical reason, just historical convention
headline_engine = "scumm"
sorted_engines[++sorted] = headline_engine
for (e = 1; e <= engine_count; e++) {
if (engines[e] != headline_engine)
sorted_engines[++sorted] = engines[e]
}
# Prepare the information to be shown
for (e = 1; e <= engine_count; e++) {
engine = sorted_engines[e]
if (get_engine_sub(engine) == "no") {
# It's a main engine
prepare_engine_build_strings(engine)
}
}
#
# Detection of WIP/unstable engines
#
for (e in engines) {
engine = engines[e]
if (get_engine_build(engine) != "no" && get_engine_build_default(engine) == "no") {
_tainted_build = "yes"
break
}
}
add_to_config_h_if_yes(_tainted_build, "#define TAINTED_BUILD")
print_engines("Engines (builtin):", _engines_built_static, _static)
print_engines("Engines (plugins):", _engines_built_dynamic, _dynamic)
print_engines("Engines Skipped:", _engines_skipped, _skipped)
print_engines("WARNING: This ScummVM build contains the following UNSTABLE engines:", _engines_built_wip, _wip)
# Ensure engines folder exists prior to trying to generate
# files into it (used for out-of-tree-builds)
system("mkdir -p engines")
print("")
print("Creating engines/engines.mk")
engines_mk = "engines/engines.mk.new"
print("# This file is automatically generated by configure\n" \
"# DO NOT EDIT MANUALLY\n" \
"# This file is being included by \"Makefile.common\"") > engines_mk
for (e = 1; e <= engine_count; e++) {
engine = sorted_engines[e]
j = toupper(engine)
if (get_engine_sub(engine) == "no") {
# main engine
print("\n" \
"ifdef ENABLE_" j "\n" \
"DEFINES += -DENABLE_" j "=$(ENABLE_" j ")\n" \
"MODULES += engines/" engine) >> engines_mk
subeng_count = get_engine_subengines(engine, subengines)
for (s = 1; s <= subeng_count; s++) {
k = toupper(subengines[s])
print("\n" \
"ifdef ENABLE_" k "\n" \
"DEFINES += -DENABLE_" k "\n" \
"endif") >> engines_mk
}
print("endif") >> engines_mk
}
}
# Name which is suffixed to each detection plugin
detectId = "_DETECTION"
det_table = "engines/detection_table.h.new"
print("Creating engines/detection_table.h")
print("/* This file is automatically generated by configure */\n" \
"/* DO NOT EDIT MANUALLY */\n" \
"// This file is being included by \"base/plugins.cpp\"") > det_table
for (e = 1; e <= engine_count; e++) {
engine = sorted_engines[e]
if (get_engine_sub(engine) == "no") {
j = toupper(engine)
detectEngine = j detectId
print("#if defined(ENABLE_" j ") || defined(DETECTION_FULL)\n" \
"LINK_PLUGIN(" j detectId ")\n" \
"#endif") >> det_table
}
}
plugins_table = "engines/plugins_table.h.new"
print("Creating engines/plugins_table.h")
print("/* This file is automatically generated by configure */\n" \
"/* DO NOT EDIT MANUALLY */\n" \
"// This file is being included by \"base/plugins.cpp\"") > plugins_table
for (e = 1; e <= engine_count; e++) {
engine = sorted_engines[e]
if (get_engine_sub(engine) == "no") {
j = toupper(engine)
print("#if PLUGIN_ENABLED_STATIC(" j ")\n" \
"LINK_PLUGIN(" j ")\n" \
"#endif") >> plugins_table
}
}
}