AndroidTools::AndroidTools(Builder &builder, const Architecture &arch):
+ Toolchain("android-gnu", get_priority(arch)),
sdk(builder),
ndk(builder, arch, sdk)
{
add_tool(new ApkBuilder(builder));
add_tool(new JarSigner(builder));
}
+
+int AndroidTools::get_priority(const Architecture &arch)
+{
+ if(arch.get_system()=="android")
+ return 30;
+ else
+ return -10;
+}
public:
AndroidTools(Builder &, const Architecture &);
+
+ static int get_priority(const Architecture &);
};
#endif
native = true;
}
- if(toolchain.empty())
- {
- if((system=="darwin" || system=="freebsd") && builder.get_vfs().find_binary("clang"))
- toolchain = "clang";
- else if(system=="windows" && native)
- toolchain = "msvc";
- else
- toolchain = "gnu";
- }
-
update();
}
name += format("-%s", cpu);
if(!fpu.empty())
name += format("-%s", fpu);
- name += format("-%d-%s-%s", bits, system, toolchain);
+ name += format("-%d-%s", bits, system);
+ if(!toolchain.empty())
+ name += format("-%s", toolchain);
filename_patterns.clear();
if(system=="windows")
#include <deque>
#include <set>
+#include <msp/core/algorithm.h>
#include <msp/core/except.h>
#include <msp/core/maputils.h>
#include <msp/datafile/parser.h>
void Builder::add_default_tools()
{
- const string &arch_tc = current_arch->get_toolchain();
+ toolchain.add_toolchain(new GnuTools(*this, *current_arch));
+ toolchain.add_toolchain(new ClangTools(*this, *current_arch));
if(current_arch->get_system()=="android")
toolchain.add_toolchain(new AndroidTools(*this, *current_arch));
- else if(arch_tc=="msvc")
+ if(current_arch->get_system()=="windows")
toolchain.add_toolchain(new MicrosoftTools(*this, *current_arch));
- else if(arch_tc=="clang")
- toolchain.add_toolchain(new ClangTools(*this, *current_arch));
- else if(arch_tc=="gnu")
- toolchain.add_toolchain(new GnuTools(*this, *current_arch));
toolchain.add_toolchain(new BuiltinTools(*this));
toolchain.add_tool(new DataTool(*this));
+
+ auto i = find_if(toolchain.get_toolchains(), [](const Toolchain *tc){ return (tc->has_tool("CC") || tc->has_tool("CXX")); });
+ if(i!=toolchain.get_toolchains().end())
+ current_arch->refine((*i)->get_name());
}
void Builder::set_logger(const Logger *l)
using namespace std;
-ClangTools::ClangTools(Builder &builder, const Architecture &arch)
+ClangTools::ClangTools(Builder &builder, const Architecture &arch):
+ Toolchain("clang", get_priority(arch))
{
add_tool(new ClangCompiler(builder, arch, "CC"));
add_tool(new ClangCompiler(builder, arch, "CXX"));
add_tool(new GnuLinker(builder, arch));
add_tool(new GnuArchiver(builder, arch));
}
+
+int ClangTools::get_priority(const Architecture &arch)
+{
+ if(arch.get_toolchain()=="clang")
+ return 20;
+ else if(arch.get_system()=="darwin" || arch.get_system()=="freebsd")
+ return 10;
+ else
+ return 0;
+}
{
public:
ClangTools(Builder &, const Architecture &);
+
+ static int get_priority(const Architecture &);
};
#endif
#include "gnutools.h"
#include "mingwdlltool.h"
-GnuTools::GnuTools(Builder &builder, const Architecture &arch)
+GnuTools::GnuTools(Builder &builder, const Architecture &arch):
+ Toolchain("gnu", get_priority(arch))
{
add_tool(new GnuCompiler(builder, arch, "CC"));
add_tool(new GnuCompiler(builder, arch, "CXX"));
if(arch.get_system()=="windows")
add_tool(new MingwDllTool(builder, arch));
}
+
+int GnuTools::get_priority(const Architecture &arch)
+{
+ if(arch.get_toolchain()=="gnu")
+ return 20;
+ else if(arch.get_system()=="linux")
+ return 10;
+ else
+ return 0;
+}
{
public:
GnuTools(Builder &, const Architecture &);
+
+ static int get_priority(const Architecture &);
};
#endif
using namespace std;
using namespace Msp;
-MicrosoftTools::MicrosoftTools(Builder &builder, const Architecture &arch)
+MicrosoftTools::MicrosoftTools(Builder &builder, const Architecture &arch):
+ Toolchain("msvc", get_priority(arch))
{
find_vc_bin_dir(builder, arch);
find_windows_sdk_dir(builder);
builder.get_logger().log("tools", "Windows SDK version %s found in %s", win_sdk_version, win_sdk_dir);
}
+
+int MicrosoftTools::get_priority(const Architecture &arch)
+{
+ if(arch.get_toolchain()=="msvc")
+ return 20;
+ else if(arch.get_system()=="windows")
+ return 10;
+ else
+ return 0;
+}
const Msp::FS::Path &get_vc_bin_dir() const { return vc_bin_dir; }
const Msp::FS::Path &get_windows_sdk_dir() const { return win_sdk_dir; }
const std::string &get_windows_sdk_version() const { return win_sdk_version; }
+
+ static int get_priority(const Architecture &);
};
#endif
-#include <algorithm>
+#include <msp/core/algorithm.h>
#include <msp/core/maputils.h>
#include "tool.h"
#include "toolchain.h"
void Toolchain::add_toolchain(Toolchain *chain)
{
- chains.push_back(chain);
+ auto i = upper_bound(chains, chain->get_priority(), [](int p, Toolchain *tc){ return p>tc->get_priority(); });
+ chains.insert(i, chain);
}
bool Toolchain::has_tool(const string &tag) const
class Toolchain
{
private:
+ std::string name;
+ int priority = 0;
std::map<std::string, Tool *> tools;
std::vector<Toolchain *> chains;
+protected:
+ Toolchain(const std::string &n, unsigned p): name(n), priority(p) { }
public:
+ Toolchain() = default;
~Toolchain();
+ const std::string &get_name() const { return name; }
+ int get_priority() const { return priority; }
void add_tool(Tool *);
void add_toolchain(Toolchain *);
bool has_tool(const std::string &) const;
Tool &get_tool(const std::string &) const;
Tool *get_tool_for_suffix(const std::string &, bool = false) const;
+ const std::vector<Toolchain *> &get_toolchains() { return chains; }
};
#endif