1 //===--- Distro.h - Linux distribution detection support --------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_DRIVER_DISTRO_H
10 #define LLVM_CLANG_DRIVER_DISTRO_H
12 #include "llvm/ADT/Triple.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().
75 /// The distribution, possibly with specific version.
79 /// @name Constructors
82 /// Default constructor leaves the distribution unknown.
83 Distro() : DistroVal() {}
85 /// Constructs a Distro type for specific distribution.
86 Distro(DistroType D) : DistroVal(D) {}
88 /// Detects the distribution using specified VFS.
89 explicit Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost);
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;
103 bool operator<=(const Distro &Other) const {
104 return DistroVal <= Other.DistroVal;
108 /// @name Convenience Predicates
111 bool IsRedhat() const {
112 return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
115 bool IsOpenSUSE() const {
116 return DistroVal == OpenSUSE;
119 bool IsDebian() const {
120 return DistroVal >= DebianLenny && DistroVal <= DebianBullseye;
123 bool IsUbuntu() const {
124 return DistroVal >= UbuntuHardy && DistroVal <= UbuntuGroovy;
127 bool IsAlpineLinux() const {
128 return DistroVal == AlpineLinux;
131 bool IsGentoo() const {
132 return DistroVal == Gentoo;
138 } // end namespace driver
139 } // end namespace clang