summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@petroules.com>2013-11-18 10:42:25 -0500
committerJake Petroules <jake.petroules@petroules.com>2013-11-19 16:56:26 +0100
commitc485150efa863fd4a244b7a223ec90734dbe6e04 (patch)
treed65d2c10512978df0705cb57960ea4ed4fa4f61b
parente32f9bf66f023669a748046fae9c6d030deef9a0 (diff)
downloadqbs-c485150efa863fd4a244b7a223ec90734dbe6e04.tar.gz
Centralize determination of endianness.
Change-Id: Ia99ed4de2a07fa8959301a50e41cdb0367de46ea Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
-rw-r--r--src/app/detect-toolchains/msvcprobe.cpp1
-rw-r--r--src/app/detect-toolchains/osxprobe.cpp6
-rw-r--r--src/app/detect-toolchains/probe.cpp13
-rw-r--r--src/lib/tools/hostosinfo.h24
4 files changed, 30 insertions, 14 deletions
diff --git a/src/app/detect-toolchains/msvcprobe.cpp b/src/app/detect-toolchains/msvcprobe.cpp
index fa42d9efd..fa7915d6b 100644
--- a/src/app/detect-toolchains/msvcprobe.cpp
+++ b/src/app/detect-toolchains/msvcprobe.cpp
@@ -77,6 +77,7 @@ static void addMSVCPlatform(Settings *settings, QList<Profile> &profiles, QStrin
p.setValue("qbs.toolchain", QStringList("msvc"));
p.setValue("cpp.windowsSDKPath", winSDKPath);
p.setValue("qbs.architecture", Internal::HostOsInfo::canonicalArchitecture(architecture));
+ p.setValue("qbs.endianness", Internal::HostOsInfo::defaultEndianness(architecture));
profiles << p;
}
diff --git a/src/app/detect-toolchains/osxprobe.cpp b/src/app/detect-toolchains/osxprobe.cpp
index 63ff00dae..7c38082fe 100644
--- a/src/app/detect-toolchains/osxprobe.cpp
+++ b/src/app/detect-toolchains/osxprobe.cpp
@@ -152,9 +152,7 @@ void OsxProbe::setArch(Profile *profile, const QString &pathToGcc, const QString
return;
}
- QString endianness, architecture;
- architecture = compilerTripletl.at(0);
- endianness = "little";
+ const QString architecture = compilerTripletl.at(0);
qbsInfo() << Tr::tr(" Toolchain %1 detected:\n"
" binary: %2\n"
@@ -162,7 +160,7 @@ void OsxProbe::setArch(Profile *profile, const QString &pathToGcc, const QString
" arch: %4").arg(profile->name(), pathToGcc, compilerTriplet,
architecture);
- profile->setValue("qbs.endianness", endianness);
+ profile->setValue("qbs.endianness", HostOsInfo::defaultEndianness(architecture));
profile->setValue("qbs.architecture", HostOsInfo::canonicalArchitecture(architecture));
}
diff --git a/src/app/detect-toolchains/probe.cpp b/src/app/detect-toolchains/probe.cpp
index e6b7bb239..fd85bb598 100644
--- a/src/app/detect-toolchains/probe.cpp
+++ b/src/app/detect-toolchains/probe.cpp
@@ -90,8 +90,6 @@ static void specific_probe(Settings *settings, QList<Profile> &profiles, QString
QString cross = QString::fromLocal8Bit(qgetenv("CROSS_COMPILE"));
QString pathToGcc;
- QString architecture;
- QString endianness;
if (ld.isEmpty())
ld = "ld";
@@ -132,12 +130,7 @@ static void specific_probe(Settings *settings, QList<Profile> &profiles, QString
return;
}
- architecture = compilerTripletl.at(0);
- if (architecture.contains("arm")) {
- endianness = "big";
- } else {
- endianness = "little";
- }
+ const QString architecture = compilerTripletl.at(0);
QStringList pathToGccL = pathToGcc.split('/');
QString compilerName = pathToGccL.takeLast().replace(cc, cxx);
@@ -157,7 +150,7 @@ static void specific_probe(Settings *settings, QList<Profile> &profiles, QString
profile.setValue("qbs.toolchain", toolchainTypes);
profile.setValue("qbs.architecture", HostOsInfo::canonicalArchitecture(architecture));
- profile.setValue("qbs.endianness", endianness);
+ profile.setValue("qbs.endianness", HostOsInfo::defaultEndianness(architecture));
if (compilerName.contains('-')) {
QStringList nl = compilerName.split('-');
@@ -218,7 +211,7 @@ static void mingwProbe(Settings *settings, QList<Profile> &profiles)
profile.setValue(QLatin1String("qbs.architecture"),
HostOsInfo::canonicalArchitecture(QString::fromLatin1(architecture)));
profile.setValue(QLatin1String("qbs.endianness"),
- QLatin1String("little"));
+ HostOsInfo::defaultEndianness(QString::fromLatin1(architecture)));
profiles << profile;
}
diff --git a/src/lib/tools/hostosinfo.h b/src/lib/tools/hostosinfo.h
index 5704886ad..898fa8b20 100644
--- a/src/lib/tools/hostosinfo.h
+++ b/src/lib/tools/hostosinfo.h
@@ -70,6 +70,7 @@ public:
static bool isOsxHost() { return hostOs() == HostOsOsx; }
static inline bool isAnyUnixHost();
static inline QString canonicalArchitecture(const QString &architecture);
+ static inline QString defaultEndianness(const QString &architecture);
static QString appendExecutableSuffix(const QString &executable)
{
@@ -166,6 +167,29 @@ QString HostOsInfo::canonicalArchitecture(const QString &architecture)
return architecture;
}
+QString HostOsInfo::defaultEndianness(const QString &architecture)
+{
+ const QString canonicalArch = canonicalArchitecture(architecture);
+
+ QStringList little = QStringList()
+ << QLatin1String("x86")
+ << QLatin1String("x86_64")
+ << QLatin1String("arm")
+ << QLatin1String("arm64");
+
+ if (little.contains(canonicalArch))
+ return QLatin1String("little");
+
+ QStringList big = QStringList()
+ << QLatin1String("ppc")
+ << QLatin1String("ppc64");
+
+ if (big.contains(canonicalArch))
+ return QLatin1String("big");
+
+ return QString();
+}
+
} // namespace Internal
} // namespace qbs