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