module GHC.Toolchain.NormaliseTriple where

import GHC.Toolchain.Prelude
import GHC.Toolchain.Program
import Data.Text (strip, pack, unpack)

-- | Normalise the triple by calling `config.sub` on the given triple.
normaliseTriple :: String -> M String
normaliseTriple :: String -> M String
normaliseTriple String
triple = do
  let norm :: String -> String
norm = Text -> String
unpack (Text -> String) -> (String -> Text) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
strip (Text -> Text) -> (String -> Text) -> String -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
pack
  normalised_triple <- String -> String
norm (String -> String) -> M String -> M String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Program -> [String] -> M String
readProgramStdout Program
shProgram [String
"config.sub", String
triple]
  logInfo $ unwords ["Normalised triple:", triple, "~>", normalised_triple]
  return normalised_triple