Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:52

0001 //===--- Distro.h - Linux distribution detection support --------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_DRIVER_DISTRO_H
0010 #define LLVM_CLANG_DRIVER_DISTRO_H
0011 
0012 #include "llvm/Support/VirtualFileSystem.h"
0013 #include "llvm/TargetParser/Triple.h"
0014 
0015 namespace clang {
0016 namespace driver {
0017 
0018 /// Distro - Helper class for detecting and classifying Linux distributions.
0019 ///
0020 /// This class encapsulates the clang Linux distribution detection mechanism
0021 /// as well as helper functions that match the specific (versioned) results
0022 /// into wider distribution classes.
0023 class Distro {
0024 public:
0025   enum DistroType {
0026     // Special value means that no detection was performed yet.
0027     UninitializedDistro,
0028     // NB: Releases of a particular Linux distro should be kept together
0029     // in this enum, because some tests are done by integer comparison against
0030     // the first and last known member in the family, e.g. IsRedHat().
0031     AlpineLinux,
0032     ArchLinux,
0033     DebianLenny,
0034     DebianSqueeze,
0035     DebianWheezy,
0036     DebianJessie,
0037     DebianStretch,
0038     DebianBuster,
0039     DebianBullseye,
0040     DebianBookworm,
0041     DebianTrixie,
0042     DebianForky,
0043     DebianDuke,
0044     Exherbo,
0045     RHEL5,
0046     RHEL6,
0047     RHEL7,
0048     Fedora,
0049     Gentoo,
0050     OpenSUSE,
0051     UbuntuHardy,
0052     UbuntuIntrepid,
0053     UbuntuJaunty,
0054     UbuntuKarmic,
0055     UbuntuLucid,
0056     UbuntuMaverick,
0057     UbuntuNatty,
0058     UbuntuOneiric,
0059     UbuntuPrecise,
0060     UbuntuQuantal,
0061     UbuntuRaring,
0062     UbuntuSaucy,
0063     UbuntuTrusty,
0064     UbuntuUtopic,
0065     UbuntuVivid,
0066     UbuntuWily,
0067     UbuntuXenial,
0068     UbuntuYakkety,
0069     UbuntuZesty,
0070     UbuntuArtful,
0071     UbuntuBionic,
0072     UbuntuCosmic,
0073     UbuntuDisco,
0074     UbuntuEoan,
0075     UbuntuFocal,
0076     UbuntuGroovy,
0077     UbuntuHirsute,
0078     UbuntuImpish,
0079     UbuntuJammy,
0080     UbuntuKinetic,
0081     UbuntuLunar,
0082     UbuntuMantic,
0083     UbuntuNoble,
0084     UbuntuOracular,
0085     UbuntuPlucky,
0086     UnknownDistro
0087   };
0088 
0089 private:
0090   /// The distribution, possibly with specific version.
0091   DistroType DistroVal;
0092 
0093 public:
0094   /// @name Constructors
0095   /// @{
0096 
0097   /// Default constructor leaves the distribution unknown.
0098   Distro() : DistroVal() {}
0099 
0100   /// Constructs a Distro type for specific distribution.
0101   Distro(DistroType D) : DistroVal(D) {}
0102 
0103   /// Detects the distribution using specified VFS.
0104   explicit Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost);
0105 
0106   bool operator==(const Distro &Other) const {
0107     return DistroVal == Other.DistroVal;
0108   }
0109 
0110   bool operator!=(const Distro &Other) const {
0111     return DistroVal != Other.DistroVal;
0112   }
0113 
0114   bool operator>=(const Distro &Other) const {
0115     return DistroVal >= Other.DistroVal;
0116   }
0117 
0118   bool operator<=(const Distro &Other) const {
0119     return DistroVal <= Other.DistroVal;
0120   }
0121 
0122   /// @}
0123   /// @name Convenience Predicates
0124   /// @{
0125 
0126   bool IsRedhat() const {
0127     return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
0128   }
0129 
0130   bool IsOpenSUSE() const { return DistroVal == OpenSUSE; }
0131 
0132   bool IsDebian() const {
0133     return DistroVal >= DebianLenny && DistroVal <= DebianDuke;
0134   }
0135 
0136   bool IsUbuntu() const {
0137     return DistroVal >= UbuntuHardy && DistroVal <= UbuntuPlucky;
0138   }
0139 
0140   bool IsAlpineLinux() const { return DistroVal == AlpineLinux; }
0141 
0142   bool IsGentoo() const { return DistroVal == Gentoo; }
0143 
0144   /// @}
0145 };
0146 
0147 } // end namespace driver
0148 } // end namespace clang
0149 
0150 #endif