Skip to content

Commit f0ffdb3

Browse files
committed
REXM: Support building full example collection and categories
ADDED: Some log info
1 parent e7d27e5 commit f0ffdb3

File tree

1 file changed

+94
-52
lines changed

1 file changed

+94
-52
lines changed

tools/rexm/rexm.c

Lines changed: 94 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
#define SUPPORT_LOG_INFO
5858
#if defined(SUPPORT_LOG_INFO) && defined(_DEBUG)
59-
#define LOG(...) printf(__VA_ARGS__)
59+
#define LOG(...) printf("REXM: "__VA_ARGS__)
6060
#else
6161
#define LOG(...)
6262
#endif
@@ -221,10 +221,12 @@ int main(int argc, char *argv[])
221221
char exRecategory[32] = { 0 }; // Example re-name category: shapes
222222
char exRename[64] = { 0 }; // Example re-name, without extension
223223

224+
char exRebuildRequested[16] = { 0 }; // Example category/full rebuild request
225+
224226
int opCode = OP_NONE; // Operation code: 0-None(Help), 1-Create, 2-Add, 3-Rename, 4-Remove
225227
bool verbose = false; // Flag for verbose log info
226228

227-
// Command-line usage mode
229+
// Command-line usage mode: command args processing
228230
//--------------------------------------------------------------------------------------
229231
if (argc > 1)
230232
{
@@ -387,16 +389,25 @@ int main(int argc, char *argv[])
387389
else if (argc > 3) LOG("WARNING: Too many arguments provided\n");
388390
else
389391
{
390-
// Verify example exists in collection to be removed
391-
char *exColInfo = LoadFileText(exCollectionFilePath);
392-
if (TextFindIndex(exColInfo, argv[2]) != -1) // Example in the collection
392+
// Support building not only individual examples but categories and "ALL"
393+
if ((strcmp(argv[2], "ALL") == 0) || TextInList(argv[2], exCategories, REXM_MAX_EXAMPLE_CATEGORIES))
394+
{
395+
// Category/ALL rebuilt requested
396+
strcpy(exRebuildRequested, argv[2]);
397+
}
398+
else
393399
{
394-
strcpy(exName, argv[2]); // Register example name for removal
395-
strncpy(exCategory, exName, TextFindIndex(exName, "_"));
396-
opCode = OP_BUILD;
400+
// Verify example exists in collection to be removed
401+
char *exColInfo = LoadFileText(exCollectionFilePath);
402+
if (TextFindIndex(exColInfo, argv[2]) != -1) // Example in the collection
403+
{
404+
strcpy(exName, argv[2]); // Register example name for removal
405+
strncpy(exCategory, exName, TextFindIndex(exName, "_"));
406+
opCode = OP_BUILD;
407+
}
408+
else LOG("WARNING: BUILD: Example requested not available in the collection\n");
409+
UnloadFileText(exColInfo);
397410
}
398-
else LOG("WARNING: BUILD: Example not available in the collection\n");
399-
UnloadFileText(exColInfo);
400411
}
401412
}
402413

@@ -407,10 +418,14 @@ int main(int argc, char *argv[])
407418
}
408419
}
409420

