aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2022-02-05 22:06:27 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2022-02-09 12:23:03 +0000
commitc2f6f404ad3f12d38ba8ac799c5eb5b8fb146a02 (patch)
tree92b3e72058c8ca32f6f9071af27d4533de07e582
parenta4046a72a29e70abe482e8d35276721ace375997 (diff)
Add support for other platforms supported by Open Watcom
This patch adds support for the following target platforms: * DOS - both 32/16 bit. * OS/2 - both 32/16 bit. * Windows - 16 bit. Also all these platforms covered in CI tests. Change-Id: Ie75d9203c50f4d61546b19328992ff0e107d9942 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--.github/workflows/main.yml29
-rw-r--r--doc/reference/modules/qbs-module.qdoc9
-rwxr-xr-xscripts/install-ow.sh129
-rw-r--r--share/qbs/imports/qbs/Probes/WatcomProbe.qbs10
-rw-r--r--share/qbs/modules/cpp/watcom.js104
-rw-r--r--share/qbs/modules/cpp/watcom.qbs3
-rw-r--r--src/app/qbs-setup-toolchains/watcomprobe.cpp147
7 files changed, 259 insertions, 172 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 9bacd9898..df2fca11b 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -804,8 +804,33 @@ jobs:
matrix:
config:
- {
- name: 'Run Windows tests (OpenWatcom)',
- testProfile: 'watcom-2_0_0-x86',
+ name: 'Run Windows tests (OpenWatcom DOS 32 bit)',
+ testProfile: 'watcom-2_0_0-dos-x86',
+ script: './scripts/test-baremetal.sh',
+ }
+ - {
+ name: 'Run Windows tests (OpenWatcom DOS 16 bit)',
+ testProfile: 'watcom-2_0_0-dos-x86_16',
+ script: './scripts/test-baremetal.sh',
+ }
+ - {
+ name: 'Run Windows tests (OpenWatcom OS/2 32 bit)',
+ testProfile: 'watcom-2_0_0-os2-x86',
+ script: './scripts/test-baremetal.sh',
+ }
+ - {
+ name: 'Run Windows tests (OpenWatcom OS/2 16 bit)',
+ testProfile: 'watcom-2_0_0-os2-x86_16',
+ script: './scripts/test-baremetal.sh',
+ }
+ - {
+ name: 'Run Windows tests (OpenWatcom Windows 32 bit)',
+ testProfile: 'watcom-2_0_0-windows-x86',
+ script: './scripts/test-baremetal.sh',
+ }
+ - {
+ name: 'Run Windows tests (OpenWatcom Windows 16 bit)',
+ testProfile: 'watcom-2_0_0-windows-x86_16',
script: './scripts/test-baremetal.sh',
}
- {
diff --git a/doc/reference/modules/qbs-module.qdoc b/doc/reference/modules/qbs-module.qdoc
index 029f6f2cd..7ab8fd509 100644
--- a/doc/reference/modules/qbs-module.qdoc
+++ b/doc/reference/modules/qbs-module.qdoc
@@ -210,6 +210,9 @@
\li \c{"android"}
\li \c{["android", "linux", "unix"]}
\row
+ \li \c{"dos"}
+ \li \c{["dos"]}
+ \row
\li \c{"freebsd"}
\li \c{["freebsd", "bsd", "unix"]}
\row
@@ -246,6 +249,9 @@
\li \c{"openbsd"}
\li \c{["openbsd", "bsd", "unix"]}
\row
+ \li \c{"os2"}
+ \li \c{["os2"]}
+ \row
\li \c{"qnx"}
\li \c{["qnx", "unix"]}
\row
@@ -442,6 +448,9 @@
\li \c{"x86"}
\li 32-bit ISA architecture processor family developed by Intel
\row
+ \li \c{"x86_16"}
+ \li 16-bit ISA architecture processor family developed by Intel
+ \row
\li \c{"x86_64"}
\li 64-bit ISA architecture processor family developed by AMD
\row
diff --git a/scripts/install-ow.sh b/scripts/install-ow.sh
index 4c8784277..6b123fab8 100755
--- a/scripts/install-ow.sh
+++ b/scripts/install-ow.sh
@@ -44,7 +44,7 @@ function show_help() {
usage: install-ow [options] [components]
Examples
- ./install-ow.sh --platform win --architecture x64
+ ./install-ow.sh --version 2.0
Options
-d, --directory <directory>
@@ -52,50 +52,32 @@ Options
Maps to c:/watcom on Windows, /opt/watcom on Linux
by default.
- --platform <platform-os>
- The host platform. Can be one of linux, win. Auto-detected by default.
-
- --architecture <architecture-os>
- The host architecture. Can be one of x86, x64. Auto-detected by default.
-
--version <version>
- The desired toolchain version. Currently supported only
- 1.9 and 2.0 versions.
+ The desired toolchain version.
+ Currently supported only 2.0 version.
EOF
}
-VERSION=2.0 # Default latest version (a fork of original toolchain)..
-
-case "$OSTYPE" in
- *linux*)
- PLATFORM="linux"
- INSTALL_DIR="/opt/watcom"
- EXE_SUFFIX=
- ;;
- msys)
- PLATFORM="win"
- INSTALL_DIR="/c/watcom"
- EXE_SUFFIX=".exe"
- ;;
- *)
- PLATFORM=
- INSTALL_DIR=
- EXE_SUFFIX=
- ;;
-esac
-
-case "$HOSTTYPE" in
- x86_64)
- ARCHITECTURE="x64"
- ;;
- x86)
- ARCHITECTURE="x86"
- ;;
- *)
- ARCHITECTURE=
- ;;
-esac
+VERSION=2.0
+INSTALL_DIR=
+BIN_DIR=
+
+if [[ "$OSTYPE" =~ "linux" ]]; then
+ INSTALL_DIR="/opt/watcom"
+ if [[ "$HOSTTYPE" == "x86_64" ]]; then
+ BIN_DIR="binl64"
+ elif [[ "$HOSTTYPE" == "x86" ]]; then
+ BIN_DIR="binl"
+ fi
+elif [[ "$OSTYPE" == "msys" ]]; then
+ INSTALL_DIR="/c/watcom"
+ if [[ "$HOSTTYPE" == "x86_64" ]]; then
+ BIN_DIR="binnt64"
+ elif [[ "$HOSTTYPE" == "x86" ]]; then
+ BIN_DIR="binnt"
+ fi
+fi
while [ $# -gt 0 ]; do
case "$1" in
@@ -103,14 +85,6 @@ while [ $# -gt 0 ]; do
INSTALL_DIR="$2"
shift
;;
- --platform)
- PLATFORM="$2"
- shift
- ;;
- --architecture)
- ARCHITECTURE="$2"
- shift
- ;;
--version)
VERSION="$2"
shift
@@ -130,64 +104,25 @@ if [ -z "${INSTALL_DIR}" ]; then
exit 1
fi
-if [ -z "${PLATFORM}" ]; then
- echo "No --platform specified or auto-detection failed." >&2
- exit 1
-fi
-
-if [ -z "${ARCHITECTURE}" ]; then
- echo "No --architecture specified or auto-detection failed." >&2
- exit 1
-fi
-
if [ -z "${VERSION}" ]; then
echo "No --version specified." >&2
exit 1
fi
-DOWNLOAD_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'ow-installer'`
-
-BASE_URL_PREFIX="https://github.com/open-watcom/open-watcom-"
+DOWNLOAD_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'ow-tmp'`
-if [[ "${VERSION}" == "1.9" ]]; then
- # Original old OW v1.9 release supports only the 32-bit packages!
- if [[ "${PLATFORM}" =~ "linux" ]]; then
- BIN_DIR="binl"
- HOST="linux"
- elif [[ "${PLATFORM}" =~ "win" ]]; then
- HOST="win32"
- BIN_DIR="binnt"
- fi
- URL="${BASE_URL_PREFIX}${VERSION}/releases/download/ow1.9/open-watcom-c-${HOST}-1.9${EXE_SUFFIX}"
-else
- if [[ "${PLATFORM}" =~ "linux" ]]; then
- if [[ "${ARCHITECTURE}" =~ "x86" ]]; then
- BIN_DIR="binl"
- elif [[ "${ARCHITECTURE}" =~ "x64" ]]; then
- BIN_DIR="binl"
- fi
- elif [[ "${PLATFORM}" =~ "win" ]]; then
- if [[ "${ARCHITECTURE}" =~ "x86" ]]; then
- BIN_DIR="binnt"
- elif [[ "${ARCHITECTURE}" =~ "x64" ]]; then
- BIN_DIR="binnt64"
- fi
- fi
- # Default URL for the latest OW v2.0 fork.
- URL="${BASE_URL_PREFIX}v2/releases/download/Current-build/open-watcom-2_0-c-${PLATFORM}-${ARCHITECTURE}${EXE_SUFFIX}"
-fi
+VERSION_MAJOR=`echo $VERSION | cut -d. -f1`
+VERSION_MINOR=`echo $VERSION | cut -d. -f2`
-INSTALLER="${DOWNLOAD_DIR}/setup${EXE_SUFFIX}"
+OW_URL="https://github.com/open-watcom/open-watcom-v${VERSION_MAJOR}/releases/download/Current-build/ow-snapshot.tar.gz"
+OW_TARGZ="${DOWNLOAD_DIR}/ow.tar.gz"
-echo "Downloading from ${URL}..." >&2
-curl --progress-bar -L -o ${INSTALLER} ${URL} >&2
+echo "Downloading compiler from ${OW_URL}..." >&2
+curl --progress-bar -L -o ${OW_TARGZ} ${OW_URL} >&2
-echo "Installing to ${INSTALL_DIR}..." >&2
-if [[ "${PLATFORM}" =~ "linux" ]]; then
- chmod +777 ${INSTALLER}
-fi
+echo "Unpacking compiler to ${INSTALL_DIR}..." >&2
+7z x "${OW_TARGZ}" -so | 7z x -aoa -si -ttar -o"${INSTALL_DIR}" >/dev/null 2>&1
-${INSTALLER} -dDstDir=${INSTALL_DIR} -i -np -ns
echo "${INSTALL_DIR}/${BIN_DIR}"
-rm -f ${INSTALLER}
+rm -f ${OW_TARGZ}
diff --git a/share/qbs/imports/qbs/Probes/WatcomProbe.qbs b/share/qbs/imports/qbs/Probes/WatcomProbe.qbs
index 34be235b1..09511458f 100644
--- a/share/qbs/imports/qbs/Probes/WatcomProbe.qbs
+++ b/share/qbs/imports/qbs/Probes/WatcomProbe.qbs
@@ -29,6 +29,7 @@
****************************************************************************/
import qbs.File
+import qbs.Host
import qbs.ModUtils
import "../../../modules/cpp/watcom.js" as WATCOM
@@ -40,6 +41,7 @@ PathProbe {
property string _pathListSeparator
property string _toolchainInstallPath
property string _targetPlatform
+ property string _targetArchitecture
// Outputs
property string architecture
@@ -64,8 +66,8 @@ PathProbe {
if (!languages || languages.length === 0)
languages = ["c"];
- environment = WATCOM.guessEnvironment(_targetPlatform, _toolchainInstallPath,
- _pathListSeparator);
+ environment = WATCOM.guessEnvironment(Host.os(), _targetPlatform, _targetArchitecture,
+ _toolchainInstallPath, _pathListSeparator);
includePaths = environment["INCLUDE"].split(_pathListSeparator).filter(function(path) {
return File.exists(path);
@@ -73,7 +75,9 @@ PathProbe {
for (var i = 0; i < languages.length; ++i) {
var tag = languages[i];
- compilerDefinesByLanguage[tag] = WATCOM.dumpMacros(environment, compilerFilePath, tag);
+ compilerDefinesByLanguage[tag] = WATCOM.dumpMacros(
+ environment, compilerFilePath,
+ _targetPlatform, _targetArchitecture, tag);
}
var macros = compilerDefinesByLanguage["c"]
diff --git a/share/qbs/modules/cpp/watcom.js b/share/qbs/modules/cpp/watcom.js
index c186fe814..20ba2dbe3 100644
--- a/share/qbs/modules/cpp/watcom.js
+++ b/share/qbs/modules/cpp/watcom.js
@@ -40,13 +40,20 @@ var TextFile = require("qbs.TextFile");
var Utilities = require("qbs.Utilities");
function toolchainDetails(qbs) {
- var targetPlatform = qbs.targetPlatform;
+ var platform = qbs.targetPlatform;
var details = {};
- if (targetPlatform.contains("windows")) {
+ if (platform === "dos") {
+ details.imageFormat = "mz";
+ details.executableSuffix = ".exe";
+ } else if (platform === "os2") {
+ details.imageFormat = "pe";
+ details.executableSuffix = ".exe";
+ details.dynamicLibrarySuffix = ".dll";
+ } else if (platform === "windows") {
details.imageFormat = "pe";
details.executableSuffix = ".exe";
details.dynamicLibrarySuffix = ".dll";
- } else if (targetPlatform.contains("linux")) {
+ } else if (platform === "linux") {
details.imageFormat = "elf";
details.executableSuffix = "";
details.dynamicLibrarySuffix = ".so";
@@ -61,6 +68,31 @@ function languageFlag(tag) {
return "-xc++";
}
+function targetFlag(platform, architecture, type) {
+ if (platform === "dos") {
+ if (architecture === "x86_16")
+ return "-bdos";
+ else if (architecture === "x86")
+ return "-bdos4g";
+ } else if (platform === "os2") {
+ if (architecture === "x86_16")
+ return "-bos2";
+ else if (architecture === "x86")
+ return "-bos2v2";
+ } else if (platform === "windows") {
+ if (architecture === "x86_16")
+ return "-bwindows";
+ else if (architecture === "x86") {
+ if (type.contains("application"))
+ return "-bnt";
+ else if (type.contains("dynamiclibrary"))
+ return "-bnt_dll";
+ }
+ } else if (platform === "linux") {
+ return "-blinux";
+ }
+}
+
function guessVersion(macros) {
var version = parseInt(macros["__WATCOMC__"], 10)
|| parseInt(macros["__WATCOM_CPLUSPLUS__"], 10);
@@ -71,7 +103,8 @@ function guessVersion(macros) {
}
}
-function guessEnvironment(targetPlatform, toolchainInstallPath, pathListSeparator) {
+function guessEnvironment(hostOs, platform, architecture,
+ toolchainInstallPath, pathListSeparator) {
var toolchainRootPath = FileInfo.path(toolchainInstallPath);
if (!File.exists(toolchainRootPath)) {
throw "Unable to deduce environment due to compiler root directory: '"
@@ -95,23 +128,44 @@ function guessEnvironment(targetPlatform, toolchainInstallPath, pathListSeparato
setVariable("WATCOM", [toolchainRootPath], undefined, pathListSeparator);
setVariable("EDPATH", ["eddat"], toolchainRootPath, pathListSeparator);
- if (targetPlatform === "windows") {
- setVariable("WIPFC", ["wipfc"], toolchainRootPath, pathListSeparator);
- setVariable("PATH", ["binw", "binnt", "binnt64"], toolchainRootPath, pathListSeparator);
- setVariable("INCLUDE", ["h", "h/nt", "h/nt/directx", "h/nt/ddk"],
- toolchainRootPath, pathListSeparator);
- setVariable("WHTMLHELP", ["binnt/help"], toolchainRootPath, pathListSeparator);
- } else if (targetPlatform === "linux") {
+
+ if (hostOs.contains("linux"))
setVariable("PATH", ["binl64", "binl"], toolchainRootPath, pathListSeparator);
+ else if (hostOs.contains("windows"))
+ setVariable("PATH", ["binnt64", "binnt"], toolchainRootPath, pathListSeparator);
+
+ if (platform === "linux") {
setVariable("INCLUDE", ["lh"], toolchainRootPath, pathListSeparator);
} else {
- throw "Unable to deduce environment for unsupported target platform: '"
- + targetPlatform + "'";
+ // Common for DOS, Windows, OS/2.
+ setVariable("WIPFC", ["wipfc"], toolchainRootPath, pathListSeparator);
+ setVariable("WHTMLHELP", ["binnt/help"], toolchainRootPath, pathListSeparator);
+
+ var includes = ["h"];
+ if (platform === "dos") {
+ // Same includes as before.
+ } else if (platform === "os2") {
+ if (architecture === "x86")
+ includes = includes.concat(["h/os2"]);
+ else if (architecture === "x86_16")
+ includes = includes.concat(["h/os21x"]);
+ } else if (platform === "windows") {
+ if (architecture === "x86")
+ includes = includes.concat(["h/nt", "h/nt/directx", "h/nt/ddk"]);
+ else if (architecture === "x86_16")
+ includes = includes.concat(["h/win"]);
+ } else {
+ throw "Unable to deduce environment for unsupported target platform: '"
+ + platform + "'";
+ }
+
+ setVariable("INCLUDE", includes, toolchainRootPath, pathListSeparator);
}
+
return env;
}
-function dumpMacros(environment, compilerPath, tag) {
+function dumpMacros(environment, compilerPath, platform, architecture, tag) {
// Note: The Open Watcom compiler does not support the predefined
// macros dumping. So, we do it with the following trick, where we try
// to create and compile a special temporary file and to parse the console
@@ -178,7 +232,10 @@ function dumpMacros(environment, compilerPath, tag) {
for (var envkey in environment)
process.setEnv(envkey, environment[envkey]);
- var args = [ outputFilePath ].concat(languageFlag(tag));
+ var target = targetFlag(platform, architecture, ["application"]);
+ var lang = languageFlag(tag);
+ var args = [ target, lang, outputFilePath ];
+
process.exec(compilerPath, args, false);
var m = Cpp.extractMacros(process.readStdOut(), /"?(#define(\s\w+){1,2})"?$/);
if (tag === "cpp" && m["__cplusplus"] === "1")
@@ -249,9 +306,12 @@ function assemblerFlags(project, product, input, outputs, explicitlyDependsOn) {
function compilerFlags(project, product, input, outputs, explicitlyDependsOn) {
var args = ["-g" + (input.cpp.debugInformation ? "3" : "0")];
- var targetPlatform = product.qbs.targetPlatform;
+ var target = targetFlag(product.qbs.targetPlatform, product.qbs.architecture,
+ product.type);
+ args.push(target);
+
if (product.type.contains("application")) {
- if (targetPlatform === "windows") {
+ if (product.qbs.targetPlatform === "windows") {
var consoleApplication = product.consoleApplication;
args.push(consoleApplication ? "-mconsole" : "-mwindows");
}
@@ -358,18 +418,16 @@ function linkerFlags(project, product, inputs, outputs) {
var args = [];
var useCompilerDriver = useCompilerDriverLinker(product);
if (useCompilerDriver) {
- var targetPlatform = product.qbs.targetPlatform;
+ var target = targetFlag(product.qbs.targetPlatform, product.qbs.architecture,
+ product.type);
+ args.push(target);
+
if (product.type.contains("application")) {
- if (targetPlatform === "windows")
- args.push("-bnt")
- else if (targetPlatform === "linux")
- args.push("-blinux")
args.push("-o", FileInfo.toNativeSeparators(outputs.application[0].filePath));
if (product.cpp.generateLinkerMapFile)
args.push("-fm=" + FileInfo.toNativeSeparators(outputs.mem_map[0].filePath));
} else if (product.type.contains("dynamiclibrary")) {
if (targetPlatform === "windows") {
- args.push("-bnt_dll")
args.push("-Wl, option implib=" + FileInfo.toNativeSeparators(
outputs.dynamiclibrary_import[0].filePath));
}
diff --git a/share/qbs/modules/cpp/watcom.qbs b/share/qbs/modules/cpp/watcom.qbs
index d180b1455..eed63692c 100644
--- a/share/qbs/modules/cpp/watcom.qbs
+++ b/share/qbs/modules/cpp/watcom.qbs
@@ -53,6 +53,7 @@ CppModule {
_pathListSeparator: qbs.pathListSeparator
_toolchainInstallPath: toolchainInstallPath
_targetPlatform: qbs.targetPlatform
+ _targetArchitecture: qbs.architecture
}
qbs.architecture: watcomProbe.found ? watcomProbe.architecture : original
@@ -110,7 +111,7 @@ CppModule {
toolchainDetails: WATCOM.toolchainDetails(qbs)
- knownArchitectures: ["x86"]
+ knownArchitectures: ["x86", "x86_16"]
property var buildEnv: watcomProbe.environment
setupBuildEnvironment: {
diff --git a/src/app/qbs-setup-toolchains/watcomprobe.cpp b/src/app/qbs-setup-toolchains/watcomprobe.cpp
index 9765f7424..dd60a21a5 100644
--- a/src/app/qbs-setup-toolchains/watcomprobe.cpp
+++ b/src/app/qbs-setup-toolchains/watcomprobe.cpp
@@ -58,32 +58,64 @@ using namespace qbs;
using Internal::HostOsInfo;
using Internal::Tr;
+namespace {
+
+struct Details {
+ QStringView architecture;
+ QStringView platform;
+};
+
+constexpr struct Platform {
+ QStringView flag;
+ Details keys;
+ Details target;
+} knownPlatforms[] = {
+ // DOS 16/32 bit.
+ {u"-bdos", {u"__I86__", u"__DOS__"}, {u"x86_16", u"dos"}},
+ {u"-bdos4g", {u"__386__", u"__DOS__"}, {u"x86", u"dos"}},
+ // Windows 16/32 bit.
+ {u"-bwindows", {u"__I86__", u"__WINDOWS__"}, {u"x86_16", u"windows"}},
+ {u"-bnt", {u"__386__", u"__NT__"}, {u"x86", u"windows"}},
+ // OS/2 16/32 bit.
+ {u"-bos2", {u"__I86__", u"__OS2__"}, {u"x86_16", u"os2"}},
+ {u"-bos2v2", {u"__386__", u"__OS2__"}, {u"x86", u"os2"}},
+ // Linux 32 bit.
+ {u"-blinux", {u"__386__", u"__LINUX__"}, {u"x86", u"linux"}},
+};
+
+} // namespace
+
static QStringList knownWatcomCompilerNames()
{
return {QStringLiteral("owcc")};
}
-static QStringList dumpOutput(const QFileInfo &compiler, const QStringList &keys)
+static QStringList dumpOutput(const QFileInfo &compiler, QStringView flag,
+ const QList<QStringView> &keys)
{
const QString filePath = QDir(QDir::tempPath()).absoluteFilePath(
QLatin1String("watcom-dump.c"));
QFile fakeIn(filePath);
if (!fakeIn.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)) {
qbsWarning() << Tr::tr("Unable to open temporary file %1 for output: %2")
- .arg(fakeIn.fileName(), fakeIn.errorString());
- return QStringList{};
+ .arg(fakeIn.fileName(), fakeIn.errorString());
+ return {};
}
fakeIn.write("#define VALUE_TO_STRING(x) #x\n");
fakeIn.write("#define VALUE(x) VALUE_TO_STRING(x)\n");
fakeIn.write("#define VAR_NAME_VALUE(var) \"#define \" #var\" \"VALUE(var)\n");
- for (const QString &key : keys) {
+ for (const auto &key : keys) {
fakeIn.write("#if defined(" + key.toLatin1() + ")\n");
fakeIn.write("#pragma message (VAR_NAME_VALUE(" + key.toLatin1() + "))\n");
fakeIn.write("#endif\n");
}
fakeIn.close();
QProcess p;
- p.start(compiler.absoluteFilePath(), {QDir::toNativeSeparators(filePath)});
+ QStringList args;
+ if (!flag.isEmpty())
+ args.push_back(flag.toString());
+ args.push_back(QDir::toNativeSeparators(filePath));
+ p.start(compiler.absoluteFilePath(), std::move(args));
p.waitForFinished(3000);
fakeIn.remove();
const QStringList lines = QString::fromUtf8(p.readAllStandardOutput())
@@ -91,60 +123,80 @@ static QStringList dumpOutput(const QFileInfo &compiler, const QStringList &keys
return lines;
}
-static QString guessWatcomArchitecture(const QFileInfo &compiler)
+static bool supportsWatcomPlatform(const QFileInfo &compiler, const Platform &platform)
{
- const QStringList keys = {QStringLiteral("__I86__"), QStringLiteral("__386__")};
- const auto macros = dumpMacros([&compiler, &keys]() { return dumpOutput(compiler, keys); });
- for (auto index = 0; index < keys.count(); ++index) {
- const auto &key = keys.at(index);
- if (macros.contains(key) && macros.value(key) == QLatin1String("1")) {
- switch (index) {
- case 0:
- return QLatin1String("x86_16");
- case 1:
- return QLatin1String("x86");
- default:
- break;
- }
- }
- }
- return QLatin1String("unknown");
+ const auto macros = dumpMacros([&compiler, &platform]() {
+ const QList<QStringView> keys = {platform.keys.architecture, platform.keys.platform};
+ return dumpOutput(compiler, platform.flag, keys); });
+
+ auto matches = [&macros](QStringView key) {
+ const auto k = key.toString();
+ if (!macros.contains(k))
+ return false;
+ return macros.value(k) == QLatin1String("1");
+ };
+
+ return matches(platform.keys.architecture) && matches(platform.keys.platform);
}
-static Profile createWatcomProfileHelper(const ToolchainInstallInfo &info,
- Settings *settings,
- QString profileName = QString())
+static std::vector<Profile> createWatcomProfileHelper(const ToolchainInstallInfo &info,
+ Settings *settings,
+ const QString &profileName = QString())
{
const QFileInfo compiler = info.compilerPath;
- const QString architecture = guessWatcomArchitecture(compiler);
+ std::vector<Profile> profiles;
+
+ for (const auto &knownPlatform : knownPlatforms) {
+ // Don't create a profile in case the compiler does
+ // not support the proposed architecture.
+ if (!supportsWatcomPlatform(compiler, knownPlatform))
+ continue;
- // In case the profile is auto-detected.
- if (profileName.isEmpty()) {
- if (!info.compilerVersion.isValid()) {
- profileName = QStringLiteral("watcom-unknown-%1").arg(architecture);
+ QString fullProfilename;
+ if (profileName.isEmpty()) {
+ // Create a full profile name in case we is in auto-detecting mode.
+ if (!info.compilerVersion.isValid()) {
+ fullProfilename = QStringLiteral("watcom-unknown-%1-%2")
+ .arg(knownPlatform.target.platform)
+ .arg(knownPlatform.target.architecture);
+ } else {
+ const QString version= info.compilerVersion.toString(QLatin1Char('_'),
+ QLatin1Char('_'));
+ fullProfilename = QStringLiteral("watcom-%1-%2-%3")
+ .arg(version)
+ .arg(knownPlatform.target.platform)
+ .arg(knownPlatform.target.architecture);
+ }
} else {
- const QString version = info.compilerVersion.toString(QLatin1Char('_'),
- QLatin1Char('_'));
- profileName = QStringLiteral("watcom-%1-%2").arg(version, architecture);
+ // Append the detected actual architecture name to the proposed profile name.
+ fullProfilename = QStringLiteral("%1-%2-%3")
+ .arg(profileName)
+ .arg(knownPlatform.target.platform)
+ .arg(knownPlatform.target.architecture);
}
- }
- Profile profile(profileName, settings);
- profile.setValue(QStringLiteral("cpp.toolchainInstallPath"), compiler.absolutePath());
- profile.setValue(QStringLiteral("qbs.toolchainType"), QStringLiteral("watcom"));
- if (!architecture.isEmpty())
- profile.setValue(QStringLiteral("qbs.architecture"), architecture);
+ Profile profile(fullProfilename, settings);
+ profile.setValue(QStringLiteral("cpp.toolchainInstallPath"), compiler.absolutePath());
+ profile.setValue(QStringLiteral("qbs.toolchainType"), QStringLiteral("watcom"));
+ profile.setValue(QStringLiteral("qbs.architecture"),
+ knownPlatform.target.architecture.toString());
+ profile.setValue(QStringLiteral("qbs.targetPlatform"),
+ knownPlatform.target.platform.toString());
- qbsInfo() << Tr::tr("Profile '%1' created for '%2'.")
+ qbsInfo() << Tr::tr("Profile '%1' created for '%2'.")
.arg(profile.name(), compiler.absoluteFilePath());
- return profile;
+
+ profiles.push_back(std::move(profile));
+ }
+
+ return profiles;
}
static Version dumpWatcomVersion(const QFileInfo &compiler)
{
- const QStringList keys = {QStringLiteral("__WATCOMC__"),
- QStringLiteral("__WATCOM_CPLUSPLUS__")};
- const auto macros = dumpMacros([&compiler, &keys]() { return dumpOutput(compiler, keys); });
+ const QList<QStringView> keys = {u"__WATCOMC__", u"__WATCOM_CPLUSPLUS__"};
+ const auto macros = dumpMacros([&compiler, &keys]() {
+ return dumpOutput(compiler, u"", keys); });
for (const auto &macro : macros) {
const int verCode = macro.toInt();
return Version{(verCode - 1100) / 100,
@@ -195,6 +247,9 @@ void watcomProbe(Settings *settings, std::vector<Profile> &profiles)
return;
}
- qbs::Internal::transform(allInfos, profiles, [settings](const auto &info) {
- return createWatcomProfileHelper(info, settings); });
+ for (const ToolchainInstallInfo &info : allInfos) {
+ const auto newProfiles = createWatcomProfileHelper(info, settings);
+ profiles.reserve(profiles.size() + int(newProfiles.size()));
+ std::copy(newProfiles.cbegin(), newProfiles.cend(), std::back_inserter(profiles));
+ }
}