From 8c0ca406b994ef2aa66f35c86e3eb087f5314364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20P=C3=B6chtrager?= Date: Wed, 24 Dec 2014 09:54:27 +0100 Subject: [PATCH] add OSXCROSS_GCC_NO_STATIC_RUNTIME option + cleanup --- CHANGELOG | 3 ++ README.md | 7 +++++ wrapper/programs/osxcross-conf.cpp | 0 wrapper/programs/osxcross-env.cpp | 9 +++--- wrapper/target.cpp | 49 ++++++++++++++++++------------ 5 files changed, 43 insertions(+), 25 deletions(-) mode change 100755 => 100644 README.md mode change 100755 => 100644 wrapper/programs/osxcross-conf.cpp diff --git a/CHANGELOG b/CHANGELOG index 285c424..dcc7c43 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,9 @@ changed: * updated cctools to 862 * updated ld64 to 241.9 +added: + * OSXCROSS_GCC_NO_STATIC_RUNTIME option (env) + /******************************* v0.8 *******************************/ changed: diff --git a/README.md b/README.md old mode 100755 new mode 100644 index e7a398c..e18e17a --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ That's it. See usage examples below. If you want to build GCC as well, then you can do this by running: `[GCC_VERSION=4.9.1] [ENABLE_FORTRAN=1] ./build_gcc.sh`. +\[A gfortran usage example can be found [here](https://github.com/tpoechtrager/osxcross/issues/28#issuecomment-67047134)] + But before you do this, make sure you have got the GCC build depedencies installed on your system. On debian like systems you can run: @@ -58,6 +60,11 @@ On debian like systems you can run: to install them. +ATTENTION: + +OSXCross links libgcc and libstdc++ statically by default (this affects `-oc-use-gcc-libs` too). +You can turn this behavior off with `OSXCROSS_GCC_NO_STATIC_RUNTIME=1` (env). + ### PACKAGING THE SDK: ### If you need a recent SDK, then you must do the SDK packaging on OS X. diff --git a/wrapper/programs/osxcross-conf.cpp b/wrapper/programs/osxcross-conf.cpp old mode 100755 new mode 100644 diff --git a/wrapper/programs/osxcross-env.cpp b/wrapper/programs/osxcross-env.cpp index 6ca6e6a..4076855 100644 --- a/wrapper/programs/osxcross-env.cpp +++ b/wrapper/programs/osxcross-env.cpp @@ -47,14 +47,13 @@ int env(int argc, char **argv) { const char *pp = p; - for (; *p; ++p) { + do { auto badChar = [&](const char *p) { std::cerr << desc << " should not contain '" << *p << "'" << std::endl; - const char *start = - p - std::min(static_cast(p - pp), static_cast(30)); + const char *start = p - std::min(p - pp, 30); - size_t len = std::min(strlen(start), static_cast(60)); + size_t len = std::min(strlen(start), 60); std::cerr << std::string(start, len) << std::endl; while (start++ != p) @@ -71,7 +70,7 @@ int env(int argc, char **argv) { badChar(p); return true; } - } + } while (*p && *++p); return false; }; diff --git a/wrapper/target.cpp b/wrapper/target.cpp index efac3bb..1d15e87 100644 --- a/wrapper/target.cpp +++ b/wrapper/target.cpp @@ -306,30 +306,45 @@ void Target::setupGCCLibs(Arch arch) { std::stringstream GCCLibSTDCXXPath; std::stringstream GCCLibPath; + const bool dynamic = !!getenv("OSXCROSS_GCC_NO_STATIC_RUNTIME"); + getSDKPath(SDKPath); - GCCLibSTDCXXPath << SDKPath << "/../../" << otriple << "/lib"; - GCCLibPath << SDKPath << "/../../lib/gcc/" << otriple << "/" - << gccversion.Str(); + GCCLibPath << SDKPath << "/../../lib/gcc/" + << otriple << "/" << gccversion.Str(); - auto addLib = [&](const std::stringstream &path, const char *lib) { - static std::stringstream tmp; - clear(tmp); - tmp << path.str() << "/lib" << lib << ".a"; - fargs.push_back(tmp.str()); - }; + GCCLibSTDCXXPath << SDKPath << "/../../" << otriple << "/lib"; switch (arch) { case Arch::i386: case Arch::i486: case Arch::i586: case Arch::i686: - GCCLibSTDCXXPath << "/" << getArchName(i386); GCCLibPath << "/" << getArchName(Arch::i386); + GCCLibSTDCXXPath << "/" << getArchName(i386); default: ; } + if (dynamic) { + fargs.push_back("-L"); + fargs.push_back(GCCLibPath.str()); + fargs.push_back("-L"); + fargs.push_back(GCCLibSTDCXXPath.str()); + } + + auto addLib = [&](const std::stringstream &path, const char *lib) { + if (dynamic) { + fargs.push_back("-l"); + fargs.push_back(lib); + } else { + static std::stringstream tmp; + clear(tmp); + tmp << path.str() << "/lib" << lib << ".a"; + fargs.push_back(tmp.str()); + } + }; + fargs.push_back("-Qunused-arguments"); addLib(GCCLibSTDCXXPath, "stdc++"); @@ -565,13 +580,11 @@ bool Target::setup() { } } - /* TODO: libgcc */ - - if (isCXX() && (/*!isCXX11orNewer() ||*/ isLibCXX())) { + if (isCXX() && isLibCXX()) { fargs.push_back("-nostdinc++"); fargs.push_back("-nodefaultlibs"); - if (haveSourceFile() && !isGCH()) { + if (!isGCH()) { std::string tmp; tmp = "-L"; @@ -584,17 +597,13 @@ bool Target::setup() { if (isLibCXX()) { fargs.push_back("-lc++"); fargs.push_back("-lc++abi"); - } else if (isLibSTDCXX()) { - // Hack: Use SDKs libstdc++ as long - // >= -std=c++11 is not given. - - fargs.push_back("-lstdc++"); } fargs.push_back(OSNum <= OSVersion(10, 4) ? "-lgcc_s.10.4" : "-lgcc_s.10.5"); } - } else if (!isLibCXX() /*&& isCXX11orNewer()*/ && !isGCH()) { + } else if (!isLibCXX() && !isGCH() && + !getenv("OSXCROSS_GCC_NO_STATIC_RUNTIME")) { fargs.push_back("-static-libgcc"); fargs.push_back("-static-libstdc++"); }