Distro.h revision 344779
1311118Sdim//===--- Distro.h - Linux distribution detection support --------*- C++ -*-===// 2311118Sdim// 3311118Sdim// The LLVM Compiler Infrastructure 4311118Sdim// 5311118Sdim// This file is distributed under the University of Illinois Open Source 6311118Sdim// License. See LICENSE.TXT for details. 7311118Sdim// 8311118Sdim//===----------------------------------------------------------------------===// 9311118Sdim 10311118Sdim#ifndef LLVM_CLANG_DRIVER_DISTRO_H 11311118Sdim#define LLVM_CLANG_DRIVER_DISTRO_H 12311118Sdim 13344779Sdim#include "llvm/Support/VirtualFileSystem.h" 14311118Sdim 15311118Sdimnamespace clang { 16311118Sdimnamespace driver { 17311118Sdim 18311118Sdim/// Distro - Helper class for detecting and classifying Linux distributions. 19311118Sdim/// 20311118Sdim/// This class encapsulates the clang Linux distribution detection mechanism 21311118Sdim/// as well as helper functions that match the specific (versioned) results 22311118Sdim/// into wider distribution classes. 23311118Sdimclass Distro { 24311118Sdimpublic: 25311118Sdim enum DistroType { 26311118Sdim // NB: Releases of a particular Linux distro should be kept together 27311118Sdim // in this enum, because some tests are done by integer comparison against 28311118Sdim // the first and last known member in the family, e.g. IsRedHat(). 29327952Sdim AlpineLinux, 30311118Sdim ArchLinux, 31311118Sdim DebianLenny, 32311118Sdim DebianSqueeze, 33311118Sdim DebianWheezy, 34311118Sdim DebianJessie, 35311118Sdim DebianStretch, 36327952Sdim DebianBuster, 37311118Sdim Exherbo, 38311118Sdim RHEL5, 39311118Sdim RHEL6, 40311118Sdim RHEL7, 41311118Sdim Fedora, 42344779Sdim Gentoo, 43311118Sdim OpenSUSE, 44311118Sdim UbuntuHardy, 45311118Sdim UbuntuIntrepid, 46311118Sdim UbuntuJaunty, 47311118Sdim UbuntuKarmic, 48311118Sdim UbuntuLucid, 49311118Sdim UbuntuMaverick, 50311118Sdim UbuntuNatty, 51311118Sdim UbuntuOneiric, 52311118Sdim UbuntuPrecise, 53311118Sdim UbuntuQuantal, 54311118Sdim UbuntuRaring, 55311118Sdim UbuntuSaucy, 56311118Sdim UbuntuTrusty, 57311118Sdim UbuntuUtopic, 58311118Sdim UbuntuVivid, 59311118Sdim UbuntuWily, 60311118Sdim UbuntuXenial, 61311118Sdim UbuntuYakkety, 62311118Sdim UbuntuZesty, 63321369Sdim UbuntuArtful, 64327952Sdim UbuntuBionic, 65341825Sdim UbuntuCosmic, 66344779Sdim UbuntuDisco, 67311118Sdim UnknownDistro 68311118Sdim }; 69311118Sdim 70311118Sdimprivate: 71311118Sdim /// The distribution, possibly with specific version. 72311118Sdim DistroType DistroVal; 73311118Sdim 74311118Sdimpublic: 75311118Sdim /// @name Constructors 76311118Sdim /// @{ 77311118Sdim 78311118Sdim /// Default constructor leaves the distribution unknown. 79311118Sdim Distro() : DistroVal() {} 80311118Sdim 81311118Sdim /// Constructs a Distro type for specific distribution. 82311118Sdim Distro(DistroType D) : DistroVal(D) {} 83311118Sdim 84311118Sdim /// Detects the distribution using specified VFS. 85344779Sdim explicit Distro(llvm::vfs::FileSystem &VFS); 86311118Sdim 87311118Sdim bool operator==(const Distro &Other) const { 88311118Sdim return DistroVal == Other.DistroVal; 89311118Sdim } 90311118Sdim 91311118Sdim bool operator!=(const Distro &Other) const { 92311118Sdim return DistroVal != Other.DistroVal; 93311118Sdim } 94311118Sdim 95311118Sdim bool operator>=(const Distro &Other) const { 96311118Sdim return DistroVal >= Other.DistroVal; 97311118Sdim } 98311118Sdim 99311118Sdim bool operator<=(const Distro &Other) const { 100311118Sdim return DistroVal <= Other.DistroVal; 101311118Sdim } 102311118Sdim 103311118Sdim /// @} 104311118Sdim /// @name Convenience Predicates 105311118Sdim /// @{ 106311118Sdim 107311118Sdim bool IsRedhat() const { 108311118Sdim return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7); 109311118Sdim } 110311118Sdim 111311118Sdim bool IsOpenSUSE() const { 112311118Sdim return DistroVal == OpenSUSE; 113311118Sdim } 114311118Sdim 115311118Sdim bool IsDebian() const { 116327952Sdim return DistroVal >= DebianLenny && DistroVal <= DebianBuster; 117311118Sdim } 118311118Sdim 119311118Sdim bool IsUbuntu() const { 120344779Sdim return DistroVal >= UbuntuHardy && DistroVal <= UbuntuDisco; 121311118Sdim } 122321369Sdim 123327952Sdim bool IsAlpineLinux() const { 124327952Sdim return DistroVal == AlpineLinux; 125327952Sdim } 126327952Sdim 127344779Sdim bool IsGentoo() const { 128344779Sdim return DistroVal == Gentoo; 129344779Sdim } 130344779Sdim 131311118Sdim /// @} 132311118Sdim}; 133311118Sdim 134311118Sdim} // end namespace driver 135311118Sdim} // end namespace clang 136311118Sdim 137311118Sdim#endif 138