Distro.h revision 311118
1178172Simp//===--- Distro.h - Linux distribution detection support --------*- C++ -*-===// 2214903Sgonzo// 3178172Simp// The LLVM Compiler Infrastructure 4178172Simp// 5178172Simp// This file is distributed under the University of Illinois Open Source 6178172Simp// License. See LICENSE.TXT for details. 7178172Simp// 8214903Sgonzo//===----------------------------------------------------------------------===// 9178172Simp 10214903Sgonzo#ifndef LLVM_CLANG_DRIVER_DISTRO_H 11214903Sgonzo#define LLVM_CLANG_DRIVER_DISTRO_H 12214903Sgonzo 13214903Sgonzo#include "clang/Basic/VirtualFileSystem.h" 14178172Simp 15214903Sgonzonamespace clang { 16214903Sgonzonamespace driver { 17214903Sgonzo 18214903Sgonzo/// Distro - Helper class for detecting and classifying Linux distributions. 19214903Sgonzo/// 20214903Sgonzo/// This class encapsulates the clang Linux distribution detection mechanism 21214903Sgonzo/// as well as helper functions that match the specific (versioned) results 22214903Sgonzo/// into wider distribution classes. 23214903Sgonzoclass Distro { 24214903Sgonzopublic: 25178172Simp enum DistroType { 26178172Simp // NB: Releases of a particular Linux distro should be kept together 27178172Simp // in this enum, because some tests are done by integer comparison against 28178172Simp // the first and last known member in the family, e.g. IsRedHat(). 29178172Simp ArchLinux, 30221173Sattilio DebianLenny, 31221173Sattilio DebianSqueeze, 32214903Sgonzo DebianWheezy, 33214903Sgonzo DebianJessie, 34214903Sgonzo DebianStretch, 35214903Sgonzo Exherbo, 36214903Sgonzo RHEL5, 37214903Sgonzo RHEL6, 38214903Sgonzo RHEL7, 39214903Sgonzo Fedora, 40221173Sattilio OpenSUSE, 41221173Sattilio UbuntuHardy, 42221173Sattilio UbuntuIntrepid, 43214903Sgonzo UbuntuJaunty, 44214903Sgonzo UbuntuKarmic, 45214903Sgonzo UbuntuLucid, 46214903Sgonzo UbuntuMaverick, 47214903Sgonzo UbuntuNatty, 48214903Sgonzo UbuntuOneiric, 49214903Sgonzo UbuntuPrecise, 50214903Sgonzo UbuntuQuantal, 51214903Sgonzo UbuntuRaring, 52214903Sgonzo UbuntuSaucy, 53214903Sgonzo UbuntuTrusty, 54214903Sgonzo UbuntuUtopic, 55214903Sgonzo UbuntuVivid, 56214903Sgonzo UbuntuWily, 57214903Sgonzo UbuntuXenial, 58214903Sgonzo UbuntuYakkety, 59214903Sgonzo UbuntuZesty, 60178172Simp UnknownDistro 61214903Sgonzo }; 62214903Sgonzo 63214903Sgonzoprivate: 64214903Sgonzo /// The distribution, possibly with specific version. 65214903Sgonzo DistroType DistroVal; 66214903Sgonzo 67214903Sgonzopublic: 68214903Sgonzo /// @name Constructors 69214903Sgonzo /// @{ 70214903Sgonzo 71214903Sgonzo /// Default constructor leaves the distribution unknown. 72214903Sgonzo Distro() : DistroVal() {} 73214903Sgonzo 74214903Sgonzo /// Constructs a Distro type for specific distribution. 75214903Sgonzo Distro(DistroType D) : DistroVal(D) {} 76214903Sgonzo 77214903Sgonzo /// Detects the distribution using specified VFS. 78214903Sgonzo explicit Distro(clang::vfs::FileSystem& VFS); 79214903Sgonzo 80214903Sgonzo bool operator==(const Distro &Other) const { 81214903Sgonzo return DistroVal == Other.DistroVal; 82214903Sgonzo } 83214903Sgonzo 84214903Sgonzo bool operator!=(const Distro &Other) const { 85214903Sgonzo return DistroVal != Other.DistroVal; 86214903Sgonzo } 87214903Sgonzo 88214903Sgonzo bool operator>=(const Distro &Other) const { 89214903Sgonzo return DistroVal >= Other.DistroVal; 90214903Sgonzo } 91214903Sgonzo 92214903Sgonzo bool operator<=(const Distro &Other) const { 93214903Sgonzo return DistroVal <= Other.DistroVal; 94214903Sgonzo } 95214903Sgonzo 96214903Sgonzo /// @} 97214903Sgonzo /// @name Convenience Predicates 98214903Sgonzo /// @{ 99214903Sgonzo 100214903Sgonzo bool IsRedhat() const { 101214903Sgonzo return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7); 102214903Sgonzo } 103214903Sgonzo 104214903Sgonzo bool IsOpenSUSE() const { 105214903Sgonzo return DistroVal == OpenSUSE; 106214903Sgonzo } 107214903Sgonzo 108214903Sgonzo bool IsDebian() const { 109214903Sgonzo return DistroVal >= DebianLenny && DistroVal <= DebianStretch; 110214903Sgonzo } 111214903Sgonzo 112214903Sgonzo bool IsUbuntu() const { 113214903Sgonzo return DistroVal >= UbuntuHardy && DistroVal <= UbuntuZesty; 114214903Sgonzo } 115214903Sgonzo 116214903Sgonzo /// @} 117214903Sgonzo}; 118214903Sgonzo 119214903Sgonzo} // end namespace driver 120214903Sgonzo} // end namespace clang 121214903Sgonzo 122214903Sgonzo#endif 123214903Sgonzo