// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
using System;
using System.IO;
namespace Flax.Build.Platforms
{
///
/// The Linux build platform implementation.
///
///
///
public class LinuxPlatform : UnixPlatform
{
///
public override TargetPlatform Target => TargetPlatform.Linux;
///
public override bool HasRequiredSDKsInstalled { get; }
///
public override bool HasSharedLibrarySupport => true;
///
/// The toolchain folder root.
///
public readonly string ToolchainRoot;
///
/// The compiler name.
///
public readonly string Compiler;
///
/// Initializes a new instance of the class.
///
public LinuxPlatform()
{
// Try to use system compiler
if (Platform.BuildTargetPlatform == TargetPlatform.Linux)
{
// Pick the newest compiler (overriden by specified in command line)
if (Which(Configuration.Compiler) != null)
Compiler = Configuration.Compiler;
else if (Which("clang++-10") != null)
Compiler = "clang++-10";
else if (Which("clang++-9") != null)
Compiler = "clang++-9";
else if (Which("clang++-8") != null)
Compiler = "clang++-8";
else if (Which("clang++-7") != null)
Compiler = "clang++-7";
else if (Which("clang++-6") != null)
Compiler = "clang++-6";
else if (Which("clang++") != null)
Compiler = "clang++";
}
if (Compiler != null)
{
// System compiler
ToolchainRoot = "/";
Log.Verbose($"Using native Linux toolchain (compiler {Compiler})");
HasRequiredSDKsInstalled = true;
}
else if (Platform.BuildTargetPlatform != TargetPlatform.Mac)
{
// Check if Linux toolchain is installed
string toolchainName = "v13_clang-7.0.1-centos7";
string toolchainsRoot = Environment.GetEnvironmentVariable("LINUX_TOOLCHAINS_ROOT");
if (string.IsNullOrEmpty(toolchainsRoot) || !Directory.Exists(Path.Combine(toolchainsRoot, toolchainName)))
{
if (string.IsNullOrEmpty(toolchainsRoot))
{
Log.Warning("Missing Linux Toolchain. Cannot build for Linux platform.");
}
return;
}
// Installed toolchain
ToolchainRoot = Path.Combine(toolchainsRoot, toolchainName).Replace('\\', '/');
Log.Verbose(string.Format("Found Linux Toolchain at {0}", ToolchainRoot));
HasRequiredSDKsInstalled = true;
}
}
///
protected override Toolchain CreateToolchain(TargetArchitecture architecture)
{
return new LinuxToolchain(this, architecture);
}
///
public override bool CanBuildPlatform(TargetPlatform platform)
{
switch (platform)
{
case TargetPlatform.Linux: return HasRequiredSDKsInstalled;
case TargetPlatform.Android: return AndroidSdk.Instance.IsValid && AndroidNdk.Instance.IsValid;
default: return false;
}
}
}
}