Mikhail Glushenkov | 24abe72 | 2009-02-08 21:10:57 +0000 | [diff] [blame] | 1 | //===- llvm/System/Unix/Host.inc -------------------------------*- C++ -*-===// |
| 2 | // |
Daniel Dunbar | f56039e | 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 | 24abe72 | 2009-02-08 21:10:57 +0000 | [diff] [blame] | 7 | // |
Daniel Dunbar | f56039e | 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 | |
| 19 | #include <llvm/Config/config.h> |
| 20 | #include "Unix.h" |
| 21 | #include <sys/utsname.h> |
| 22 | #include <string> |
| 23 | |
| 24 | using namespace llvm; |
| 25 | |
Daniel Dunbar | 6214577 | 2009-03-31 17:30:15 +0000 | [diff] [blame] | 26 | static std::string getOSVersion() { |
Daniel Dunbar | f56039e | 2008-10-02 01:17:28 +0000 | [diff] [blame] | 27 | struct utsname info; |
| 28 | |
| 29 | if (uname(&info)) |
| 30 | return ""; |
| 31 | |
| 32 | return info.release; |
| 33 | } |
Daniel Dunbar | 6214577 | 2009-03-31 17:30:15 +0000 | [diff] [blame] | 34 | |
| 35 | std::string sys::getHostTriple() { |
| 36 | // FIXME: Derive more directly instead of relying on the autoconf |
| 37 | // generated variable. |
| 38 | |
| 39 | std::string Triple = LLVM_HOSTTRIPLE; |
| 40 | |
| 41 | // Force i<N>86 to i386. |
| 42 | if (Triple[0] == 'i' && isdigit(Triple[1]) && |
| 43 | Triple[2] == '8' && Triple[3] == '6') |
| 44 | Triple[1] = '3'; |
| 45 | |
| 46 | // On darwin, we want to update the version to match that of the |
| 47 | // host. |
| 48 | std::string::size_type DarwinDashIdx = Triple.find("-darwin"); |
| 49 | if (DarwinDashIdx != std::string::npos) { |
| 50 | Triple.resize(DarwinDashIdx + strlen("-darwin")); |
| 51 | |
| 52 | // Only add the major part of the os version. |
| 53 | std::string Version = getOSVersion(); |
| 54 | Triple += Version.substr(0, Version.find('.')); |
| 55 | } |
| 56 | |
| 57 | return Triple; |
| 58 | } |