]> git.tdb.fi Git - builder.git/commitdiff
Move system-specific code to a separate file
authorMikko Rasa <tdb@tdb.fi>
Sat, 28 Aug 2021 13:00:12 +0000 (16:00 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 28 Aug 2021 13:06:44 +0000 (16:06 +0300)
source/architecture.cpp
source/sysutils.cpp [new file with mode: 0644]
source/sysutils.h [new file with mode: 0644]

index 63ec6ba3f3dc5da4f60bd814a592547c0c1c1d15..8bdd1bfe8fceef06070f91c6db73b20111e08b5d 100644 (file)
@@ -1,11 +1,9 @@
 #include <limits>
-#ifndef _WIN32
-#include <sys/utsname.h>
-#endif
 #include <msp/strings/format.h>
 #include <msp/strings/utils.h>
 #include "architecture.h"
 #include "builder.h"
+#include "sysutils.h"
 
 using namespace std;
 using namespace Msp;
@@ -95,18 +93,9 @@ Architecture::Architecture(Builder &b, const string &spec):
 {
        if(spec.empty())
        {
-#ifdef _WIN32
-               system = "windows";
-#else
-               utsname un;
-               if(uname(&un)==0)
-               {
-                       system = tolower(un.sysname);
-                       parse_specification(tolower(un.machine));
-                       // We really only want to set type for the default arch
-                       cpu.clear();
-               }
-#endif
+               parse_specification(get_system_type());
+               // We really only want to set type for the default arch
+               cpu.clear();
                bits = sizeof(void *)*numeric_limits<unsigned char>::digits;
                native = true;
        }
diff --git a/source/sysutils.cpp b/source/sysutils.cpp
new file mode 100644 (file)
index 0000000..6e1828c
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef _WIN32
+#include <sys/utsname.h>
+#endif
+#include <msp/strings/format.h>
+#include <msp/strings/utils.h>
+#include "sysutils.h"
+
+using namespace std;
+using namespace Msp;
+
+string get_system_type()
+{
+#ifdef _WIN32
+       return "windows";
+#else
+       utsname un;
+       if(uname(&un)==0)
+               return tolower(format("%s-%s", un.sysname, un.machine));
+#endif
+
+       return string();
+}
diff --git a/source/sysutils.h b/source/sysutils.h
new file mode 100644 (file)
index 0000000..c422b7f
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef SYSUTILS_H_
+#define SYSUTILS_H_
+
+#include <string>
+
+std::string get_system_type();
+
+#endif