aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--butl/triplet16
-rw-r--r--butl/triplet.cxx15
-rw-r--r--tests/triplet/driver.cxx29
3 files changed, 44 insertions, 16 deletions
diff --git a/butl/triplet b/butl/triplet
index f61493d..44b5195 100644
--- a/butl/triplet
+++ b/butl/triplet
@@ -56,8 +56,8 @@ namespace butl
// strategy for (presumably less common) cases were we don't split things
// correctly.
//
- // Note also that the version splitting is only done for certain,
- // commonly-used targets.
+ // Note also that the version splitting is only done for certain commonly-
+ // used targets.
//
// Some examples of canonicalization and splitting:
//
@@ -75,6 +75,17 @@ namespace butl
// x86_64-linux-gnux32 x86_64 linux-gnux32
// x86_64-microsoft-win32-msvc14.0 x86_64 microsoft win32-msvc 14.0
//
+ // Similar to version splitting, for certain commonly-used targets we also
+ // derive the "target class" which can be used as a shorthand, more
+ // convenient way to identify a targets. If the target is not recognized,
+ // then the special 'other' value is used. Currently the following classes
+ // are recognized:
+ //
+ // linux *-*-linux-*
+ // macosx *-apple-darwin*
+ // freebsd *-*-freebsd*
+ // windows *-*-win32-* | *-*-mingw32
+ //
// References:
//
// 1. The libtool repository contains the PLATFORM file that lists many known
@@ -88,6 +99,7 @@ namespace butl
std::string vendor;
std::string system;
std::string version;
+ std::string class_;
// Parse the triplet optionally returning the canonicalized string. Throw
// std::invalid_argument if the triplet is not recognizable.
diff --git a/butl/triplet.cxx b/butl/triplet.cxx
index 8369539..39057a3 100644
--- a/butl/triplet.cxx
+++ b/butl/triplet.cxx
@@ -103,7 +103,7 @@ namespace butl
*c += system;
}
- // Finally, extract VERSION for some recognized systems.
+ // Extract VERSION for some recognized systems.
//
string::size_type v (0);
if (system.compare (0, (v = 6), "darwin") == 0 ||
@@ -118,5 +118,18 @@ namespace butl
version.assign (system, v, string::npos);
system.resize (system.size () - version.size ());
}
+
+ // Determine class for some recognized systems.
+ //
+ if (system.compare (0, 5, "linux") == 0)
+ class_ = "linux";
+ else if (vendor == "apple" && system == "darwin")
+ class_ = "macosx";
+ else if (system == "freebsd")
+ class_ = "freebsd";
+ else if (system.compare (0, 5, "win32") == 0 || system == "mingw32")
+ class_ = "windows";
+ else
+ class_ = "other";
}
}
diff --git a/tests/triplet/driver.cxx b/tests/triplet/driver.cxx
index fdd5939..51bb7e0 100644
--- a/tests/triplet/driver.cxx
+++ b/tests/triplet/driver.cxx
@@ -20,7 +20,8 @@ test (const char*,
const char* cpu,
const char* vendor,
const char* system,
- const char* version);
+ const char* version,
+ const char* class_ = "other");
int
main ()
@@ -49,31 +50,31 @@ main ()
assert (test ("arm-none-linux-gnueabi",
"arm-linux-gnueabi",
- "arm", "", "linux-gnueabi", ""));
+ "arm", "", "linux-gnueabi", "", "linux"));
assert (test ("arm-softfloat-linux-gnu",
"arm-softfloat-linux-gnu",
- "arm", "softfloat", "linux-gnu", ""));
+ "arm", "softfloat", "linux-gnu", "", "linux"));
assert (test ("i686-pc-mingw32",
"i686-mingw32",
- "i686", "", "mingw32", ""));
+ "i686", "", "mingw32", "", "windows"));
assert (test ("i686-w64-mingw32",
"i686-w64-mingw32",
- "i686", "w64", "mingw32", ""));
+ "i686", "w64", "mingw32", "", "windows"));
assert (test ("i686-lfs-linux-gnu",
"i686-lfs-linux-gnu",
- "i686", "lfs", "linux-gnu", ""));
+ "i686", "lfs", "linux-gnu", "", "linux"));
assert (test ("x86_64-unknown-linux-gnu",
"x86_64-linux-gnu",
- "x86_64", "", "linux-gnu", ""));
+ "x86_64", "", "linux-gnu", "", "linux"));
assert (test ("x86_64-linux-gnux32",
"x86_64-linux-gnux32",
- "x86_64", "", "linux-gnux32", ""));
+ "x86_64", "", "linux-gnux32", "", "linux"));
// Removal of none-.
//
@@ -89,11 +90,11 @@ main ()
//
assert (test ("x86_64-apple-darwin14.5.0",
"x86_64-apple-darwin14.5.0",
- "x86_64", "apple", "darwin", "14.5.0"));
+ "x86_64", "apple", "darwin", "14.5.0", "macosx"));
assert (test ("x86_64-unknown-freebsd10.2",
"x86_64-freebsd10.2",
- "x86_64", "", "freebsd", "10.2"));
+ "x86_64", "", "freebsd", "10.2", "freebsd"));
assert (test ("x86_64-pc-openbsd5.6",
"x86_64-openbsd5.6",
@@ -105,7 +106,7 @@ main ()
assert (test ("x86_64-microsoft-win32-msvc14.0",
"x86_64-microsoft-win32-msvc14.0",
- "x86_64", "microsoft", "win32-msvc", "14.0"));
+ "x86_64", "microsoft", "win32-msvc", "14.0", "windows"));
}
static bool
@@ -114,7 +115,8 @@ test (const char* s,
const char* cpu,
const char* vendor,
const char* system,
- const char* version)
+ const char* version,
+ const char* class_)
{
string c;
triplet t (s, c);
@@ -137,7 +139,8 @@ test (const char* s,
cmp (t.cpu, cpu, "cpu") &&
cmp (t.vendor, vendor, "vendor") &&
cmp (t.system, system, "system") &&
- cmp (t.version, version, "version");
+ cmp (t.version, version, "version") &&
+ cmp (t.class_, class_, "class");
}
static bool