public override bool Build(CompileMessages errors, bool forceRebuild)
{
if (!base.Build(errors, forceRebuild)) return false;
if (!CheckPluginsHaveSharedLibraries())
{
errors.Add(new CompileError("Could not build for Linux due to missing plugins."));
return false;
}
foreach (string fileName in Directory.GetFiles(Path.Combine(AGSEditor.OUTPUT_DIRECTORY, AGSEditor.DATA_OUTPUT_DIRECTORY)))
{
if ((!fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) &&
(!Path.GetFileName(fileName).Equals("winsetup.exe", StringComparison.OrdinalIgnoreCase)) &&
(!Path.GetFileName(fileName).Equals(AGSEditor.CONFIG_FILE_NAME, StringComparison.OrdinalIgnoreCase)))
{
Utilities.CreateHardLink(GetCompiledPath(LINUX_DATA_DIR, Path.GetFileName(fileName)), fileName, true);
}
}
// Update config file with current game parameters
Factory.AGSEditor.WriteConfigFile(GetCompiledPath(LINUX_DATA_DIR));
foreach (KeyValuePair<string, string> pair in GetRequiredLibraryPaths())
{
string fileName = pair.Value;
if (!fileName.EndsWith(pair.Key)) fileName = Path.Combine(fileName, pair.Key);
string folderName = null;
if ((!fileName.EndsWith("ags32")) && (!fileName.EndsWith("ags64")))
{
// the engine files belong in the LINUX_DATA_DIR, but the other libs
// should have lib32 or lib64 subdirectories as part of their name
folderName = Path.GetFileName(Path.GetDirectoryName(fileName).TrimEnd(Path.DirectorySeparatorChar));
}
Utilities.CreateHardLink(GetCompiledPath(LINUX_DATA_DIR, folderName, Path.GetFileName(fileName)),
fileName, true);
}
string linuxDataLib32Dir = GetCompiledPath(LINUX_DATA_DIR, LINUX_LIB32_DIR);
string linuxDataLib64Dir = GetCompiledPath(LINUX_DATA_DIR, LINUX_LIB64_DIR);
string editorLinuxDir = Path.Combine(Factory.AGSEditor.EditorDirectory, LINUX_DIR);
string editorLinuxLib32Dir = Path.Combine(editorLinuxDir, LINUX_LIB32_DIR);
string editorLinuxLib64Dir = Path.Combine(editorLinuxDir, LINUX_LIB64_DIR);
foreach (string soName in _plugins)
{
Utilities.CreateHardLink(Path.Combine(linuxDataLib32Dir, soName),
Path.Combine(editorLinuxLib32Dir, soName), true);
Utilities.CreateHardLink(Path.Combine(linuxDataLib64Dir, soName),
Path.Combine(editorLinuxLib64Dir, soName), true);
}
string scriptFileName = GetCompiledPath(Factory.AGSEditor.BaseGameFileName.Replace(" ", "")); // strip whitespace from script name
string scriptText =
@"#!/bin/sh
SCRIPTPATH=""$(dirname ""$(readlink -f $0)"")""
if test ""x$@"" = ""x-h"" -o ""x$@"" = ""x--help""
then
echo ""Usage:"" ""$(basename ""$(readlink -f $0)"")"" ""[<ags options>]""
echo """"
fi
if test $(uname -m) = x86_64
then" + GetSymLinkScriptForEachPlugin(true) +
@"
else" + GetSymLinkScriptForEachPlugin(false) +
@"
fi
";
scriptText = scriptText.Replace("\r\n", "\n"); // make sure script has UNIX line endings
FileStream stream = File.Create(scriptFileName);
byte[] bytes = Encoding.UTF8.GetBytes(scriptText);
stream.Write(bytes, 0, bytes.Length);
stream.Close();
return true;
}