1 //===--- Distro.h - Linux distribution detection support --------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_CLANG_DRIVER_DISTRO_H 10 #define LLVM_CLANG_DRIVER_DISTRO_H 11 12 #include "llvm/Support/VirtualFileSystem.h" 13 #include "llvm/TargetParser/Triple.h" 14 15 namespace clang { 16 namespace driver { 17 18 /// Distro - Helper class for detecting and classifying Linux distributions. 19 /// 20 /// This class encapsulates the clang Linux distribution detection mechanism 21 /// as well as helper functions that match the specific (versioned) results 22 /// into wider distribution classes. 23 class Distro { 24 public: 25 enum DistroType { 26 // Special value means that no detection was performed yet. 27 UninitializedDistro, 28 // NB: Releases of a particular Linux distro should be kept together 29 // in this enum, because some tests are done by integer comparison against 30 // the first and last known member in the family, e.g. IsRedHat(). 31 AlpineLinux, 32 ArchLinux, 33 DebianLenny, 34 DebianSqueeze, 35 DebianWheezy, 36 DebianJessie, 37 DebianStretch, 38 DebianBuster, 39 DebianBullseye, 40 DebianBookworm, 41 DebianTrixie, 42 DebianForky, 43 DebianDuke, 44 Exherbo, 45 RHEL5, 46 RHEL6, 47 RHEL7, 48 Fedora, 49 Gentoo, 50 OpenSUSE, 51 UbuntuHardy, 52 UbuntuIntrepid, 53 UbuntuJaunty, 54 UbuntuKarmic, 55 UbuntuLucid, 56 UbuntuMaverick, 57 UbuntuNatty, 58 UbuntuOneiric, 59 UbuntuPrecise, 60 UbuntuQuantal, 61 UbuntuRaring, 62 UbuntuSaucy, 63 UbuntuTrusty, 64 UbuntuUtopic, 65 UbuntuVivid, 66 UbuntuWily, 67 UbuntuXenial, 68 UbuntuYakkety, 69 UbuntuZesty, 70 UbuntuArtful, 71 UbuntuBionic, 72 UbuntuCosmic, 73 UbuntuDisco, 74 UbuntuEoan, 75 UbuntuFocal, 76 UbuntuGroovy, 77 UbuntuHirsute, 78 UbuntuImpish, 79 UbuntuJammy, 80 UbuntuKinetic, 81 UbuntuLunar, 82 UbuntuMantic, 83 UbuntuNoble, 84 UbuntuOracular, 85 UbuntuPlucky, 86 UbuntuQuesting, 87 UnknownDistro 88 }; 89 90 private: 91 /// The distribution, possibly with specific version. 92 DistroType DistroVal; 93 94 public: 95 /// @name Constructors 96 /// @{ 97 98 /// Default constructor leaves the distribution unknown. Distro()99 Distro() : DistroVal() {} 100 101 /// Constructs a Distro type for specific distribution. Distro(DistroType D)102 Distro(DistroType D) : DistroVal(D) {} 103 104 /// Detects the distribution using specified VFS. 105 explicit Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost); 106 107 bool operator==(const Distro &Other) const { 108 return DistroVal == Other.DistroVal; 109 } 110 111 bool operator!=(const Distro &Other) const { 112 return DistroVal != Other.DistroVal; 113 } 114 115 bool operator>=(const Distro &Other) const { 116 return DistroVal >= Other.DistroVal; 117 } 118 119 bool operator<=(const Distro &Other) const { 120 return DistroVal <= Other.DistroVal; 121 } 122 123 /// @} 124 /// @name Convenience Predicates 125 /// @{ 126 IsRedhat()127 bool IsRedhat() const { 128 return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7); 129 } 130 IsOpenSUSE()131 bool IsOpenSUSE() const { return DistroVal == OpenSUSE; } 132 IsDebian()133 bool IsDebian() const { 134 return DistroVal >= DebianLenny && DistroVal <= DebianDuke; 135 } 136 IsUbuntu()137 bool IsUbuntu() const { 138 return DistroVal >= UbuntuHardy && DistroVal <= UbuntuQuesting; 139 } 140 IsAlpineLinux()141 bool IsAlpineLinux() const { return DistroVal == AlpineLinux; } 142 IsGentoo()143 bool IsGentoo() const { return DistroVal == Gentoo; } 144 145 /// @} 146 }; 147 148 } // end namespace driver 149 } // end namespace clang 150 151 #endif 152