blob: 457217125a2229a160cf71e7b13bdc44c012f4b4 [file] [log] [blame]
NAKAMURA Takumi3d238b42014-09-24 04:44:37 +00001//===- llvm/Support/Unix/Host.inc -------------------------------*- C++ -*-===//
Mikhail Glushenkova6435d42009-02-08 21:10:57 +00002//
Daniel Dunbare52e6bf2008-10-02 01:17:28 +00003// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Mikhail Glushenkova6435d42009-02-08 21:10:57 +00007//
Daniel Dunbare52e6bf2008-10-02 01:17:28 +00008//===----------------------------------------------------------------------===//
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
Daniel Dunbare52e6bf2008-10-02 01:17:28 +000019#include "Unix.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000020#include "llvm/ADT/StringRef.h"
21#include "llvm/Config/config.h"
Nick Lewycky0de20af2010-12-19 20:43:38 +000022#include <cctype>
Daniel Dunbare52e6bf2008-10-02 01:17:28 +000023#include <string>
Chandler Carruthd9903882015-01-14 11:23:27 +000024#include <sys/utsname.h>
Daniel Dunbare52e6bf2008-10-02 01:17:28 +000025
26using namespace llvm;
27
Daniel Dunbarfb1a6eb2009-03-31 17:30:15 +000028static std::string getOSVersion() {
Daniel Dunbare52e6bf2008-10-02 01:17:28 +000029 struct utsname info;
30
31 if (uname(&info))
32 return "";
33
34 return info.release;
35}
Daniel Dunbarfb1a6eb2009-03-31 17:30:15 +000036
Sebastian Pop99ab2732012-01-05 18:28:46 +000037std::string sys::getDefaultTargetTriple() {
Tim Northoverbe0fda32015-02-12 15:12:13 +000038 std::string TargetTripleString(LLVM_DEFAULT_TARGET_TRIPLE);
Daniel Dunbarfb1a6eb2009-03-31 17:30:15 +000039
40 // On darwin, we want to update the version to match that of the
Sebastian Pop94441fb2011-11-01 21:32:20 +000041 // target.
Tim Northoverbe0fda32015-02-12 15:12:13 +000042 std::string::size_type DarwinDashIdx = TargetTripleString.find("-darwin");
Daniel Dunbarfb1a6eb2009-03-31 17:30:15 +000043 if (DarwinDashIdx != std::string::npos) {
Tim Northoverbe0fda32015-02-12 15:12:13 +000044 TargetTripleString.resize(DarwinDashIdx + strlen("-darwin"));
45 TargetTripleString += getOSVersion();
Daniel Dunbarfb1a6eb2009-03-31 17:30:15 +000046 }
47
Tim Northoverbe0fda32015-02-12 15:12:13 +000048 return Triple::normalize(TargetTripleString);
Daniel Dunbarfb1a6eb2009-03-31 17:30:15 +000049}