| NAKAMURA Takumi | 3d238b4 | 2014-09-24 04:44:37 +0000 | [diff] [blame] | 1 | //===- llvm/Support/Unix/Host.inc -------------------------------*- C++ -*-===// | 
| Mikhail Glushenkov | a6435d4 | 2009-02-08 21:10:57 +0000 | [diff] [blame] | 2 | // | 
| Daniel Dunbar | e52e6bf | 2008-10-02 01:17:28 +0000 | [diff] [blame] | 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. | 
| Mikhail Glushenkov | a6435d4 | 2009-02-08 21:10:57 +0000 | [diff] [blame] | 7 | // | 
| Daniel Dunbar | e52e6bf | 2008-10-02 01:17:28 +0000 | [diff] [blame] | 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 |  | 
| Daniel Dunbar | e52e6bf | 2008-10-02 01:17:28 +0000 | [diff] [blame] | 19 | #include "Unix.h" | 
| Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringRef.h" | 
|  | 21 | #include "llvm/Config/config.h" | 
| Nick Lewycky | 0de20af | 2010-12-19 20:43:38 +0000 | [diff] [blame] | 22 | #include <cctype> | 
| Daniel Dunbar | e52e6bf | 2008-10-02 01:17:28 +0000 | [diff] [blame] | 23 | #include <string> | 
| Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 24 | #include <sys/utsname.h> | 
| Daniel Dunbar | e52e6bf | 2008-10-02 01:17:28 +0000 | [diff] [blame] | 25 |  | 
|  | 26 | using namespace llvm; | 
|  | 27 |  | 
| Daniel Dunbar | fb1a6eb | 2009-03-31 17:30:15 +0000 | [diff] [blame] | 28 | static std::string getOSVersion() { | 
| Daniel Dunbar | e52e6bf | 2008-10-02 01:17:28 +0000 | [diff] [blame] | 29 | struct utsname info; | 
|  | 30 |  | 
|  | 31 | if (uname(&info)) | 
|  | 32 | return ""; | 
|  | 33 |  | 
|  | 34 | return info.release; | 
|  | 35 | } | 
| Daniel Dunbar | fb1a6eb | 2009-03-31 17:30:15 +0000 | [diff] [blame] | 36 |  | 
| Sebastian Pop | 99ab273 | 2012-01-05 18:28:46 +0000 | [diff] [blame] | 37 | std::string sys::getDefaultTargetTriple() { | 
| Tim Northover | be0fda3 | 2015-02-12 15:12:13 +0000 | [diff] [blame] | 38 | std::string TargetTripleString(LLVM_DEFAULT_TARGET_TRIPLE); | 
| Daniel Dunbar | fb1a6eb | 2009-03-31 17:30:15 +0000 | [diff] [blame] | 39 |  | 
|  | 40 | // On darwin, we want to update the version to match that of the | 
| Sebastian Pop | 94441fb | 2011-11-01 21:32:20 +0000 | [diff] [blame] | 41 | // target. | 
| Tim Northover | be0fda3 | 2015-02-12 15:12:13 +0000 | [diff] [blame] | 42 | std::string::size_type DarwinDashIdx = TargetTripleString.find("-darwin"); | 
| Daniel Dunbar | fb1a6eb | 2009-03-31 17:30:15 +0000 | [diff] [blame] | 43 | if (DarwinDashIdx != std::string::npos) { | 
| Tim Northover | be0fda3 | 2015-02-12 15:12:13 +0000 | [diff] [blame] | 44 | TargetTripleString.resize(DarwinDashIdx + strlen("-darwin")); | 
|  | 45 | TargetTripleString += getOSVersion(); | 
| Daniel Dunbar | fb1a6eb | 2009-03-31 17:30:15 +0000 | [diff] [blame] | 46 | } | 
|  | 47 |  | 
| Tim Northover | be0fda3 | 2015-02-12 15:12:13 +0000 | [diff] [blame] | 48 | return Triple::normalize(TargetTripleString); | 
| Daniel Dunbar | fb1a6eb | 2009-03-31 17:30:15 +0000 | [diff] [blame] | 49 | } |