421+
// Command-line usage mode: command execution
410422
switch (opCode)
411423
{
412424
case OP_CREATE: // Create: New example from template
413425
{
426+
LOG("INFO: Command requested: CREATE\n");
427+
LOG("INFO: Example to create: %s\n", exName);
428+
414429
// Create: raylib/examples/<category>/<category>_example_name.c
415430
char *exText = LoadFileText(exTemplateFilePath);
416431
char *exTextUpdated[6] = { 0 };
@@ -430,6 +445,9 @@ int main(int argc, char *argv[])
430445
}
431446
case OP_ADD: // Add: Example from command-line input filename
432447
{
448+
if (opCode != OP_CREATE) LOG("INFO: Command requested: ADD\n");
449+
LOG("INFO: Example file to be added: %s\n", inFileName);
450+
433451
// Add: raylib/examples/<category>/<category>_example_name.c
434452
if (opCode != OP_CREATE) FileCopy(inFileName, TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
435453

@@ -629,6 +647,9 @@ int main(int argc, char *argv[])
629647
} break;
630648
case OP_RENAME: // Rename
631649
{
650+
LOG("INFO: Command requested: RENAME\n");
651+
LOG("INFO: Example to be renamed: %s --> %s\n", exName, exRename);
652+
632653
// NOTE: At this point provided values have been validated:
633654
// exName, exCategory, exRename, exRecategory
634655
if (strcmp(exCategory, exRecategory) == 0)
@@ -740,6 +761,9 @@ int main(int argc, char *argv[])
740761
} break;
741762
case OP_REMOVE: // Remove
742763
{
764+
LOG("INFO: Command requested: REMOVE\n");
765+
LOG("INFO: Example to be removed: %s\n", exName);
766+
743767
// Remove example from collection for files update
744768
//------------------------------------------------------------------------------------------------
745769
char *exCollectionList = LoadFileText(exCollectionFilePath);
@@ -818,10 +842,70 @@ int main(int argc, char *argv[])
818842
FileRemove(TextFormat("%s/%s/%s.wasm", exWebPath, exCategory, exName));
819843
FileRemove(TextFormat("%s/%s/%s.js", exWebPath, exCategory, exName));
820844

845+
} break;
846+
case OP_BUILD:
847+
{
848+
LOG("INFO: Command requested: BUILD\n");
849+
LOG("INFO: Example to be built: %s\n", exRebuildRequested);
850+
851+
if ((strcmp(exRebuildRequested, "others") != 0) &&
852+
(strcmp(exCategory, "others") != 0)) // Skipping "others" category for rebuild: Special needs
853+
{
854+
int exRebuildCount = 0;
855+
rlExampleInfo *exRebuildList = LoadExamplesData(exCollectionFilePath, exRebuildRequested, false, &exRebuildCount);
856+
857+
// Build: raylib.com/examples/<category>/<category>_example_name.html
858+
// Build: raylib.com/examples/<category>/<category>_example_name.data
859+
// Build: raylib.com/examples/<category>/<category>_example_name.wasm
860+
// Build: raylib.com/examples/<category>/<category>_example_name.js
861+
862+
#if defined(_WIN32)
863+
// Set required environment variables
864+
//putenv(TextFormat("RAYLIB_DIR=%s\\..", exBasePath));
865+
putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin");
866+
//putenv("MAKE=mingw32-make");
867+
//ChangeDirectory(exBasePath);
868+
#endif
869+
for (int i = 0; i < exRebuildCount; i++)
870+
{
871+
// Build example for PLATFORM_DESKTOP
872+
#if defined(_WIN32)
873+
system(TextFormat("mingw32-make -C %s %s/%s PLATFORM=PLATFORM_DESKTOP -B", exBasePath, exRebuildList[i].category, exRebuildList[i].name));
874+
#else
875+
system(TextFormat("make -C %s %s/%s PLATFORM=PLATFORM_DESKTOP -B", exBasePath, exRebuildList[i].category, exRebuildList[i].name));
876+
#endif
877+
878+
// Build example for PLATFORM_WEB
879+
#if defined(_WIN32)
880+
system(TextFormat("mingw32-make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exRebuildList[i].category, exRebuildList[i].name));
881+
#else
882+
system(TextFormat("make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exRebuildList[i].category, exRebuildList[i].name));
883+
#endif
884+
// Update generated .html metadata
885+
UpdateWebMetadata(TextFormat("%s/%s/%s.html", exBasePath, exRebuildList[i].category, exRebuildList[i].name),
886+
TextFormat("%s/%s/%s.c", exBasePath, exRebuildList[i].category, exRebuildList[i].name));
887+
888+
// Copy results to web side
889+
FileCopy(TextFormat("%s/%s/%s.html", exBasePath, exRebuildList[i].category, exRebuildList[i].name),
890+
TextFormat("%s/%s/%s.html", exWebPath, exRebuildList[i].category, exRebuildList[i].name));
891+
FileCopy(TextFormat("%s/%s/%s.data", exBasePath, exRebuildList[i].category, exRebuildList[i].name),
892+
TextFormat("%s/%s/%s.data", exWebPath, exRebuildList[i].category, exRebuildList[i].name));
893+
FileCopy(TextFormat("%s/%s/%s.wasm", exBasePath, exRebuildList[i].category, exRebuildList[i].name),
894+
TextFormat("%s/%s/%s.wasm", exWebPath, exRebuildList[i].category, exRebuildList[i].name));
895+
FileCopy(TextFormat("%s/%s/%s.js", exBasePath, exRebuildList[i].category, exRebuildList[i].name),
896+
TextFormat("%s/%s/%s.js", exWebPath, exRebuildList[i].category, exRebuildList[i].name));
897+
}
898+
899+
UnloadExamplesData(exRebuildList);
900+
}
901+
else LOG("WARNING: [others] category examples should be build manually, they could have specific build requirements\n");
902+
821903
} break;
822904
case OP_VALIDATE: // Validate: report and actions
823905
case OP_UPDATE:
824906
{
907+
LOG("INFO: Command requested: %s\n", (opCode == OP_VALIDATE)? "VALIDATE" : "UPDATE");
908+
LOG("INFO: Example collection is being %s\n", (opCode == OP_VALIDATE)? "validated" : "validated and updated");
825909
/*
826910
// Validation flags available:
827911
VALID_MISSING_C
@@ -1285,48 +1369,6 @@ int main(int argc, char *argv[])
12851369
//------------------------------------------------------------------------------------------------
12861370

12871371
} break;
1288-
case OP_BUILD:
1289-
{
1290-
// Build: raylib.com/examples/<category>/<category>_example_name.html
1291-
// Build: raylib.com/examples/<category>/<category>_example_name.data
1292-
// Build: raylib.com/examples/<category>/<category>_example_name.wasm
1293-
// Build: raylib.com/examples/<category>/<category>_example_name.js
1294-
if (strcmp(exCategory, "others") != 0) // Skipping "others" category
1295-
{
1296-
// Build example for PLATFORM_DESKTOP
1297-
#if defined(_WIN32)
1298-
//putenv(TextFormat("RAYLIB_DIR=%s\\..", exBasePath));
1299-
putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin");
1300-
//putenv("MAKE=mingw32-make");
1301-
//ChangeDirectory(exBasePath);
1302-
system(TextFormat("mingw32-make -C %s %s/%s PLATFORM=PLATFORM_DESKTOP -B", exBasePath, exCategory, exName));
1303-
#else
1304-
system(TextFormat("make -C %s %s/%s PLATFORM=PLATFORM_DESKTOP -B", exBasePath, exCategory, exName));
1305-
#endif
1306-
1307-
// Build example for PLATFORM_WEB
1308-
#if defined(_WIN32)
1309-
putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin");
1310-
system(TextFormat("mingw32-make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exCategory, exName));
1311-
#else
1312-
system(TextFormat("make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exCategory, exName));
1313-
#endif
1314-
1315-
// Update generated .html metadata
1316-
UpdateWebMetadata(TextFormat("%s/%s/%s.html", exBasePath, exCategory, exName),
1317-
TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
1318-
1319-
// Copy results to web side
1320-
FileCopy(TextFormat("%s/%s/%s.html", exBasePath, exCategory, exName),
1321-
TextFormat("%s/%s/%s.html", exWebPath, exCategory, exName));
1322-
FileCopy(TextFormat("%s/%s/%s.data", exBasePath, exCategory, exName),
1323-
TextFormat("%s/%s/%s.data", exWebPath, exCategory, exName));
1324-
FileCopy(TextFormat("%s/%s/%s.wasm", exBasePath, exCategory, exName),
1325-
TextFormat("%s/%s/%s.wasm", exWebPath, exCategory, exName));
1326-
FileCopy(TextFormat("%s/%s/%s.js", exBasePath, exCategory, exName),
1327-
TextFormat("%s/%s/%s.js", exWebPath, exCategory, exName));
1328-
}
1329-
} break;
13301372
default: // Help
13311373
{
13321374
// Supported commands:

0 commit comments

Comments
 (0)