aboutsummaryrefslogtreecommitdiff
path: root/backend/ninja/Ninja.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backend/ninja/Ninja.cpp')
-rw-r--r--backend/ninja/Ninja.cpp107
1 files changed, 7 insertions, 100 deletions
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp
index 526fccb..d5bfc67 100644
--- a/backend/ninja/Ninja.cpp
+++ b/backend/ninja/Ninja.cpp
@@ -722,109 +722,14 @@ namespace backend
return result;
}
- static string getCompilerCExecutable(Compiler compiler)
- {
- char *cc = std::getenv("CC");
- if(cc)
- return cc;
-
- string result;
- switch(compiler)
- {
- case Compiler::GCC:
- result = "ccache cc";
- break;
- case Compiler::MINGW_W64:
- result = "x86_64-w64-mingw32-cc";
- break;
- case Compiler::MSVC:
- result = "cl.exe";
- break;
- }
- return result;
- }
-
- static string getCompilerCppExecutable(Compiler compiler)
- {
- char *cxx = std::getenv("CXX");
- if(cxx)
- return cxx;
-
- string result;
- switch(compiler)
- {
- case Compiler::GCC:
- result = "ccache c++";
- break;
- case Compiler::MINGW_W64:
- result = "x86_64-w64-mingw32-c++";
- break;
- case Compiler::MSVC:
- result = "cl.exe";
- break;
- }
- return result;
- }
-
- static string getCompilerLinker(Compiler compiler)
- {
- char *ar = std::getenv("AR");
- if(ar)
- return ar;
-
- string result;
- switch(compiler)
- {
- case Compiler::GCC:
- result = "ar";
- break;
- case Compiler::MINGW_W64:
- result = "x86_64-w64-mingw32-ar";
- break;
- case Compiler::MSVC:
- result = "lib.exe";
- break;
- }
- return result;
- }
-
- enum class RuntimeCompilerType
- {
- NONE,
- OTHER,
- CLANG,
- EMSCRIPTEN
- };
-
Result<bool> Ninja::build(const SibsConfig &config, const _tinydir_char_t *savePath, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallback, GlobalIncludeDirCallbackFunc globalIncludeDirCallback)
{
- string cCompilerName = getCompilerCExecutable(config.getCompiler());
- string cppCompilerName = getCompilerCppExecutable(config.getCompiler());
- string compilerLinker = getCompilerLinker(config.getCompiler());
-
- RuntimeCompilerType cCompilerType = RuntimeCompilerType::NONE;
- Result<ExecResult> cCompilerVersion = exec(toFileString(cCompilerName) + TINYDIR_STRING(" --version"));
- if(cCompilerVersion && cCompilerVersion.unwrap().exitCode == 0)
- {
- if(cCompilerVersion.unwrap().execStdout.find("Emscripten") != string::npos)
- cCompilerType = RuntimeCompilerType::EMSCRIPTEN;
- else if(cCompilerVersion.unwrap().execStdout.find("clang") != string::npos)
- cCompilerType = RuntimeCompilerType::CLANG;
- else
- cCompilerType = RuntimeCompilerType::OTHER;
- }
+ string cCompilerName = BackendUtils::getCompilerCExecutable(config.getCompiler());
+ string cppCompilerName = BackendUtils::getCompilerCppExecutable(config.getCompiler());
+ string compilerLinker = BackendUtils::getCompilerLinker(config.getCompiler());
- RuntimeCompilerType cppCompilerType = RuntimeCompilerType::NONE;
- Result<ExecResult> cppCompilerVersion = exec(toFileString(cppCompilerName) + TINYDIR_STRING(" --version"));
- if(cppCompilerVersion && cppCompilerVersion.unwrap().exitCode == 0)
- {
- if(cppCompilerVersion.unwrap().execStdout.find("Emscripten") != string::npos)
- cppCompilerType = RuntimeCompilerType::EMSCRIPTEN;
- else if(cppCompilerVersion.unwrap().execStdout.find("clang") != string::npos)
- cppCompilerType = RuntimeCompilerType::CLANG;
- else
- cppCompilerType = RuntimeCompilerType::OTHER;
- }
+ RuntimeCompilerType cCompilerType = BackendUtils::getCCompilerType(config.getCompiler());
+ RuntimeCompilerType cppCompilerType = BackendUtils::getCppCompilerType(config.getCompiler());
if(cCompilerType != RuntimeCompilerType::NONE && cppCompilerType != RuntimeCompilerType::NONE && cCompilerType != cppCompilerType)
return Result<bool>::Err("The c and c++ compiler has to be of the same type");
@@ -1608,6 +1513,8 @@ namespace backend
const char *fileExtension = CONFIG_DYNAMIC_LIB_FILE_EXTENSION;
if(compilerType == RuntimeCompilerType::EMSCRIPTEN)
fileExtension = "wasm";
+ else if(config.getCompiler() == Compiler::MINGW_W64)
+ fileExtension = "dll";
generatedFile = "lib" + config.getPackageName() + "." + fileExtension;
break;
}