295 lines
7.3 KiB
Haxe
295 lines
7.3 KiB
Haxe
package platforms;
|
|
|
|
|
|
import haxe.io.Path;
|
|
import haxe.Template;
|
|
import helpers.AssetHelper;
|
|
import helpers.CPPHelper;
|
|
import helpers.FileHelper;
|
|
import helpers.IconHelper;
|
|
import helpers.NekoHelper;
|
|
import helpers.PathHelper;
|
|
import helpers.PlatformHelper;
|
|
import helpers.ProcessHelper;
|
|
import project.AssetType;
|
|
import project.Haxelib;
|
|
import project.HXProject;
|
|
import project.PlatformTarget;
|
|
import sys.io.File;
|
|
import sys.FileSystem;
|
|
|
|
|
|
class WindowsPlatform extends PlatformTarget {
|
|
|
|
|
|
private var applicationDirectory:String;
|
|
private var executablePath:String;
|
|
private var targetDirectory:String;
|
|
private var useNeko:Bool;
|
|
|
|
|
|
public function new (command:String, _project:HXProject, targetFlags:Map <String, String> ) {
|
|
|
|
super (command, _project, targetFlags);
|
|
|
|
targetDirectory = project.app.path + "/windows/cpp";
|
|
|
|
if (project.targetFlags.exists ("neko") || project.target != PlatformHelper.hostPlatform) {
|
|
|
|
targetDirectory = project.app.path + "/windows/neko";
|
|
useNeko = true;
|
|
|
|
}
|
|
|
|
applicationDirectory = targetDirectory + "/bin/";
|
|
executablePath = applicationDirectory + "/" + project.app.file + ".exe";
|
|
|
|
}
|
|
|
|
|
|
public override function build ():Void {
|
|
|
|
var type = "release";
|
|
|
|
if (project.debug) {
|
|
|
|
type = "debug";
|
|
|
|
} else if (project.targetFlags.exists ("final")) {
|
|
|
|
type = "final";
|
|
|
|
}
|
|
|
|
var hxml = targetDirectory + "/haxe/" + type + ".hxml";
|
|
|
|
PathHelper.mkdir (targetDirectory);
|
|
|
|
for (dependency in project.dependencies) {
|
|
|
|
if (StringTools.endsWith (dependency.path, ".dll")) {
|
|
|
|
var fileName = Path.withoutDirectory (dependency.path);
|
|
FileHelper.copyIfNewer (dependency.path, applicationDirectory + "/" + fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!project.targetFlags.exists ("static")) {
|
|
|
|
for (ndll in project.ndlls) {
|
|
|
|
FileHelper.copyLibrary (project, ndll, "Windows", "", (ndll.haxelib != null && (ndll.haxelib.name == "hxcpp" || ndll.haxelib.name == "hxlibc")) ? ".dll" : ".ndll", applicationDirectory, project.debug);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (useNeko) {
|
|
|
|
ProcessHelper.runCommand ("", "haxe", [ hxml ]);
|
|
NekoHelper.createExecutable (project.templatePaths, "windows", targetDirectory + "/obj/ApplicationMain.n", executablePath);
|
|
NekoHelper.copyLibraries (project.templatePaths, "windows", applicationDirectory);
|
|
|
|
} else {
|
|
|
|
var haxeArgs = [ hxml ];
|
|
var flags = [];
|
|
|
|
if (!project.environment.exists ("SHOW_CONSOLE")) {
|
|
|
|
haxeArgs.push ("-D");
|
|
haxeArgs.push ("no_console");
|
|
flags.push ("-Dno_console");
|
|
|
|
}
|
|
|
|
if (!project.targetFlags.exists ("static")) {
|
|
|
|
ProcessHelper.runCommand ("", "haxe", haxeArgs);
|
|
CPPHelper.compile (project, targetDirectory + "/obj", flags);
|
|
|
|
FileHelper.copyFile (targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-debug" : "") + ".exe", executablePath);
|
|
|
|
} else {
|
|
|
|
ProcessHelper.runCommand ("", "haxe", haxeArgs.concat ([ "-D", "static_link" ]));
|
|
CPPHelper.compile (project, targetDirectory + "/obj", flags.concat ([ "-Dstatic_link" ]));
|
|
CPPHelper.compile (project, targetDirectory + "/obj", flags, "BuildMain.xml");
|
|
|
|
FileHelper.copyFile (targetDirectory + "/obj/Main" + (project.debug ? "-debug" : "") + ".exe", executablePath);
|
|
|
|
}
|
|
|
|
var iconPath = PathHelper.combine (applicationDirectory, "icon.ico");
|
|
|
|
if (IconHelper.createWindowsIcon (project.icons, iconPath)) {
|
|
|
|
var templates = [ PathHelper.getHaxelib (new Haxelib ("lime")) + "/templates" ].concat (project.templatePaths);
|
|
ProcessHelper.runCommand ("", PathHelper.findTemplate (templates, "bin/ReplaceVistaIcon.exe"), [ executablePath, iconPath ], true, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public override function clean ():Void {
|
|
|
|
if (FileSystem.exists (targetDirectory)) {
|
|
|
|
PathHelper.removeDirectory (targetDirectory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public override function display ():Void {
|
|
|
|
var type = "release";
|
|
|
|
if (project.debug) {
|
|
|
|
type = "debug";
|
|
|
|
} else if (project.targetFlags.exists ("final")) {
|
|
|
|
type = "final";
|
|
|
|
}
|
|
|
|
var hxml = PathHelper.findTemplate (project.templatePaths, (useNeko ? "neko" : "cpp") + "/hxml/" + type + ".hxml");
|
|
var template = new Template (File.getContent (hxml));
|
|
Sys.println (template.execute (generateContext ()));
|
|
|
|
}
|
|
|
|
|
|
private function generateContext ():Dynamic {
|
|
|
|
var context = project.templateContext;
|
|
|
|
context.NEKO_FILE = targetDirectory + "/obj/ApplicationMain.n";
|
|
context.CPP_DIR = targetDirectory + "/obj";
|
|
context.BUILD_DIR = project.app.path + "/windows";
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
public override function rebuild ():Void {
|
|
|
|
if (project.environment.exists ("VS110COMNTOOLS") && project.environment.exists ("VS100COMNTOOLS")) {
|
|
|
|
project.environment.set ("HXCPP_MSVC", project.environment.get ("VS100COMNTOOLS"));
|
|
Sys.putEnv ("HXCPP_MSVC", project.environment.get ("VS100COMNTOOLS"));
|
|
|
|
}
|
|
|
|
CPPHelper.rebuild (project, [[ "-Dwindows" ]]);
|
|
|
|
}
|
|
|
|
|
|
public override function run ():Void {
|
|
|
|
var arguments = additionalArguments.copy ();
|
|
|
|
if (project.target == PlatformHelper.hostPlatform) {
|
|
|
|
arguments = arguments.concat ([ "-livereload" ]);
|
|
ProcessHelper.runCommand (applicationDirectory, Path.withoutDirectory (executablePath), arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public override function update ():Void {
|
|
|
|
project = project.clone ();
|
|
|
|
if (project.targetFlags.exists ("xml")) {
|
|
|
|
project.haxeflags.push ("-xml " + targetDirectory + "/types.xml");
|
|
|
|
}
|
|
|
|
var context = generateContext ();
|
|
|
|
if (project.targetFlags.exists ("static")) {
|
|
|
|
for (i in 0...project.ndlls.length) {
|
|
|
|
var ndll = project.ndlls[i];
|
|
|
|
if (ndll.path == null || ndll.path == "") {
|
|
|
|
context.ndlls[i].path = PathHelper.getLibraryPath (ndll, "Windows", "lib", ".lib", project.debug);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PathHelper.mkdir (targetDirectory);
|
|
PathHelper.mkdir (targetDirectory + "/obj");
|
|
PathHelper.mkdir (targetDirectory + "/haxe");
|
|
PathHelper.mkdir (applicationDirectory);
|
|
|
|
//SWFHelper.generateSWFClasses (project, targetDirectory + "/haxe");
|
|
|
|
FileHelper.recursiveCopyTemplate (project.templatePaths, "haxe", targetDirectory + "/haxe", context);
|
|
FileHelper.recursiveCopyTemplate (project.templatePaths, (useNeko ? "neko" : "cpp") + "/hxml", targetDirectory + "/haxe", context);
|
|
|
|
if (project.targetFlags.exists ("static")) {
|
|
|
|
FileHelper.recursiveCopyTemplate (project.templatePaths, "cpp/static", targetDirectory + "/obj", context);
|
|
|
|
}
|
|
|
|
/*if (IconHelper.createIcon (project.icons, 32, 32, PathHelper.combine (applicationDirectory, "icon.png"))) {
|
|
|
|
context.HAS_ICON = true;
|
|
context.WIN_ICON = "icon.png";
|
|
|
|
}*/
|
|
|
|
for (asset in project.assets) {
|
|
|
|
if (asset.embed != true) {
|
|
|
|
var path = PathHelper.combine (applicationDirectory, asset.targetPath);
|
|
|
|
if (asset.type != AssetType.TEMPLATE) {
|
|
|
|
PathHelper.mkdir (Path.directory (path));
|
|
FileHelper.copyAssetIfNewer (asset, path);
|
|
|
|
} else {
|
|
|
|
PathHelper.mkdir (Path.directory (path));
|
|
FileHelper.copyAsset (asset, path, context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AssetHelper.createManifest (project, PathHelper.combine (applicationDirectory, "manifest"));
|
|
|
|
}
|
|
|
|
|
|
@ignore public override function install ():Void {}
|
|
@ignore public override function trace ():Void {}
|
|
@ignore public override function uninstall ():Void {}
|
|
|
|
|
|
} |