module Shake.C where
import qualified Development.Shake as Shake
type Flag = String
data ExternalLibrary = ExternalLibrary {
ExternalLibrary -> [Flag]
libLink :: [Flag]
, ExternalLibrary -> [Flag]
libCompile :: [Flag]
} deriving (Int -> ExternalLibrary -> ShowS
[ExternalLibrary] -> ShowS
ExternalLibrary -> Flag
forall a.
(Int -> a -> ShowS) -> (a -> Flag) -> ([a] -> ShowS) -> Show a
showList :: [ExternalLibrary] -> ShowS
$cshowList :: [ExternalLibrary] -> ShowS
show :: ExternalLibrary -> Flag
$cshow :: ExternalLibrary -> Flag
showsPrec :: Int -> ExternalLibrary -> ShowS
$cshowsPrec :: Int -> ExternalLibrary -> ShowS
Show)
library :: String -> ExternalLibrary
library :: Flag -> ExternalLibrary
library Flag
name = ExternalLibrary
{ libLink :: [Flag]
libLink = [Flag
"-l" forall a. Semigroup a => a -> a -> a
<> Flag
name]
, libCompile :: [Flag]
libCompile = []
}
data Binary config = Binary {
forall config. Binary config -> Flag
binName :: String
, forall config. Binary config -> [Flag]
binObjs :: [FilePath]
, forall config. Binary config -> config -> [Flag]
binCompile :: config -> [Flag]
, forall config. Binary config -> config -> [Flag]
binLink :: config -> [Flag]
, forall config. Binary config -> config -> [ExternalLibrary]
binLibraries :: config -> [ExternalLibrary]
, forall config. Binary config -> Flag -> Action ()
binPostproc :: FilePath -> Shake.Action ()
}
binary :: String -> [FilePath] -> Binary config
binary :: forall config. Flag -> [Flag] -> Binary config
binary Flag
name [Flag]
objs = Binary
{ binName :: Flag
binName = Flag
name
, binObjs :: [Flag]
binObjs = [Flag]
objs
, binCompile :: config -> [Flag]
binCompile = forall a b. a -> b -> a
const []
, binLink :: config -> [Flag]
binLink = forall a b. a -> b -> a
const []
, binLibraries :: config -> [ExternalLibrary]
binLibraries = forall a b. a -> b -> a
const []
, binPostproc :: Flag -> Action ()
binPostproc = forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return ()
}
binCompileFlags :: Binary config -> config -> [Flag]
binCompileFlags :: forall config. Binary config -> config -> [Flag]
binCompileFlags Binary config
bin config
config =
forall config. Binary config -> config -> [Flag]
binCompile Binary config
bin config
config forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ExternalLibrary -> [Flag]
libCompile (forall config. Binary config -> config -> [ExternalLibrary]
binLibraries Binary config
bin config
config)
binLinkFlags :: Binary config -> config -> [Flag]
binLinkFlags :: forall config. Binary config -> config -> [Flag]
binLinkFlags Binary config
bin config
config =
forall config. Binary config -> config -> [Flag]
binLink Binary config
bin config
config forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ExternalLibrary -> [Flag]
libLink (forall config. Binary config -> config -> [ExternalLibrary]
binLibraries Binary config
bin config
config)