#include "PS4CPU.h"
#include "CommonArgs.h"
+#include "clang/Config/config.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/DriverDiagnostic.h"
// SDK include or lib directories. This behavior could be changed if
// -Weverything or -Winvalid-or-nonexistent-directory options are passed.
// If -isysroot was passed, use that as the SDK base path.
- std::string PrefixDir;
if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
- PrefixDir = A->getValue();
- if (!llvm::sys::fs::exists(PrefixDir))
- D.Diag(clang::diag::warn_missing_sysroot) << PrefixDir;
+ SDKRootDir = A->getValue();
+ if (!llvm::sys::fs::exists(SDKRootDir))
+ D.Diag(clang::diag::warn_missing_sysroot) << SDKRootDir;
} else
- PrefixDir = std::string(SDKDir.str());
+ SDKRootDir = std::string(SDKDir.str());
- SmallString<512> SDKIncludeDir(PrefixDir);
+ SmallString<512> SDKIncludeDir(SDKRootDir);
llvm::sys::path::append(SDKIncludeDir, "target/include");
if (!Args.hasArg(options::OPT_nostdinc) &&
!Args.hasArg(options::OPT_nostdlibinc) &&
<< Twine(Platform, " system headers").str() << SDKIncludeDir;
}
- SmallString<512> SDKLibDir(SDKDir);
+ SmallString<512> SDKLibDir(SDKRootDir);
llvm::sys::path::append(SDKLibDir, "target/lib");
if (!Args.hasArg(options::OPT_nostdlib) &&
!Args.hasArg(options::OPT_nodefaultlibs) &&
getFilePaths().push_back(std::string(SDKLibDir.str()));
}
+void toolchains::PS4PS5Base::AddClangSystemIncludeArgs(
+ const ArgList &DriverArgs,
+ ArgStringList &CC1Args) const {
+ const Driver &D = getDriver();
+
+ if (DriverArgs.hasArg(options::OPT_nostdinc))
+ return;
+
+ if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+ SmallString<128> Dir(D.ResourceDir);
+ llvm::sys::path::append(Dir, "include");
+ addSystemInclude(DriverArgs, CC1Args, Dir.str());
+ }
+
+ if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+ return;
+
+ // Add dirs specified via 'configure --with-c-include-dirs'.
+ StringRef CIncludeDirs(C_INCLUDE_DIRS);
+ if (!CIncludeDirs.empty()) {
+ SmallVector<StringRef, 5> dirs;
+ CIncludeDirs.split(dirs, ":");
+ for (StringRef dir : dirs) {
+ StringRef Prefix =
+ llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : "";
+ addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
+ }
+ return;
+ }
+
+ addExternCSystemInclude(DriverArgs, CC1Args,
+ SDKRootDir + "/target/include");
+ addExternCSystemInclude(DriverArgs, CC1Args,
+ SDKRootDir + "/target/include_common");
+}
+
Tool *toolchains::PS4CPU::buildAssembler() const {
return new tools::PScpu::Assembler(*this);
}
const llvm::opt::ArgList &Args, StringRef Platform,
const char *EnvVar);
+ void
+ AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args) const override;
// No support for finding a C++ standard library yet.
void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override {
protected:
Tool *buildLinker() const override;
+
+private:
+ // We compute the SDK root dir in the ctor, and use it later.
+ std::string SDKRootDir;
};
// PS4-specific Toolchain class.
switch (os) {
case llvm::Triple::CloudABI:
case llvm::Triple::NaCl:
- case llvm::Triple::PS4:
- case llvm::Triple::PS5:
case llvm::Triple::ELFIAMCU:
break;
case llvm::Triple::Win32:
case llvm::Triple::NaCl:
case llvm::Triple::ELFIAMCU:
break;
- case llvm::Triple::PS4:
- case llvm::Triple::PS5: {
- // <isysroot> gets prepended later in AddPath().
- std::string BaseSDKPath;
- if (!HasSysroot) {
- const char *EnvVar = (os == llvm::Triple::PS4) ? "SCE_ORBIS_SDK_DIR"
- : "SCE_PROSPERO_SDK_DIR";
- const char *envValue = getenv(EnvVar);
- if (envValue)
- BaseSDKPath = envValue;
- else {
- // HSOpts.ResourceDir variable contains the location of Clang's
- // resource files.
- // Assuming that Clang is configured for PS4 without
- // --with-clang-resource-dir option, the location of Clang's resource
- // files is <SDK_DIR>/host_tools/lib/clang
- SmallString<128> P = StringRef(HSOpts.ResourceDir);
- llvm::sys::path::append(P, "../../..");
- BaseSDKPath = std::string(P.str());
- }
- }
- AddPath(BaseSDKPath + "/target/include", System, false);
- AddPath(BaseSDKPath + "/target/include_common", System, false);
- break;
- }
default:
AddPath("/usr/include", ExternCSystem, false);
break;
case llvm::Triple::FreeBSD:
case llvm::Triple::NetBSD:
case llvm::Triple::OpenBSD:
+ case llvm::Triple::PS4:
+ case llvm::Triple::PS5:
case llvm::Triple::Fuchsia:
case llvm::Triple::Hurd:
case llvm::Triple::Linux:
/// PS4 and PS5 use the same SDK layout, so use the same tree for both.
// RUN: env SCE_ORBIS_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target x86_64-scei-ps4 --sysroot="" -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4
// RUN: env SCE_PROSPERO_SDK_DIR=%S/Inputs/scei-ps4_tree %clang -target x86_64-sie-ps5 --sysroot="" -E -v %s 2>&1 | FileCheck %s --check-prefix=ENVPS4
-// ENVPS4: Inputs/scei-ps4_tree/target/include{{$}}
-// ENVPS4: Inputs/scei-ps4_tree/target/include_common{{$}}
+// ENVPS4: Inputs/scei-ps4_tree/target/include
+// ENVPS4: Inputs/scei-ps4_tree/target/include_common
// ENVPS4-NOT: /usr/include
// RUN: %clang -isysroot %S/Inputs/scei-ps4_tree -target x86_64-scei-ps4 -E -v %s 2>&1 | FileCheck %s --check-prefix=SYSROOTPS4
// RUN: %clang -isysroot %S/Inputs/scei-ps4_tree -target x86_64-sie-ps5 -E -v %s 2>&1 | FileCheck %s --check-prefix=SYSROOTPS4
// SYSROOTPS4: "{{[^"]*}}clang{{[^"]*}}"
-// SYSROOTPS4: Inputs/scei-ps4_tree/target/include{{$}}
-// SYSROOTPS4: Inputs/scei-ps4_tree/target/include_common{{$}}
+// SYSROOTPS4: Inputs/scei-ps4_tree/target/include
+// SYSROOTPS4: Inputs/scei-ps4_tree/target/include_common
// SYSROOTPS4-NOT: /usr/include