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 "llvm/Support/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().
71 /// The distribution, possibly with specific version.
75 /// @name Constructors
78 /// Default constructor leaves the distribution unknown.
79 Distro() : DistroVal() {}
81 /// Constructs a Distro type for specific distribution.
82 Distro(DistroType D) : DistroVal(D) {}
84 /// Detects the distribution using specified VFS.
85 explicit Distro(llvm::vfs::FileSystem &VFS);
87 bool operator==(const Distro &Other) const {
88 return DistroVal == Other.DistroVal;
91 bool operator!=(const Distro &Other) const {
92 return DistroVal != Other.DistroVal;
95 bool operator>=(const Distro &Other) const {
96 return DistroVal >= Other.DistroVal;
99 bool operator<=(const Distro &Other) const {
100 return DistroVal <= Other.DistroVal;
104 /// @name Convenience Predicates
107 bool IsRedhat() const {
108 return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
111 bool IsOpenSUSE() const {
112 return DistroVal == OpenSUSE;
115 bool IsDebian() const {
116 return DistroVal >= DebianLenny && DistroVal <= DebianBuster;
119 bool IsUbuntu() const {
120 return DistroVal >= UbuntuHardy && DistroVal <= UbuntuDisco;
123 bool IsAlpineLinux() const {
124 return DistroVal == AlpineLinux;
127 bool IsGentoo() const {
128 return DistroVal == Gentoo;
134 } // end namespace driver
135 } // end namespace clang