Commit c8e8f052 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Add read/show for CompilerFlavour like for OS and Arch

Also add YHC compiler flavour.
parent e9ea7591
...@@ -39,18 +39,45 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ...@@ -39,18 +39,45 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -} OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Compiler (CompilerFlavor(..), defaultCompilerFlavor) where module Distribution.Compiler (
CompilerFlavor(..),
showCompilerFlavor,
readCompilerFlavor,
buildCompilerFlavor,
defaultCompilerFlavor
) where
import System.Info (compilerName) import qualified System.Info (compilerName)
import qualified Data.Char as Char (toLower)
data CompilerFlavor data CompilerFlavor = GHC | NHC | YHC | Hugs | HBC | Helium | JHC
= GHC | NHC | Hugs | HBC | Helium | JHC | OtherCompiler String | OtherCompiler String
deriving (Show, Read, Eq, Ord) deriving (Show, Read, Eq, Ord)
knownCompilerFlavors :: [CompilerFlavor]
knownCompilerFlavors = [GHC, NHC, YHC, Hugs, HBC, Helium, JHC]
showCompilerFlavor :: CompilerFlavor -> String
showCompilerFlavor (OtherCompiler name) = name
showCompilerFlavor NHC = "nhc98"
showCompilerFlavor other = lowercase (show other)
readCompilerFlavor :: String -> CompilerFlavor
readCompilerFlavor s =
case lookup (lowercase s) compilerMap of
Just arch -> arch
Nothing -> OtherCompiler (lowercase s)
where
compilerMap = [ (showCompilerFlavor compiler, compiler)
| compiler <- knownCompilerFlavors ]
buildCompilerFlavor :: CompilerFlavor
buildCompilerFlavor = readCompilerFlavor System.Info.compilerName
defaultCompilerFlavor :: Maybe CompilerFlavor defaultCompilerFlavor :: Maybe CompilerFlavor
defaultCompilerFlavor = case compilerName of defaultCompilerFlavor = case buildCompilerFlavor of
"ghc" -> Just GHC OtherCompiler _ -> Nothing
"nhc98" -> Just NHC _ -> Just buildCompilerFlavor
"jhc" -> Just JHC
"hugs" -> Just Hugs lowercase :: String -> String
_ -> Nothing lowercase = map Char.toLower
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment