diff options
Diffstat (limited to 'libbutl/target-triplet.cxx')
-rw-r--r-- | libbutl/target-triplet.cxx | 113 |
1 files changed, 69 insertions, 44 deletions
diff --git a/libbutl/target-triplet.cxx b/libbutl/target-triplet.cxx index c2535b1..e28f119 100644 --- a/libbutl/target-triplet.cxx +++ b/libbutl/target-triplet.cxx @@ -1,33 +1,9 @@ // file : libbutl/target-triplet.cxx -*- C++ -*- // license : MIT; see accompanying LICENSE file -#ifndef __cpp_modules_ts -#include <libbutl/target-triplet.mxx> -#endif - -// C includes. - -#ifndef __cpp_lib_modules_ts -#include <string> -#include <ostream> +#include <libbutl/target-triplet.hxx> #include <stdexcept> // invalid_argument -#endif - -// Other includes. - -#ifdef __cpp_modules_ts -module butl.target_triplet; - -// Only imports additional to interface. -#ifdef __clang__ -#ifdef __cpp_lib_modules_ts -import std.core; -import std.io; -#endif -#endif - -#endif using namespace std; @@ -48,7 +24,12 @@ namespace butl if (f == 0 || f == string::npos) bad ("missing cpu"); - cpu.assign (s, 0, f); + // Canonicalize CPU. + // + if (s.compare (0, f, "arm64") == 0) + cpu = "aarch64"; + else + cpu.assign (s, 0, f); // If we have something in between, then the first component after CPU is // VENDOR. Unless it is a first component of two-component system, as in @@ -71,19 +52,15 @@ namespace butl if (l != p) bad ("too many components"); - - // Handle the none-* case here. - // - if (s.compare (l + 1, 5, "none-") == 0) - l += 5; } else { // See if this is one of the well-known non-vendors. // - if (s.compare (f, n, "linux") == 0 || - s.compare (f, n, "windows") == 0 || - s.compare (f, n, "kfreebsd") == 0) + if (s.compare (f, n, "linux") == 0 || + s.compare (f, n, "windows") == 0 || + s.compare (f, n, "kfreebsd") == 0 || + s.compare (f, n, "nto") == 0) { l = f - 1; n = 0; // No VENDOR. @@ -111,22 +88,38 @@ namespace butl if (system.front () == '-' || system.back () == '-') bad ("invalid os/kernel/abi"); + // Canonicalize SYSTEM. + // + if (system == "linux") + system = "linux-gnu"; // Per config.sub. + else if (system == "windows-gnu" && vendor == "w64") // Clang's innovation. + system = "mingw32"; + // Extract VERSION for some recognized systems. // string::size_type v (0); - if (system.compare (0, (v = 6), "darwin") == 0 || - system.compare (0, (v = 7), "freebsd") == 0 || - system.compare (0, (v = 7), "openbsd") == 0 || - system.compare (0, (v = 6), "netbsd") == 0 || - system.compare (0, (v = 7), "solaris") == 0 || - system.compare (0, (v = 3), "aix") == 0 || - system.compare (0, (v = 4), "hpux") == 0 || - system.compare (0, (v = 10), "win32-msvc") == 0 || - system.compare (0, (v = 12), "windows-msvc") == 0) + if (system.compare (0, (v = 6), "darwin") == 0 || + system.compare (0, (v = 7), "freebsd") == 0 || + system.compare (0, (v = 7), "openbsd") == 0 || + system.compare (0, (v = 6), "netbsd") == 0 || + system.compare (0, (v = 7), "solaris") == 0 || + system.compare (0, (v = 3), "aix") == 0 || + system.compare (0, (v = 4), "hpux") == 0 || + system.compare (0, (v = 10), "win32-msvc") == 0 || + system.compare (0, (v = 12), "windows-msvc") == 0 || + system.compare (0, (v = 7), "nto-qnx") == 0) { version.assign (system, v, string::npos); system.resize (system.size () - version.size ()); } + else if (vendor == "apple" && system.compare (0, 3, "ios") == 0) + { + // Handle iosNN[-...]. + // + string::size_type p (system.find ('-')); + version.assign (system, 3, p == string::npos ? p : p - 3); + system.erase (3, version.size ()); + } // Determine class for some recognized systems. // @@ -134,6 +127,8 @@ namespace butl class_ = "linux"; else if (vendor == "apple" && system == "darwin") class_ = "macos"; + else if (vendor == "apple" && system.compare (0, 3, "ios") == 0) + class_ = "ios"; else if (system == "freebsd" || system == "openbsd" || system == "netbsd") @@ -165,7 +160,37 @@ namespace butl if (!version.empty ()) { - r += version; + if (vendor == "apple" && system.compare (0, 3, "ios") == 0) + r.insert (r.size () - system.size () + 3, version); + else + r += version; + } + + return r; + } + + std::string target_triplet:: + representation () const + { + std::string r (cpu); + + { + if (!r.empty ()) r += '-'; + r += vendor.empty () ? "unknown" : vendor.c_str (); + } + + if (!system.empty ()) + { + if (!r.empty ()) r += '-'; + r += system; + } + + if (!version.empty ()) + { + if (vendor == "apple" && system.compare (0, 3, "ios") == 0) + r.insert (r.size () - system.size () + 3, version); + else + r += version; } return r; |