Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit e86364a

Browse files
committed
Improve the management of definitions in the compiler, separating the definitions for C and C++ in the makefile, and improve the management of the program version on the JSON
1 parent a645ace commit e86364a

6 files changed

Lines changed: 113 additions & 20 deletions

File tree

src/Main.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import src.utils.UDPListener;
1919
*/
2020
class Main {
2121
public static var hxcompileuString = "\x1b[38;5;214mHx\033[0mCompile\x1b[38;5;74mU\033[0m";
22-
public static final version:String = "1.5.1";
22+
public static final version:String = "1.5.3";
2323
static var stdin = Sys.stdin();
2424
static var stdout = Sys.stdout();
2525
static var args = Sys.args();

src/compilers/CafeCompiler.hx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ class CafeCompiler {
6060
makefileContent = makefileContent.replace("[SOURCE_DIR]", jsonFile.haxeConfig.outDir + "/src");
6161
makefileContent = makefileContent.replace("[INCLUDE_DIR]", jsonFile.haxeConfig.outDir + "/include");
6262
makefileContent = makefileContent.replace("[LIBS]", parseMakeLibs());
63-
makefileContent = makefileContent.replace("[DEFINES]", parseMakeDefines());
63+
makefileContent = makefileContent.replace("[C_DEFINES]", parseMakeDefines().c);
64+
makefileContent = makefileContent.replace("[CPP_DEFINES]", parseMakeDefines().cpp);
6465

6566
if (!FileSystem.exists(SlushiUtils.getPathFromCurrentTerminal() + "/" + jsonFile.haxeConfig.outDir + "/wiiuFiles")) {
6667
FileSystem.createDirectory(SlushiUtils.getPathFromCurrentTerminal() + "/" + jsonFile.haxeConfig.outDir + "/wiiuFiles");
@@ -90,7 +91,8 @@ class CafeCompiler {
9091
makefileContent = makefileContent.replace("[SOURCE_DIR]", jsonFile.haxeConfig.outDir + "/src");
9192
makefileContent = makefileContent.replace("[INCLUDE_DIR]", jsonFile.haxeConfig.outDir + "/include");
9293
makefileContent = makefileContent.replace("[LIBS]", parseMakeLibs());
93-
makefileContent = makefileContent.replace("[DEFINES]", parseMakeDefines());
94+
makefileContent = makefileContent.replace("[C_DEFINES]", parseMakeDefines().c);
95+
makefileContent = makefileContent.replace("[CPP_DEFINES]", parseMakeDefines().cpp);
9496

9597
if (!FileSystem.exists(SlushiUtils.getPathFromCurrentTerminal() + "/" + jsonFile.haxeConfig.outDir + "/wiiuFiles")) {
9698
FileSystem.createDirectory(SlushiUtils.getPathFromCurrentTerminal() + "/" + jsonFile.haxeConfig.outDir + "/wiiuFiles");
@@ -160,18 +162,27 @@ class CafeCompiler {
160162
return libs;
161163
}
162164

163-
static function parseMakeDefines():String {
164-
var defines = "";
165+
static function parseMakeDefines():{c:String, cpp:String} {
166+
var defines = {c: "", cpp: ""};
165167

166-
for (define in Defines.parseCDefines()) {
167-
defines += define + " ";
168+
for (define in Defines.parseMakeFileDefines().main) {
169+
defines.c += define + " ";
168170
}
169171

170172
if (jsonFile.haxeConfig.debugMode == true) {
171-
defines += "-D debug ";
173+
defines.c += "-D debug ";
172174
}
173175

174-
defines += JsonFile.parseJSONVars();
176+
defines.c += JsonFile.parseJSONVars();
177+
178+
// These things absolutely have to go to the end.
179+
for (define in Defines.parseMakeFileDefines().c) {
180+
defines.c += define + " ";
181+
}
182+
183+
for (define in Defines.parseMakeFileDefines().cpp) {
184+
defines.cpp += define + " ";
185+
}
175186

176187
return defines;
177188
}

src/compilers/MainCompiler.hx

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import src.compilers.HaxeCompiler;
1212

1313
import src.utils.LibsManager;
1414

15+
using StringTools;
16+
1517
/**
1618
* The main compiler, it will start the compilation of the project
1719
* in Haxe and Wii U.
@@ -25,11 +27,74 @@ class MainCompiler {
2527
* Starts the compilation of the project.
2628
*/
2729
public static function start(arg2:String, arg3:String):Void {
28-
if (SlushiUtils.parseVersion(Main.version) < SlushiUtils.parseVersion(JsonFile.getJson().programVersion)) {
29-
SlushiUtils.printMsg("The current version of HxCompileU is older than the one in the JSON file, consider updating it.", WARN);
30+
var jsonVersion:String = JsonFile.getJson().programVersion;
31+
var forced:Bool = jsonVersion.endsWith(":forced");
32+
var versionStr = forced ? jsonVersion.split(":")[0] : jsonVersion;
33+
34+
var operatorStr:String = "";
35+
var versionValue:String = versionStr;
36+
37+
if (versionStr.startsWith(">=")) {
38+
operatorStr = ">=";
39+
versionValue = versionStr.substr(2);
40+
} else if (versionStr.startsWith(">")) {
41+
operatorStr = ">";
42+
versionValue = versionStr.substr(1);
43+
} else if (versionStr.startsWith("<=")) {
44+
operatorStr = "<=";
45+
versionValue = versionStr.substr(2);
46+
} else if (versionStr.startsWith("<")) {
47+
operatorStr = "<";
48+
versionValue = versionStr.substr(1);
49+
}
50+
51+
var parsedJsonVersion = SlushiUtils.parseVersion(versionValue);
52+
var currentVersion = SlushiUtils.parseVersion(Main.version);
53+
54+
var versionMismatch:Bool = false;
55+
var shouldStop:Bool = false;
56+
57+
if (operatorStr == ">=") {
58+
if (currentVersion < parsedJsonVersion) {
59+
versionMismatch = true;
60+
shouldStop = true; // Stop if current version is less than required
61+
}
62+
// If currentVersion >= parsedJsonVersion, continue
63+
} else if (operatorStr == ">") {
64+
if (currentVersion <= parsedJsonVersion) {
65+
versionMismatch = true;
66+
shouldStop = true; // Stop if current version is less or equal
67+
}
68+
} else if (operatorStr == "<=") {
69+
if (currentVersion > parsedJsonVersion) {
70+
versionMismatch = true;
71+
shouldStop = true; // Stop if current version is greater than required
72+
}
73+
// If currentVersion <= parsedJsonVersion, continue
74+
} else if (operatorStr == "<") {
75+
if (currentVersion >= parsedJsonVersion) {
76+
versionMismatch = true;
77+
shouldStop = true; // Stop if current version is greater or equal
78+
}
79+
} else {
80+
if (currentVersion < parsedJsonVersion) {
81+
SlushiUtils.printMsg("The current version of HxCompileU is older than the one in the JSON file, consider updating it.", WARN);
82+
if (forced) {
83+
versionMismatch = true;
84+
shouldStop = true; // Stop if forced
85+
}
86+
} else if (currentVersion > parsedJsonVersion) {
87+
SlushiUtils.printMsg("The current version of HxCompileU is newer than the one in the JSON file, consider checking the JSON file.", WARN);
88+
if (forced) {
89+
versionMismatch = true;
90+
shouldStop = true; // Stop if forced
91+
}
92+
}
3093
}
31-
else if (SlushiUtils.parseVersion(Main.version) > SlushiUtils.parseVersion(JsonFile.getJson().programVersion)) {
32-
SlushiUtils.printMsg("The current version of HxCompileU is newer than the one in the JSON file, consider checking the JSON file.", WARN);
94+
95+
if (shouldStop) {
96+
SlushiUtils.printMsg("Cannot continue: The JSON requires a specific version of HxCompileU: " + jsonVersion, ERROR);
97+
return;
3398
}
3499

35100
// Check and get required libs

src/utils/Defines.hx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,28 @@ class Defines {
3838
* Parses the C defines from the JSON file.
3939
* @return Array<String>
4040
*/
41-
public static function parseCDefines():Array<String> {
42-
var defines:Array<String> = [];
41+
public static function parseMakeFileDefines():{main:Array<String>, c:Array<String>, cpp:Array<String>} {
42+
var defines = {main: [], c: [], cpp: []};
4343

4444
for (define in jsonFile.projectDefines) {
45-
defines.push("-D" + define);
45+
defines.main.push("-D" + define);
4646
}
4747

4848
for (lib in MainCompiler.libs) {
4949
for (define in lib.libJSONData.mainDefines) {
50-
defines.push("-D" + define);
50+
defines.main.push("-D" + define);
51+
}
52+
}
53+
54+
for (lib in MainCompiler.libs) {
55+
for (define in lib.libJSONData.cDefines) {
56+
defines.c.push(define);
57+
}
58+
}
59+
60+
for (lib in MainCompiler.libs) {
61+
for (define in lib.libJSONData.cppDefines) {
62+
defines.cpp.push(define);
5163
}
5264
}
5365

src/utils/LibsManager.hx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ typedef HxCULibJSONStruct = {
1919
libVersion:String,
2020
// Haxe things
2121
haxeLibs:Array<String>,
22-
// WiiU things
22+
// Wii U things
2323
wiiuLibs:Array<String>,
2424
// Other things
2525
mainDefines:Array<String>,
26+
// MakeFile things
27+
cDefines:Array<String>,
28+
cppDefines:Array<String>
2629
}
2730

2831
/**
@@ -107,6 +110,8 @@ class LibsManager {
107110
haxeLibs: jsonContent.haxeLibs,
108111
wiiuLibs: jsonContent.wiiuLibs,
109112
mainDefines: jsonContent.mainDefines,
113+
cDefines: jsonContent.cDefines,
114+
cppDefines: jsonContent.cppDefines
110115
},
111116
hxLibName: libName,
112117
});

templates/makefileSimpleAppWUT

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ ROMFS := romfs
3535
CFLAGS := -g -Wall -O2 -ffunction-sections \
3636
$(MACHDEP)
3737

38-
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ [DEFINES]
38+
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ [C_DEFINES]
3939

40-
CXXFLAGS := $(CFLAGS) -std=c++17 -Wno-unused-function -Wno-unused-variable -Wno-sequence-point -Wunused-but-set-variable -Wreturn-type
40+
CXXFLAGS := $(CFLAGS) -std=c++17 -Wno-unused-function -Wno-unused-variable -Wno-sequence-point -Wunused-but-set-variable -Wreturn-type [CPP_DEFINES]
4141

4242
ASFLAGS := -g $(MACHDEP)
4343
LDFLAGS := -g $(MACHDEP) $(RPXSPECS) -Wl,-Map,$(notdir $*.map)

0 commit comments

Comments
 (0)