module Distribution.Simple.CCompiler (
CDialect(..),
cSourceExtensions,
cDialectFilenameExtension,
filenameCDialect
) where
import Prelude ()
import Distribution.Compat.Prelude
import System.FilePath
( takeExtension )
data CDialect = C
| ObjectiveC
| CPlusPlus
| ObjectiveCPlusPlus
deriving (CDialect -> CDialect -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CDialect -> CDialect -> Bool
$c/= :: CDialect -> CDialect -> Bool
== :: CDialect -> CDialect -> Bool
$c== :: CDialect -> CDialect -> Bool
Eq, Int -> CDialect -> ShowS
[CDialect] -> ShowS
CDialect -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CDialect] -> ShowS
$cshowList :: [CDialect] -> ShowS
show :: CDialect -> String
$cshow :: CDialect -> String
showsPrec :: Int -> CDialect -> ShowS
$cshowsPrec :: Int -> CDialect -> ShowS
Show)
instance Monoid CDialect where
mempty :: CDialect
mempty = CDialect
C
mappend :: CDialect -> CDialect -> CDialect
mappend = forall a. Semigroup a => a -> a -> a
(<>)
instance Semigroup CDialect where
CDialect
C <> :: CDialect -> CDialect -> CDialect
<> CDialect
anything = CDialect
anything
CDialect
ObjectiveC <> CDialect
CPlusPlus = CDialect
ObjectiveCPlusPlus
CDialect
CPlusPlus <> CDialect
ObjectiveC = CDialect
ObjectiveCPlusPlus
CDialect
_ <> CDialect
ObjectiveCPlusPlus = CDialect
ObjectiveCPlusPlus
CDialect
ObjectiveC <> CDialect
_ = CDialect
ObjectiveC
CDialect
CPlusPlus <> CDialect
_ = CDialect
CPlusPlus
CDialect
ObjectiveCPlusPlus <> CDialect
_ = CDialect
ObjectiveCPlusPlus
cSourceExtensions :: [String]
cSourceExtensions :: [String]
cSourceExtensions = [String
"c", String
"i", String
"ii", String
"m", String
"mi", String
"mm", String
"M", String
"mii", String
"cc", String
"cp",
String
"cxx", String
"cpp", String
"CPP", String
"c++", String
"C"]
cDialectFilenameExtension :: CDialect -> Bool -> String
cDialectFilenameExtension :: CDialect -> Bool -> String
cDialectFilenameExtension CDialect
C Bool
True = String
"c"
cDialectFilenameExtension CDialect
C Bool
False = String
"i"
cDialectFilenameExtension CDialect
ObjectiveC Bool
True = String
"m"
cDialectFilenameExtension CDialect
ObjectiveC Bool
False = String
"mi"
cDialectFilenameExtension CDialect
CPlusPlus Bool
True = String
"cpp"
cDialectFilenameExtension CDialect
CPlusPlus Bool
False = String
"ii"
cDialectFilenameExtension CDialect
ObjectiveCPlusPlus Bool
True = String
"mm"
cDialectFilenameExtension CDialect
ObjectiveCPlusPlus Bool
False = String
"mii"
filenameCDialect :: String -> Maybe (CDialect, Bool)
filenameCDialect :: String -> Maybe (CDialect, Bool)
filenameCDialect String
filename = do
String
extension <- case ShowS
takeExtension String
filename of
Char
'.':String
ext -> forall a. a -> Maybe a
Just String
ext
String
_ -> forall a. Maybe a
Nothing
case String
extension of
String
"c" -> forall (m :: * -> *) a. Monad m => a -> m a
return (CDialect
C, Bool
True)
String
"i" -> forall (m :: * -> *) a. Monad m => a -> m a
return (CDialect
C, Bool
False)
String
"ii" -> forall (m :: * -> *) a. Monad m => a -> m a
return (CDialect
CPlusPlus, Bool
False)
String
"m" -> forall (m :: * -> *) a. Monad m => a -> m a
return (CDialect
ObjectiveC, Bool
True)
String
"mi" -> forall (m :: * -> *) a. Monad m => a -> m a
return (CDialect
ObjectiveC, Bool
False)
String
"mm" -> forall (m :: * -> *) a. Monad m => a -> m a
return (CDialect
ObjectiveCPlusPlus, Bool
True)
String
"M" -> forall (m :: * -> *) a. Monad m => a -> m a
return (CDialect
ObjectiveCPlusPlus, Bool
True)
String
"mii" -> forall (m :: * -> *) a. Monad m => a -> m a
return (CDialect
ObjectiveCPlusPlus, Bool
False)
String
"cc" -> forall (m :: * -> *) a. Monad m => a -> m a
return (CDialect
CPlusPlus, Bool
True)
String
"cp" -> forall (m :: * -> *) a. Monad m => a -> m a
return (CDialect
CPlusPlus, Bool
True)
String
"cxx" -> forall (m :: * -> *) a. Monad m => a -> m a
return (CDialect
CPlusPlus, Bool
True)
String
"cpp" -> forall (m :: * -> *) a. Monad m => a -> m a
return (CDialect
CPlusPlus, Bool
True)
String
"CPP" -> forall (m :: * -> *) a. Monad m => a -> m a
return (CDialect
CPlusPlus, Bool
True)
String
"c++" -> forall (m :: * -> *) a. Monad m => a -> m a
return (CDialect
CPlusPlus, Bool
True)
String
"C" -> forall (m :: * -> *) a. Monad m => a -> m a
return (CDialect
CPlusPlus, Bool
True)
String
_ -> forall a. Maybe a
Nothing