mirror of
https://github.com/Relintai/osxcross.git
synced 2025-02-08 02:55:56 +01:00
Wrapper: Avoid some string operations
This commit is contained in:
parent
a4e9a2aea8
commit
68cca0de16
@ -384,14 +384,18 @@ bool detectTarget(int argc, char **argv, Target &target) {
|
||||
return false;
|
||||
|
||||
target.target = std::string(cmd, p - cmd);
|
||||
target.compiler = getCompilerIdentifier(&p[1]);
|
||||
target.compilername = &p[1];
|
||||
|
||||
if (target.compilername == "cc")
|
||||
target.compilername = getDefaultCompiler();
|
||||
else if (target.compilername == "c++")
|
||||
target.compilername = getDefaultCXXCompiler();
|
||||
else if (auto *prog = program::getprog(target.compilername))
|
||||
if (target.compilername == "cc") {
|
||||
target.compiler = getDefaultCompilerIdentifier();
|
||||
target.compilername = getDefaultCompilerName();
|
||||
} else if (target.compilername == "c++") {
|
||||
target.compiler = getDefaultCXXCompilerIdentifier();
|
||||
target.compilername = getDefaultCXXCompilerName();
|
||||
} else if (auto *prog = program::getprog(target.compilername)) {
|
||||
(*prog)(argc, argv, target);
|
||||
}
|
||||
|
||||
if (target.target != getDefaultTarget())
|
||||
warn << "this wrapper was built for target "
|
||||
@ -414,8 +418,11 @@ bool detectTarget(int argc, char **argv, Target &target) {
|
||||
else
|
||||
return false;
|
||||
|
||||
if (const char *p = strchr(cmd, '-'))
|
||||
target.compilername = &cmd[p - cmd + 1];
|
||||
if (const char *p = strchr(cmd, '-')) {
|
||||
const char *compilername = &cmd[p - cmd + 1];
|
||||
target.compiler = getCompilerIdentifier(compilername);
|
||||
target.compilername = compilername;
|
||||
}
|
||||
|
||||
if (!commandopts::parse(argc, argv, target))
|
||||
return false;
|
||||
|
@ -43,7 +43,8 @@ namespace target {
|
||||
Target::Target()
|
||||
: vendor(getDefaultVendor()), SDK(getenv("OSXCROSS_SDKROOT")),
|
||||
arch(Arch::x86_64), target(getDefaultTarget()), stdlib(StdLib::unset),
|
||||
usegcclibs(), compilername(getDefaultCompiler()), language() {
|
||||
usegcclibs(), compiler(getDefaultCompilerIdentifier()),
|
||||
compilername(getDefaultCompilerName()), language() {
|
||||
if (!getExecutablePath(execpath, sizeof(execpath)))
|
||||
abort();
|
||||
|
||||
@ -242,6 +243,9 @@ bool Target::isLibCXX() const {
|
||||
bool Target::isLibSTDCXX() const { return stdlib == StdLib::libstdcxx; }
|
||||
|
||||
bool Target::isCXX() {
|
||||
if (isKnownCompiler())
|
||||
return (compiler == Compiler::CLANGXX || compiler == Compiler::GXX);
|
||||
|
||||
return endsWith(compilername, "++");
|
||||
}
|
||||
|
||||
@ -257,12 +261,15 @@ bool Target::isGCH() {
|
||||
|
||||
|
||||
bool Target::isClang() const {
|
||||
return !strncmp(getFileName(compilername.c_str()), "clang", 5);
|
||||
return (compiler == Compiler::CLANG || compiler == Compiler::CLANGXX);
|
||||
}
|
||||
|
||||
bool Target::isGCC() const {
|
||||
const char *c = getFileName(compilername.c_str());
|
||||
return (!strncmp(c, "gcc", 3) || !strncmp(c, "g++", 3));
|
||||
return (compiler == Compiler::GCC || compiler == Compiler::GXX);
|
||||
}
|
||||
|
||||
bool Target::isKnownCompiler() const {
|
||||
return compiler != Compiler::UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,8 +29,23 @@ using namespace tools;
|
||||
|
||||
constexpr const char *getDefaultVendor() { return "apple"; }
|
||||
constexpr const char *getDefaultTarget() { return OSXCROSS_TARGET; }
|
||||
constexpr const char *getDefaultCompiler() { return "clang"; }
|
||||
constexpr const char *getDefaultCXXCompiler() { return "clang++"; }
|
||||
|
||||
constexpr const char *getDefaultCompilerName() {
|
||||
return "clang";
|
||||
}
|
||||
|
||||
constexpr Compiler getDefaultCompilerIdentifier() {
|
||||
return Compiler::CLANG;
|
||||
}
|
||||
|
||||
constexpr const char *getDefaultCXXCompilerName() {
|
||||
return "clang++";
|
||||
}
|
||||
|
||||
constexpr Compiler getDefaultCXXCompilerIdentifier() {
|
||||
return Compiler::CLANGXX;
|
||||
}
|
||||
|
||||
constexpr const char *getLinkerVersion() { return OSXCROSS_LINKER_VERSION; }
|
||||
constexpr const char *getBuildDir() { return OSXCROSS_BUILD_DIR; }
|
||||
|
||||
@ -104,7 +119,7 @@ struct Target {
|
||||
bool isClang() const;
|
||||
bool isGCC() const;
|
||||
|
||||
bool isKnownCompiler() const { return isClang() || isGCC(); }
|
||||
bool isKnownCompiler() const;
|
||||
|
||||
const std::string &getDefaultTriple(std::string &triple) const;
|
||||
const std::string &getTriple() const { return triple; }
|
||||
@ -125,6 +140,7 @@ struct Target {
|
||||
ClangVersion clangversion;
|
||||
GCCVersion gccversion;
|
||||
bool usegcclibs;
|
||||
Compiler compiler;
|
||||
std::string compilerpath; // /usr/bin/clang | [...]/target/bin/*-gcc
|
||||
std::string compilername; // clang | gcc
|
||||
std::string compilerexecname; // clang | *-apple-darwin-gcc
|
||||
|
@ -343,6 +343,36 @@ static const auto &parseClangVersion = parseOSVersion;
|
||||
typedef OSVersion LLVMVersion;
|
||||
static const auto &parseLLVMVersion = parseOSVersion;
|
||||
|
||||
//
|
||||
// Compiler Identifier
|
||||
//
|
||||
|
||||
#undef Compiler
|
||||
#undef CLANG
|
||||
#undef CLANGXX
|
||||
#undef GCC
|
||||
#undef GXX
|
||||
|
||||
enum Compiler : int {
|
||||
CLANG,
|
||||
CLANGXX,
|
||||
GCC,
|
||||
GXX,
|
||||
UNKNOWN // Upper-case to avoid clash with "enum Arch"
|
||||
};
|
||||
|
||||
inline Compiler getCompilerIdentifier(const char *compilername) {
|
||||
if (!strncmp(compilername, "clang++", 7))
|
||||
return Compiler::CLANGXX;
|
||||
if (!strncmp(compilername, "clang", 5))
|
||||
return Compiler::CLANG;
|
||||
else if (!strncmp(compilername, "g++", 3))
|
||||
return Compiler::GXX;
|
||||
else if (!strncmp(compilername, "gcc", 3))
|
||||
return Compiler::GCC;
|
||||
return Compiler::UNKNOWN;
|
||||
}
|
||||
|
||||
//
|
||||
// Arch
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user