-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdoommake.script
384 lines (313 loc) · 10.9 KB
/
doommake.script
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
/*****************************************************************************
* vesper - doommake build script
* (mostly generated by doommake itself, so thanks to MTrop for all o' dis)
* (c) matt tropiano & xaser acheron 2021
* MIT License
****************************************************************************/
#include "scripts/doommake-lib.script"
#include "scripts/doommake-init.script"
/* ------------------------------------------------------------------------ */
/**
* Cleans the build directory found in the properties.
*/
function doClean() {
initBuild();
return cleandir(getBuildDirectory());
}
/* ------------------------------------------------------------------------ */
#define SRC_DECOHACK_DIR "/decohack"
#define SRC_DECOHACK_ROOT_MAIN "main"
#define SRC_DECOHACK_ROOT_EXT_DEATHMATCH "ext-deathmatch"
#define IN_DECOHACK_EXTENSION ".dh"
#define OUT_DECOHACK_PREFIX "dehsrc-"
#define OUT_DECOHACK_EXTENSION ".dh"
#define OUT_DEHACKED_PREFIX "dehacked-"
#define OUT_DEHACKED_EXTENSION ".deh"
/**
* Return the output patch file name.
*/
function getVesperPatchFile(rootName) {
return OUT_DEHACKED_PREFIX + rootName + OUT_DEHACKED_EXTENSION;
}
/**
* Return the output patch source file name.
*/
function getVesperPatchSourceOutputFile(rootName) {
return OUT_DECOHACK_PREFIX + rootName + OUT_DECOHACK_EXTENSION;
}
/**
* Return DECOHack root for the specified root name.
*/
function getVesperDECOHackRoot(rootName) {
return rootName + IN_DECOHACK_EXTENSION;
}
/**
* Calls DECOHack.
* Creates patch from the specified root file.
*/
check function doPatch(budget, sourceDir, rootName) {
outFile = getBuildDirectory() + "/" + getVesperPatchFile(rootName);
outSourceFile = getBuildDirectory() + "/" + getVesperPatchSourceOutputFile(rootName);
decohack(
file(sourceDir + "/" + getVesperDECOHackRoot(rootName)),
file(outFile),
budget,
file(outSourceFile)
);
}
/**
* Creates DEH patches. Word.
*/
check function doPatches(budget) {
initBuild();
sourceDir = getSourceDirectory() + SRC_DECOHACK_DIR;
verifydirs(sourceDir);
// [XA] TODO: make this work again :P
if (checkFileExistenceAndBuildStatuses(outFile)) {
hash = directoryHasChanged(sourceDir);
if (hash === null) {
println("[Skipped] DECOHack directory (" + sourceDir + ") up to date.");
return;
}
} else {
hash = directoryHasChanged(sourceDir);
}
println("Compiling patches...");
doPatch(budget, sourceDir, SRC_DECOHACK_ROOT_MAIN);
doPatch(budget, sourceDir, SRC_DECOHACK_ROOT_EXT_DEATHMATCH);
storeDirectoryChanged(sourceDir, hash);
setBuilt("dehacked");
}
/* ------------------------------------------------------------------------ */
#define SRC_DIR_ASSETS "src/assets"
#define MERGESCRIPT_ASSETS "scripts/merge-assets.txt"
/**
* Cleans up the created asset WAD.
*/
check function cleanUpAssetWAD(wadpath) {
wf = wadfile(wadpath);
// Remove the sprite namespace if empty.
sx = wadentryindex(wf, "SS_START");
sy = wadentryindex(wf, "SS_END");
if (sx !== null && (sy - sx === 1)) {
wf->waddelete(wf->wadentryindex("SS_START"));
wf->waddelete(wf->wadentryindex("SS_END"));
}
close(wf);
}
/**
* Calls the merge script for merging maps.
* Creates assets WAD.
*/
check function doAssets() {
initBuild();
verifydirs(SRC_DIR_ASSETS + "/_global");
verifydirs(SRC_DIR_ASSETS + "/graphics");
verifydirs(SRC_DIR_ASSETS + "/music");
verifydirs(SRC_DIR_ASSETS + "/sounds");
verifydirs(SRC_DIR_ASSETS + "/sprites");
wadmerge(file(MERGESCRIPT_ASSETS), [
getBuildDirectory(),
getAssetsWAD()
]);
cleanUpAssetWAD(getBuildDirectory() + "/" + getAssetsWAD());
}
/* ------------------------------------------------------------------------ */
#define PROP_RUN_EXE "doommake.run.exe"
#define PROP_RUN_EXE_WORK "doommake.run.exe.workdir"
#define PROP_RUN_SWITCH_IWAD "doommake.run.switch.iwad"
#define DEFAULT_RUN_SWITCH_IWAD "-iwad"
#define PROP_RUN_SWITCH_FILE "doommake.run.switch.file"
#define DEFAULT_RUN_SWITCH_FILE "-file"
#define PROP_RUN_SWITCH_DEH "doommake.run.switch.deh"
#define DEFAULT_RUN_SWITCH_DEH "-deh"
#define PROP_RUN_ARGS "doommake.run.args"
/**
* Calls a port to run this project.
* portType: If specified, then this looks for the properties that end with ".porttype".
* wadList: List of WAD files to add.
* dehFile: DEH file to add.
*/
check function doRun(portType, wadList, dehFile) {
portType = empty(portType) ? "" : "." + portType;
exepath = prop(PROP_RUN_EXE + portType);
exeworkdir = prop(PROP_RUN_EXE_WORK + portType) ?: fileparent(exepath);
iwadSwitch = prop(PROP_RUN_SWITCH_IWAD + portType, DEFAULT_RUN_SWITCH_IWAD);
fileSwitch = prop(PROP_RUN_SWITCH_FILE + portType, DEFAULT_RUN_SWITCH_FILE);
dehSwitch = prop(PROP_RUN_SWITCH_DEH + portType, DEFAULT_RUN_SWITCH_DEH);
miscArgs = prop(PROP_RUN_ARGS + portType);
if (empty(exepath))
return error("NoEXE", "Executable not specified. Requires a property to be set: " + PROP_RUN_EXE + portType);
if (!fileexists(exepath))
return error("NoEXE", "Executable could not be found: " + exepath);
if (!fileexists(exeworkdir))
return error("NoEXE", "Working directory for executable not found: " + exeworkdir);
if (empty(iwadSwitch))
return error("RunError", "IWAD switch not specified. Requires a property to be set: " + PROP_RUN_SWITCH_IWAD + portType);
if (empty(fileSwitch))
return error("RunError", "FILE switch not specified. Requires a property to be set: " + PROP_RUN_SWITCH_FILE + portType);
if (empty(dehSwitch))
return error("RunError", "DEH switch not specified. Requires a property to be set: " + PROP_RUN_SWITCH_DEH + portType);
arguments = [];
iwadPath = getIwad();
if (empty(iwadPath))
return error("NoIWAD", "An IWAD for this project was not set in properties: " + PROP_IWADPATH);
arguments->listadd(iwadSwitch);
arguments->listadd(iwadPath->filecanonpath());
if (!empty(wadList)) {
arguments->listadd(fileSwitch);
each (w : wadList)
arguments->listadd(w->filecanonpath());
}
if (!empty(dehFile)) {
arguments->listadd(dehSwitch);
arguments->listadd(dehFile->filecanonpath());
}
if (!empty(miscArgs)) {
each (a : strsplit(miscArgs, " "))
arguments->listadd(a);
}
return execresult(exec(
exepath, arguments, envvars(), exeworkdir, stdout(), stderr(), stdin()
));
}
/* ------------------------------------------------------------------------ */
#define MERGESCRIPT_RELEASE "scripts/merge-release.txt"
#define MERGESCRIPT_EXTENSION "scripts/merge-extension.txt"
#define SRC_WADINFO "src/wadinfo.txt"
/**
* Initializes the build directory.
*/
function initDist() {
return verifydirs(getDistDirectory());
}
/**
* Copies the WAD info to the build directory as its TXT file.
* Throws error if unsuccessful.
*/
function copyProjectTXT(destfile) {
srcfile = file(SRC_WADINFO);
println("Copying " + srcfile + " to " + destfile + "...");
return copyfile(srcfile, destfile, true);
}
/**
* Builds every component for the project release.
*/
check function doAll() {
initBuild();
doPatches(false);
doAssets();
}
/**
* Call wadmerge and build release wad
*/
function mergeRelease(mergescript, wadName, patchRoot) {
wadmerge(file(mergescript), [
getBuildDirectory()
,wadName
,getVesperPatchFile(patchRoot)
,getVesperPatchSourceOutputFile(patchRoot)
,getAssetsWAD()
]);
}
/**
* Return the project WAD file name.
*/
function getVesperExtensionWAD(patchRoot) {
return getProjectName() + "-" + patchRoot + ".wad";
}
/**
* Merges all components into the project file and creates the distributable.
*/
check function doRelease() {
mergeRelease(MERGESCRIPT_RELEASE, getProjectWad(), SRC_DECOHACK_ROOT_MAIN);
mergeRelease(MERGESCRIPT_EXTENSION, getVesperExtensionWAD(SRC_DECOHACK_ROOT_EXT_DEATHMATCH), SRC_DECOHACK_ROOT_EXT_DEATHMATCH);
// Assemble project archive.
initDist();
copyProjectTXT(getBuildDirectory() + "/" + getProjectTXT());
copyProjectTXT(getDistDirectory() + "/" + getProjectTXT());
zipProject([
getBuildDirectory() + "/" + getProjectWAD(),
getBuildDirectory() + "/" + getProjectTXT()
]);
println("Done!");
}
/****************************************************************************
* TARGET: init
****************************************************************************
* Initializes this project.
* doommake init
****************************************************************************/
check entry init(args) {
doInit(args);
}
/****************************************************************************
* TARGET: clean
****************************************************************************
* Cleans the build directory.
* doommake clean
****************************************************************************/
check entry clean(args) {
doClean();
}
/*****************************************************************************
* TARGET: patch
*****************************************************************************
* Compiles the DeHackEd patches (and shows the budget).
* doommake patch
****************************************************************************/
check entry patch(args) {
doPatches(true);
}
/*****************************************************************************
* TARGET: assets
*****************************************************************************
* Merges the assets WAD.
* doommake assets
****************************************************************************/
check entry assets(args) {
doAssets();
}
/*****************************************************************************
* TARGET: run
*****************************************************************************
* Runs this project.
* doommake run
****************************************************************************/
check entry run(args) {
wadList = [
getBuildDirectory() + "/" + getProjectWAD()
];
// Set DEH file here, if any.
dehFile = null;
return doRun(args[0], wadList, dehFile);
}
/****************************************************************************
* TARGET: all
****************************************************************************
* Builds all parts of the project.
* doommake all
****************************************************************************/
check entry all(args) {
doAll();
}
/****************************************************************************
* TARGET: release
****************************************************************************
* Creates a release and distribution.
* doommake release
****************************************************************************/
check entry release(args) {
doRelease();
}
/****************************************************************************
* TARGET: make
****************************************************************************
* Default make target.
* doommake
****************************************************************************/
check entry make(args) {
doInit();
doAll();
doRelease();
}