|
@@ -2,6 +2,7 @@ class Build {
|
|
|
|
|
|
var output : String;
|
|
|
var name : String;
|
|
|
+ var sourcesDir : String;
|
|
|
var targetDir : String;
|
|
|
var dataPath : String;
|
|
|
var config : {
|
|
@@ -17,17 +18,36 @@ class Build {
|
|
|
this.dataPath = dataPath;
|
|
|
var path = new haxe.io.Path(output);
|
|
|
this.name = path.file;
|
|
|
- this.targetDir = path.dir+"/";
|
|
|
+ this.sourcesDir = path.dir+"/";
|
|
|
+ this.targetDir = this.sourcesDir;
|
|
|
}
|
|
|
|
|
|
+ function log(message:String) {
|
|
|
+ if( config.defines.get("hlgen.silent") == null )
|
|
|
+ Sys.println(message);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public function run() {
|
|
|
var tpl = config.defines.get("hlgen.makefile");
|
|
|
if( tpl != null )
|
|
|
generateTemplates(tpl);
|
|
|
- if( config.defines.get("hlgen.silent") == null )
|
|
|
- Sys.println("Code generated in "+output+" automatic native compilation not yet implemented");
|
|
|
+ log('Code generated in $output');
|
|
|
+ switch tpl {
|
|
|
+ case "make":
|
|
|
+ Sys.command("make", ["-C", targetDir]);
|
|
|
+ case "hxcpp":
|
|
|
+ Sys.command("haxelib", ["--cwd", targetDir, "run", "hxcpp", "Build.xml"].concat(config.defines.exists("debug") ? ["-Ddebug"] : []));
|
|
|
+ case "vs2019", "vs2022":
|
|
|
+ Sys.command("make", ["-C", targetDir]);
|
|
|
+ case null:
|
|
|
+ var suggestion = (Sys.systemName() == "Windows") ? "vs2019" : "make";
|
|
|
+ log('Set -D hlgen.makefile=${suggestion} for automatic native compilation');
|
|
|
+ case unimplemented:
|
|
|
+ log('Automatic native compilation not yet implemented for $unimplemented');
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
function isAscii( bytes : haxe.io.Bytes ) {
|
|
|
// BOM CHECK
|
|
|
if( bytes.length > 3 && bytes.get(0) == 0xEF && bytes.get(1) == 0xBB && bytes.get(2) == 0xBF )
|
|
@@ -36,7 +56,7 @@ class Build {
|
|
|
var len = bytes.length;
|
|
|
while( i < len ) {
|
|
|
var c = bytes.get(i++);
|
|
|
- if( c == 0 || c >= 0x80 ) return false;
|
|
|
+ if( c == 0 || c >= 0x80 ) return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
@@ -45,22 +65,20 @@ class Build {
|
|
|
if( tpl == null || tpl == "1" )
|
|
|
tpl = "vs2015";
|
|
|
var srcDir = tpl;
|
|
|
- var targetDir = config.defines.get("hlgen.makefilepath");
|
|
|
var jumboBuild = config.defines.get("hlgen.makefile.jumbo");
|
|
|
var relDir = "";
|
|
|
- if( targetDir == null )
|
|
|
- targetDir = this.targetDir;
|
|
|
- else {
|
|
|
+ if( config.defines["hlgen.makefilepath"] != null ) {
|
|
|
+ targetDir = config.defines.get("hlgen.makefilepath");
|
|
|
if( !StringTools.endsWith(targetDir,"/") && !StringTools.endsWith(targetDir,"\\") )
|
|
|
targetDir += "/";
|
|
|
+ var sourcesAbs = sys.FileSystem.absolutePath(sourcesDir);
|
|
|
var targetAbs = sys.FileSystem.absolutePath(targetDir);
|
|
|
- var currentAbs = sys.FileSystem.absolutePath(this.targetDir);
|
|
|
- if( !StringTools.startsWith(currentAbs, targetAbs+"/") )
|
|
|
- relDir = currentAbs+"/"; // absolute
|
|
|
- else
|
|
|
- relDir = currentAbs.substr(targetAbs.length+1);
|
|
|
+ if( !StringTools.startsWith(sourcesAbs, targetAbs+"/") )
|
|
|
+ relDir = sourcesAbs+"/"; // absolute
|
|
|
+ else
|
|
|
+ relDir = sourcesAbs.substr(targetAbs.length+1);
|
|
|
relDir = relDir.split("\\").join("/");
|
|
|
- if( relDir != "" )
|
|
|
+ if( !(relDir == "" || StringTools.endsWith(relDir, "/")) )
|
|
|
relDir += "/";
|
|
|
}
|
|
|
if( !sys.FileSystem.exists(srcDir) ) {
|
|
@@ -76,7 +94,7 @@ class Build {
|
|
|
for( f in config.files )
|
|
|
if( StringTools.endsWith(f,".c") ) {
|
|
|
var h = f.substr(0,-2) + ".h";
|
|
|
- if( sys.FileSystem.exists(targetDir+h) )
|
|
|
+ if( sys.FileSystem.exists(sourcesDir+h) )
|
|
|
allFiles.push(h);
|
|
|
}
|
|
|
allFiles.sort(Reflect.compare);
|
|
@@ -98,7 +116,7 @@ class Build {
|
|
|
|
|
|
var directories = [for( k in directories.keys() ) { path : k }];
|
|
|
directories.sort(function(a,b) return Reflect.compare(a.path,b.path));
|
|
|
-
|
|
|
+
|
|
|
function genRec( path : String ) {
|
|
|
var dir = srcDir + "/" + path;
|
|
|
for( f in sys.FileSystem.readDirectory(dir) ) {
|
|
@@ -143,7 +161,7 @@ class Build {
|
|
|
return sha1.substr(0,8)+"-"+sha1.substr(8,4)+"-"+sha1.substr(12,4)+"-"+sha1.substr(16,4)+"-"+sha1.substr(20,12);
|
|
|
},
|
|
|
makePath : function(_,dir:String) {
|
|
|
- return dir == "" ? "./" : (StringTools.endsWith(dir,"/") || StringTools.endsWith(dir,"\\")) ? dir : dir + "/";
|
|
|
+ return dir == "" ? "." : (StringTools.endsWith(dir,"/") || StringTools.endsWith(dir,"\\")) ? dir : dir + "/";
|
|
|
},
|
|
|
upper : function(_,s:String) {
|
|
|
return s.charAt(0).toUpperCase() + s.substr(1);
|
|
@@ -172,7 +190,7 @@ class Run {
|
|
|
var originalPath = args.pop();
|
|
|
var haxelibPath = Sys.getCwd()+"/";
|
|
|
Sys.setCwd(originalPath);
|
|
|
-
|
|
|
+
|
|
|
switch( args.shift() ) {
|
|
|
case "build":
|
|
|
var output = args.shift();
|
|
@@ -183,11 +201,11 @@ class Run {
|
|
|
new Build(haxelibPath,output,config).run();
|
|
|
case "run":
|
|
|
var output = args.shift();
|
|
|
- if( StringTools.endsWith(output,".c") ) return;
|
|
|
+ if( StringTools.endsWith(output,".c") ) return;
|
|
|
Sys.command("hl "+output);
|
|
|
case cmd:
|
|
|
Sys.println("Unknown command "+cmd);
|
|
|
Sys.exit(1);
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|