1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
-- |
-- Module : Foundation.System.Info
-- License : BSD-style
-- Maintainer : foundation
-- Stability : experimental
-- Portability : portable
--
{-# LANGUAGE CPP #-}
module Foundation.System.Info
(
-- * Operation System info
OS(..)
, os
-- * CPU info
, Arch(..)
, arch
, cpus
, Endianness(..)
, endianness
-- * Compiler info
, compilerName
, System.Info.compilerVersion
, Data.Version.Version(..)
) where
import qualified System.Info
import qualified Data.Version
import Data.Data
import qualified GHC.Conc
import Basement.Compat.Base
import Basement.Endianness (Endianness(..), endianness)
import Foundation.String
data OS
= Windows
| OSX
| Linux
| Android
| BSD
deriving (Show, Eq, Ord, Enum, Bounded, Data, Typeable)
-- | get the operating system on which the program is running.
--
-- Either return the known `OS` or a strict `String` of the OS name.
--
-- This function uses the `base`'s `System.Info.os` function.
--
os :: Either [Char] OS
os = case System.Info.os of
"darwin" -> Right OSX
"mingw32" -> Right Windows
"linux" -> Right Linux
"linux-android" -> Right Android
"openbsd" -> Right BSD
"netbsd" -> Right BSD
"freebsd" -> Right BSD
str -> Left str
-- | Enumeration of the known GHC supported architecture.
--
data Arch
= I386
| X86_64
| PowerPC
| PowerPC64
| Sparc
| Sparc64
| ARM
| ARM64
deriving (Show, Eq, Ord, Enum, Bounded, Data, Typeable)
-- | get the machine architecture on which the program is running
--
-- Either return the known architecture or a Strict `String` of the
-- architecture name.
--
-- This function uses the `base`'s `System.Info.arch` function.
--
arch :: Either [Char] Arch
arch = case System.Info.arch of
"i386" -> Right I386
"x86_64" -> Right X86_64
"powerpc" -> Right PowerPC
"powerpc64" -> Right PowerPC64
"powerpc64le" -> Right PowerPC64
"sparc" -> Right Sparc
"sparc64" -> Right Sparc64
"arm" -> Right ARM
"aarch64" -> Right ARM64
str -> Left str
-- | get the compiler name
--
-- get the compilerName from base package but convert
-- it into a strict String
compilerName :: String
compilerName = fromList System.Info.compilerName
-- | returns the number of CPUs the machine has
cpus :: IO Int
cpus = GHC.Conc.getNumProcessors
|