1 //===--- Distro.h - Linux distribution detection support --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_DRIVER_DISTRO_H
11 #define LLVM_CLANG_DRIVER_DISTRO_H
13 #include "clang/Basic/VirtualFileSystem.h"
18 /// Distro - Helper class for detecting and classifying Linux distributions.
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.
26 // NB: Releases of a particular Linux distro should be kept together
27 // in this enum, because some tests are done by integer comparison against
28 // the first and last known member in the family, e.g. IsRedHat().
69 /// The distribution, possibly with specific version.
73 /// @name Constructors
76 /// Default constructor leaves the distribution unknown.
77 Distro() : DistroVal() {}
79 /// Constructs a Distro type for specific distribution.
80 Distro(DistroType D) : DistroVal(D) {}
82 /// Detects the distribution using specified VFS.
83 explicit Distro(clang::vfs::FileSystem& VFS);
85 bool operator==(const Distro &Other) const {
86 return DistroVal == Other.DistroVal;
89 bool operator!=(const Distro &Other) const {
90 return DistroVal != Other.DistroVal;
93 bool operator>=(const Distro &Other) const {
94 return DistroVal >= Other.DistroVal;
97 bool operator<=(const Distro &Other) const {
98 return DistroVal <= Other.DistroVal;
102 /// @name Convenience Predicates
105 bool IsRedhat() const {
106 return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
109 bool IsOpenSUSE() const {
110 return DistroVal == OpenSUSE;
113 bool IsDebian() const {
114 return DistroVal >= DebianLenny && DistroVal <= DebianBuster;
117 bool IsUbuntu() const {
118 return DistroVal >= UbuntuHardy && DistroVal <= UbuntuCosmic;
121 bool IsAlpineLinux() const {
122 return DistroVal == AlpineLinux;
128 } // end namespace driver
129 } // end namespace clang