1 //===- llvm/Support/Unix/Host.inc -------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the UNIX Host support.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 //=== WARNING: Implementation here must contain only generic UNIX code that
16 //=== is guaranteed to work on *all* UNIX variants.
17 //===----------------------------------------------------------------------===//
19 #include "llvm/Config/config.h"
20 #include "llvm/ADT/StringRef.h"
22 #include <sys/utsname.h>
28 static std::string getOSVersion() {
37 std::string sys::getHostTriple() {
38 // FIXME: Derive directly instead of relying on the autoconf generated
41 StringRef HostTripleString(LLVM_HOSTTRIPLE);
42 std::pair<StringRef, StringRef> ArchSplit = HostTripleString.split('-');
44 // Normalize the arch, since the host triple may not actually match the host.
45 std::string Arch = ArchSplit.first;
47 std::string Triple(Arch);
49 Triple += ArchSplit.second;
51 // Force i<N>86 to i386.
52 if (Triple[0] == 'i' && isdigit(Triple[1]) &&
53 Triple[2] == '8' && Triple[3] == '6')
56 // On darwin, we want to update the version to match that of the
58 std::string::size_type DarwinDashIdx = Triple.find("-darwin");
59 if (DarwinDashIdx != std::string::npos) {
60 Triple.resize(DarwinDashIdx + strlen("-darwin"));
61 Triple += getOSVersion();