forked from mdecalza/embryo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoommake.script
More file actions
715 lines (568 loc) · 19.6 KB
/
Copy pathdoommake.script
File metadata and controls
715 lines (568 loc) · 19.6 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
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
/****************************************************************************
* DoomMake Build Script
*
* DoomMake employs a language called RookScript.
* Documentation is included for this in the DoomTools docs folder.
* All WadScript and DoomMake extensions are available here.
****************************************************************************/
#include "scripts/doommake-lib.script"
#include "scripts/doommake-init.script"
/* ------------------------------------------------------------------------ */
/**
* Cleans the build directory and distro directory found in the properties.
*/
function doClean() {
initBuild();
println("Cleaning build and dist...");
out = cleandir(getBuildDirectory()) && cleandir(getDistDirectory());
println("Done.");
return out;
}
/* ------------------------------------------------------------------------ */
#define PROP_PATCH_INPUT "doommake.file.patch.input"
#define SRC_PATCH "/patch"
#define SRC_PATCH_FILE "dehacked.deh"
/**
* Copies a patch.
*/
check function doPatch() {
initBuild();
outFile = getBuildDirectory() + "/" + getPatchFile();
inFile = getSourceDirectory() + SRC_PATCH + "/" + prop(PROP_PATCH_INPUT, SRC_PATCH_FILE);
sourceDir = getSourceDirectory() + SRC_PATCH;
verifydirs(sourceDir);
if (checkFileExistenceAndBuildStatuses(outFile)) {
hash = directoryHasChanged(sourceDir);
if (hash === null) {
println("[Skipped] Patch directory (" + sourceDir + ") up to date.");
return;
}
} else {
hash = getDirectoryHash(sourceDir);
}
println("Copying patch...");
copyfile(inFile, outFile, true);
storeDirectoryChanged(sourceDir, hash);
setBuilt("dehacked");
}
/* ------------------------------------------------------------------------ */
#define SRC_DIR_CONVERT "/convert"
/**
* Converts sound assets in the conversion directories.
* Puts them in the build conversion folder.
*/
check function doConvertSounds() {
initBuild();
sourceDir = getSourceDirectory() + SRC_DIR_CONVERT + "/sounds";
targetDir = getBuildDirectory() + SRC_DIR_CONVERT + "/sounds";
verifydirs(sourceDir);
verifydirs(targetDir);
hash = directoryHasChanged(sourceDir);
if (hash === null) {
println("[Skipped] Sound conversion directory (" + sourceDir + ") up to date.");
return;
}
println("Converting sounds...");
convertdmx(sourceDir, targetDir);
storeDirectoryChanged(sourceDir, hash);
setBuilt("convert-sound");
println("Sounds converted from `" + sourceDir + "` to `" + targetDir + "`.");
}
/**
* Converts graphics assets in the conversion directories.
* Puts them in the build conversion folder.
*/
check function doConvertGraphics() {
initBuild();
sourceDir = getSourceDirectory() + SRC_DIR_CONVERT + "/graphics";
targetDir = getBuildDirectory() + SRC_DIR_CONVERT + "/graphics";
verifydirs(sourceDir);
verifydirs(targetDir);
hash = directoryHasChanged(sourceDir);
if (hash === null) {
println("[Skipped] Graphic conversion directory (" + sourceDir + ") up to date.");
return;
}
println("Converting graphics...");
convertimg(sourceDir, targetDir, "graphics");
storeDirectoryChanged(sourceDir, hash);
setBuilt("convert-graphics");
println("Graphics converted from `" + sourceDir + "` to `" + targetDir + "`.");
}
/**
* Converts sprite assets in the conversion directories.
* Puts them in the build conversion folder.
*/
check function doConvertSprites() {
initBuild();
sourceDir = getSourceDirectory() + SRC_DIR_CONVERT + "/sprites";
targetDir = getBuildDirectory() + SRC_DIR_CONVERT + "/sprites";
verifydirs(sourceDir);
verifydirs(targetDir);
hash = directoryHasChanged(sourceDir);
if (hash === null) {
println("[Skipped] Sprite conversion directory (" + sourceDir + ") up to date.");
return;
}
println("Converting sprites...");
convertimg(sourceDir, targetDir, "graphics");
storeDirectoryChanged(sourceDir, hash);
setBuilt("convert-sprites");
println("Sprites converted from `" + sourceDir + "` to `" + targetDir + "`.");
}
/**
* Converts colormap assets in the conversion directories.
* Puts them in the build conversion folder.
*/
check function doConvertColormaps() {
initBuild();
sourceDir = getSourceDirectory() + SRC_DIR_CONVERT + "/colormaps";
targetDir = getBuildDirectory() + SRC_DIR_CONVERT + "/colormaps";
verifydirs(sourceDir);
verifydirs(targetDir);
hash = directoryHasChanged(sourceDir);
if (hash === null) {
println("[Skipped] Colormap conversion directory (" + sourceDir + ") up to date.");
return;
}
println("Converting colormaps...");
convertimg(sourceDir, targetDir, "colormaps");
storeDirectoryChanged(sourceDir, hash);
setBuilt("convert-colormaps");
println("Colormaps converted from `" + sourceDir + "` to `" + targetDir + "`.");
}
/* ------------------------------------------------------------------------ */
#define SRC_DIR_ASSETS "/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"));
}
// Remove the colormap namespace if empty.
sx = wadentryindex(wf, "C_START");
sy = wadentryindex(wf, "C_END");
if (sx !== null && (sy - sx === 1)) {
wf->waddelete(wf->wadentryindex("C_START"));
wf->waddelete(wf->wadentryindex("C_END"));
}
close(wf);
}
/**
* Calls the merge script for merging assets.
* Creates assets WAD.
*/
check function doAssets() {
initBuild();
outWad = getBuildDirectory() + "/" + getAssetsWAD();
sourceDir = getSourceDirectory() + SRC_DIR_ASSETS;
verifydirs(sourceDir + "/_global");
verifydirs(sourceDir + "/colormaps");
verifydirs(sourceDir + "/graphics");
verifydirs(sourceDir + "/music");
verifydirs(sourceDir + "/sounds");
verifydirs(sourceDir + "/sprites");
if (checkFileExistenceAndBuildStatuses(outWad, ["convert-sound", "convert-graphics", "convert-sprites", "convert-colormaps"])) {
hash = directoryHasChanged(sourceDir);
if (hash === null) {
println("[Skipped] Assets directory (" + sourceDir + ") up to date.");
return;
}
} else {
hash = getDirectoryHash(sourceDir);
}
println("Building assets...");
wadmerge(file(MERGESCRIPT_ASSETS), [
getBuildDirectory(),
getSourceDirectory(),
getAssetsWAD()
]);
cleanUpAssetWAD(outWad);
storeDirectoryChanged(sourceDir, hash);
setBuilt("assets");
}
/* ------------------------------------------------------------------------ */
#define SRC_DIR_MAPS "/maps"
#define MERGESCRIPT_MAPS "scripts/merge-maps.txt"
/**
* Merges maps together.
* Creates map WAD.
*/
check function doMaps() {
initBuild();
outWad = getBuildDirectory() + "/" + getMapsWad();
sourceDir = getSourceDirectory() + SRC_DIR_MAPS;
verifydirs(sourceDir);
if (checkFileExistenceAndBuildStatuses(outWad)) {
hash = directoryHasChanged(sourceDir);
if (hash === null) {
println("[Skipped] Maps directory (" + sourceDir + ") up to date.");
return;
}
} else {
hash = getDirectoryHash(sourceDir);
}
println("Building maps...");
wadmerge(file(MERGESCRIPT_MAPS), [
getBuildDirectory(),
getSourceDirectory(),
getMapsWad()
]);
storeDirectoryChanged(sourceDir, hash);
setBuilt("maps");
}
/* ------------------------------------------------------------------------ */
#define PROP_MAPTEXWAD "doommake.file.maptex"
#define DEFAULT_MAPTEXWAD "maptex.wad"
/**
* Return the output map textures WAD.
*/
function getMapTexWad() {
return prop(PROP_MAPTEXWAD, DEFAULT_MAPTEXWAD);
}
/* ------------------------------------------------------------------------ */
#define SRC_DIR_TEXTUREWADS "/wads/textures"
/**
* Scans the project for available texture WADs.
*/
function scanTextureWADList() {
return filelist(getSourceDirectory() + SRC_DIR_TEXTUREWADS, false, REGEX_WADFILES);
}
/* ------------------------------------------------------------------------ */
/**
* Extracts textures from the project texture WADs using the maps.
* Creates maptex WAD.
*/
check function doMapTextures() {
initBuild();
baseIwadPath = getIwad();
if (empty(baseIwadPath))
return error("NoIWAD", "An IWAD for this project was not set in properties: " + PROP_IWADPATH);
// Figure out where the textures are.
textureWad = getBuildDirectory() + "/" + getTextureWad();
mapsWadPath = getBuildDirectory() + "/" + getMapsWad();
outWad = getBuildDirectory() + "/" + getMapTexWad();
// Gather all WADs.
textureWadPathList = scanTextureWADList() ?? [];
if (fileexists(textureWad)) {
textureWadPathList->listAdd(textureWad);
}
if (empty(textureWadPathList)) {
println("[Skipped] No textures to extract for maps. Skipping texture extraction.");
wadfilecreate(outWad);
return;
}
// Only do if maps were compiled.
if (!fileExists(mapsWadPath)) {
println("[Skipped] No maps at `" + mapsWadPath + "`. Maps WAD not built. Skipping texture extraction.");
wadfilecreate(outWad);
return;
}
// Texture extraction.
if (checkFileExistenceAndBuildStatuses(outWad, ["maps", "textures"])) {
println("[Skipped] Both maps and textures were not built. Skipping map texture rebuild.");
return;
}
println("Extracting map textures...");
extractUsedMapTextures(
baseIwadPath,
[mapsWadPath],
textureWadPathList,
outWad
);
setBuilt("maptextures");
}
/* ------------------------------------------------------------------------ */
#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"
/**
* 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, args) {
iwadPath = getIwad();
if (empty(iwadPath))
return error("NoIWAD", "An IWAD for this project was not set in properties: " + PROP_IWADPATH);
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);
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 = [];
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 (args) each (a : args) {
arguments->listadd(a);
}
return execresult(exec(
exepath, arguments, envvars(), exeworkdir, stdout(), stderr(), stdin()
));
}
/* ------------------------------------------------------------------------ */
check function runCommon(args)
{
// Must use native separator for args passed to program.
fs = prop("file.separator", "/");
patchPath = getBuildDirectory() + fs + getPatchFile();
assetsWadPath = getBuildDirectory() + fs + getAssetsWAD();
mapsWadPath = getBuildDirectory() + fs + getMapsWAD();
texWadPath = getBuildDirectory() + fs + getTextureWAD();
mapTexWadPath = getBuildDirectory() + fs + getMapTextureWAD();
wadList = [];
if (fileexists(assetsWadPath))
wadlist->listAdd(assetsWadPath);
if (fileexists(mapsWadPath))
wadlist->listAdd(mapsWadPath);
// Run will add either add the reduced texture set from compiled maps
// or the compiled textures WAD. If you want to explicitly use one or the
// other, edit the following lines:
if (fileexists(mapTexWadPath))
wadlist->listAdd(mapTexWadPath);
else if (fileexists(texWadPath))
wadlist->listAdd(texWadPath);
// Set DEH file here, if any.
dehFile = fileexists(patchPath) ? file(patchPath) : null;
if (length(args) > 1) {
argrest = args->sublist(1);
}
return doRun(args[0], wadList, dehFile, argrest);
}
/* ------------------------------------------------------------------------ */
#define MERGESCRIPT_RELEASE "scripts/merge-release.txt"
#define SRC_WADINFO "/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(getSourceDirectory() + SRC_WADINFO);
println("Copying " + srcfile + " to " + destfile + "...");
return copyfile(srcfile, destfile, true);
}
/**
* Builds every component for the project release.
*/
check function doAll() {
initBuild();
doPatch();
doConvertSounds();
doConvertGraphics();
doConvertSprites();
doConvertColormaps();
doAssets();
doMaps();
doMapTextures();
}
/**
* Merges all components into the project file and creates the distributable.
*/
check function doRelease() {
outFile = getBuildDirectory() + "/" + getProjectWAD();
if (checkFileExistenceAndBuildStatuses(outFile, ["dehacked", "maps", "assets", "maptextures"])) {
println("[Skipped] No pertinent project data built.");
return;
}
wadmerge(file(MERGESCRIPT_RELEASE), [
getBuildDirectory()
,getSourceDirectory()
,getProjectWad()
,getPatchFile()
,getAssetsWAD()
,getMapsWad()
,getMapTexWad()
]);
setBuilt("release");
}
/**
* Assembles the distributable.
*/
check function doDist() {
projectFile = getBuildDirectory() + "/" + getProjectWAD();
outTextFile = getBuildDirectory() + "/" + getProjectTXT();
outDistZipFile = getDistDirectory() + "/" + getProjectZip();
outDistTextFile = getDistDirectory() + "/" + getProjectTXT();
if (checkFileExistenceAndBuildStatuses([outTextFile, outDistZipFile, outDistTextFile], "release")) {
println("[Skipped] No release rebuilt - no distributable needs building.");
return;
}
println("Assembling distributable...");
// Assemble project archive.
initDist();
copyProjectTXT(outTextFile);
copyProjectTXT(outDistTextFile);
println("Zipping project to " + outDistZipFile + "...");
zipfiles(outDistZipFile, [
projectFile,
outTextFile
]);
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
*****************************************************************************
* Copies the DeHackEd patch.
* doommake patch
****************************************************************************/
check entry patch(args) {
doPatch();
}
/*****************************************************************************
* TARGET: convert
*****************************************************************************
* Converts assets to Doom assets and puts them in the asset directories.
* doommake convert
****************************************************************************/
check entry convert(args) {
doConvertSounds();
doConvertGraphics();
doConvertSprites();
doConvertColormaps();
}
/*****************************************************************************
* TARGET: assets
*****************************************************************************
* Converts and merges the assets WAD.
* doommake assets
****************************************************************************/
check entry assets(args) {
doConvertSounds();
doConvertGraphics();
doConvertSprites();
doConvertColormaps();
doAssets();
}
/*****************************************************************************
* TARGET: maps
*****************************************************************************
* Merges the maps WAD.
* doommake maps
****************************************************************************/
check entry maps(args) {
doMaps();
}
/*****************************************************************************
* TARGET: maptextures
*****************************************************************************
* Reads the map WADs and available texture resources and exports
* a WAD of used textures.
* doommake maptextures
****************************************************************************/
check entry maptextures(args) {
doMapTextures();
}
/*****************************************************************************
* TARGET: run
*****************************************************************************
* Runs this project.
* doommake run [optional:portname]
****************************************************************************/
check entry run(args) {
doInit(args);
doAll();
return runCommon(args);
}
/*****************************************************************************
* TARGET: justrun
*****************************************************************************
* Runs this project with no pre-build.
* doommake justrun [optional:portname]
****************************************************************************/
check entry justrun(args) {
doInit(args);
return runCommon(args);
}
/****************************************************************************
* TARGET: all
****************************************************************************
* Builds all parts of the project.
* doommake all
****************************************************************************/
check entry all(args) {
doInit();
doAll();
}
/****************************************************************************
* TARGET: release
****************************************************************************
* Creates a release WAD.
* doommake release
****************************************************************************/
check entry release(args) {
doInit();
doAll();
doRelease();
}
/****************************************************************************
* TARGET: make
****************************************************************************
* Default make target.
* Creates a release and packages up the distribution.
* doommake
****************************************************************************/
check entry make(args) {
doInit();
doAll();
doRelease();
doDist();
}