]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/lib/Support/Unix/Host.inc
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / contrib / llvm / lib / Support / Unix / Host.inc
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 //===----------------------------------------------------------------------===//
15 //=== WARNING: Implementation here must contain only generic UNIX code that
16 //===          is guaranteed to work on *all* UNIX variants.
17 //===----------------------------------------------------------------------===//
18
19 #include "llvm/Config/config.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "Unix.h"
22 #include <sys/utsname.h>
23 #include <cctype>
24 #include <string>
25 #include <cstdlib> // ::getenv
26
27 using namespace llvm;
28
29 static std::string getOSVersion() {
30   struct utsname info;
31
32   if (uname(&info))
33     return "";
34
35   return info.release;
36 }
37
38 std::string sys::getHostTriple() {
39 #ifdef __FreeBSD__
40   return LLVM_HOSTTRIPLE;
41 #else
42   // FIXME: Derive directly instead of relying on the autoconf generated
43   // variable.
44
45   StringRef HostTripleString(LLVM_HOSTTRIPLE);
46   std::pair<StringRef, StringRef> ArchSplit = HostTripleString.split('-');
47
48   // Normalize the arch, since the host triple may not actually match the host.
49   std::string Arch = ArchSplit.first;
50
51   std::string Triple(Arch);
52   Triple += '-';
53   Triple += ArchSplit.second;
54
55   // Force i<N>86 to i386.
56   if (Triple[0] == 'i' && isdigit(Triple[1]) &&
57       Triple[2] == '8' && Triple[3] == '6')
58     Triple[1] = '3';
59
60   // On darwin, we want to update the version to match that of the
61   // host.
62   std::string::size_type DarwinDashIdx = Triple.find("-darwin");
63   if (DarwinDashIdx != std::string::npos) {
64     Triple.resize(DarwinDashIdx + strlen("-darwin"));
65     Triple += getOSVersion();
66   }
67
68   return Triple;
69 #endif
70 }