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