xref: /netbsd-src/external/apache2/llvm/dist/clang/include/clang/Driver/Distro.h (revision e038c9c4676b0f19b1b7dd08a940c6ed64a6d5ae)
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/ADT/Triple.h"
13 #include "llvm/Support/VirtualFileSystem.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     Exherbo,
41     RHEL5,
42     RHEL6,
43     RHEL7,
44     Fedora,
45     Gentoo,
46     OpenSUSE,
47     UbuntuHardy,
48     UbuntuIntrepid,
49     UbuntuJaunty,
50     UbuntuKarmic,
51     UbuntuLucid,
52     UbuntuMaverick,
53     UbuntuNatty,
54     UbuntuOneiric,
55     UbuntuPrecise,
56     UbuntuQuantal,
57     UbuntuRaring,
58     UbuntuSaucy,
59     UbuntuTrusty,
60     UbuntuUtopic,
61     UbuntuVivid,
62     UbuntuWily,
63     UbuntuXenial,
64     UbuntuYakkety,
65     UbuntuZesty,
66     UbuntuArtful,
67     UbuntuBionic,
68     UbuntuCosmic,
69     UbuntuDisco,
70     UbuntuEoan,
71     UbuntuFocal,
72     UbuntuGroovy,
73     UbuntuHirsute,
74     UbuntuImpish,
75     UnknownDistro
76   };
77 
78 private:
79   /// The distribution, possibly with specific version.
80   DistroType DistroVal;
81 
82 public:
83   /// @name Constructors
84   /// @{
85 
86   /// Default constructor leaves the distribution unknown.
Distro()87   Distro() : DistroVal() {}
88 
89   /// Constructs a Distro type for specific distribution.
Distro(DistroType D)90   Distro(DistroType D) : DistroVal(D) {}
91 
92   /// Detects the distribution using specified VFS.
93   explicit Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost);
94 
95   bool operator==(const Distro &Other) const {
96     return DistroVal == Other.DistroVal;
97   }
98 
99   bool operator!=(const Distro &Other) const {
100     return DistroVal != Other.DistroVal;
101   }
102 
103   bool operator>=(const Distro &Other) const {
104     return DistroVal >= Other.DistroVal;
105   }
106 
107   bool operator<=(const Distro &Other) const {
108     return DistroVal <= Other.DistroVal;
109   }
110 
111   /// @}
112   /// @name Convenience Predicates
113   /// @{
114 
IsRedhat()115   bool IsRedhat() const {
116     return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
117   }
118 
IsOpenSUSE()119   bool IsOpenSUSE() const { return DistroVal == OpenSUSE; }
120 
IsDebian()121   bool IsDebian() const {
122     return DistroVal >= DebianLenny && DistroVal <= DebianBullseye;
123   }
124 
IsUbuntu()125   bool IsUbuntu() const {
126     return DistroVal >= UbuntuHardy && DistroVal <= UbuntuImpish;
127   }
128 
IsAlpineLinux()129   bool IsAlpineLinux() const { return DistroVal == AlpineLinux; }
130 
IsGentoo()131   bool IsGentoo() const { return DistroVal == Gentoo; }
132 
133   /// @}
134 };
135 
136 } // end namespace driver
137 } // end namespace clang
138 
139 #endif
140