Host.inc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //===- llvm/Support/Unix/Host.inc -------------------------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the UNIX Host support.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //===----------------------------------------------------------------------===//
  14. //=== WARNING: Implementation here must contain only generic UNIX code that
  15. //=== is guaranteed to work on *all* UNIX variants.
  16. //===----------------------------------------------------------------------===//
  17. #include "Unix.h"
  18. #include "llvm/ADT/StringRef.h"
  19. #include "llvm/Config/config.h"
  20. #include <cctype>
  21. #include <string>
  22. #include <sys/utsname.h>
  23. using namespace llvm;
  24. static std::string getOSVersion() {
  25. struct utsname info;
  26. if (uname(&info))
  27. return "";
  28. return info.release;
  29. }
  30. std::string sys::getDefaultTargetTriple() {
  31. std::string TargetTripleString(LLVM_DEFAULT_TARGET_TRIPLE);
  32. // On darwin, we want to update the version to match that of the
  33. // target.
  34. std::string::size_type DarwinDashIdx = TargetTripleString.find("-darwin");
  35. if (DarwinDashIdx != std::string::npos) {
  36. TargetTripleString.resize(DarwinDashIdx + strlen("-darwin"));
  37. TargetTripleString += getOSVersion();
  38. }
  39. return Triple::normalize(TargetTripleString);
  40. }