module Language.Drasil.Code.Imperative.Build.AST where
import Build.Drasil (makeS, MakeString, mkImplicitVar, mkWindowsVar, mkOSVar,
Command, mkCheckedCommand, Dependencies)
type CommandFragment = MakeString
data BuildName = BMain
| BPackName
| BPack BuildName
| BWithExt BuildName Ext
data Ext = CodeExt
| OtherExt MakeString
data BuildDependencies = BcSource
| BcSingle BuildName
data BuildConfig = BuildConfig
([CommandFragment] -> CommandFragment -> CommandFragment -> [BuildCommand])
(Maybe BuildName) (Maybe BuildName) BuildDependencies
data RunType = Standalone
| Interpreter [CommandFragment]
data Runnable = Runnable BuildName NameOpts RunType
data DocConfig = DocConfig Dependencies [Command]
data NameOpts = NameOpts {
NameOpts -> String
packSep :: String,
NameOpts -> Bool
includeExt :: Bool
}
nameOpts :: NameOpts
nameOpts :: NameOpts
nameOpts = NameOpts {
packSep :: String
packSep = String
"/",
includeExt :: Bool
includeExt = Bool
True
}
type BuildCommand = [CommandFragment]
type InterpreterCommand = String
type InterpreterOption = String
asFragment :: String -> CommandFragment
asFragment :: String -> CommandFragment
asFragment = String -> CommandFragment
makeS
osClassDefault :: String -> String -> String -> CommandFragment
osClassDefault :: String -> String -> String -> CommandFragment
osClassDefault = String -> String -> String -> CommandFragment
mkWindowsVar
buildAll :: ([CommandFragment] -> CommandFragment -> [BuildCommand]) ->
BuildName -> Maybe BuildConfig
buildAll :: ([CommandFragment] -> CommandFragment -> [[CommandFragment]])
-> BuildName -> Maybe BuildConfig
buildAll [CommandFragment] -> CommandFragment -> [[CommandFragment]]
f BuildName
n = BuildConfig -> Maybe BuildConfig
forall a. a -> Maybe a
Just (BuildConfig -> Maybe BuildConfig)
-> BuildConfig -> Maybe BuildConfig
forall a b. (a -> b) -> a -> b
$ ([CommandFragment]
-> CommandFragment -> CommandFragment -> [[CommandFragment]])
-> Maybe BuildName
-> Maybe BuildName
-> BuildDependencies
-> BuildConfig
BuildConfig (\[CommandFragment]
i CommandFragment
o CommandFragment
_ -> [CommandFragment] -> CommandFragment -> [[CommandFragment]]
f [CommandFragment]
i CommandFragment
o) (BuildName -> Maybe BuildName
forall a. a -> Maybe a
Just BuildName
n) Maybe BuildName
forall a. Maybe a
Nothing BuildDependencies
BcSource
buildAllAdditionalName :: ([CommandFragment] -> CommandFragment ->
CommandFragment -> [BuildCommand]) -> BuildName -> BuildName ->
Maybe BuildConfig
buildAllAdditionalName :: ([CommandFragment]
-> CommandFragment -> CommandFragment -> [[CommandFragment]])
-> BuildName -> BuildName -> Maybe BuildConfig
buildAllAdditionalName [CommandFragment]
-> CommandFragment -> CommandFragment -> [[CommandFragment]]
f BuildName
n BuildName
a = BuildConfig -> Maybe BuildConfig
forall a. a -> Maybe a
Just (BuildConfig -> Maybe BuildConfig)
-> BuildConfig -> Maybe BuildConfig
forall a b. (a -> b) -> a -> b
$ ([CommandFragment]
-> CommandFragment -> CommandFragment -> [[CommandFragment]])
-> Maybe BuildName
-> Maybe BuildName
-> BuildDependencies
-> BuildConfig
BuildConfig [CommandFragment]
-> CommandFragment -> CommandFragment -> [[CommandFragment]]
f (BuildName -> Maybe BuildName
forall a. a -> Maybe a
Just BuildName
n) (BuildName -> Maybe BuildName
forall a. a -> Maybe a
Just BuildName
a) BuildDependencies
BcSource
buildSingle :: ([CommandFragment] -> CommandFragment -> [BuildCommand]) ->
BuildName -> BuildName -> Maybe BuildConfig
buildSingle :: ([CommandFragment] -> CommandFragment -> [[CommandFragment]])
-> BuildName -> BuildName -> Maybe BuildConfig
buildSingle [CommandFragment] -> CommandFragment -> [[CommandFragment]]
f BuildName
n = BuildConfig -> Maybe BuildConfig
forall a. a -> Maybe a
Just (BuildConfig -> Maybe BuildConfig)
-> (BuildName -> BuildConfig) -> BuildName -> Maybe BuildConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([CommandFragment]
-> CommandFragment -> CommandFragment -> [[CommandFragment]])
-> Maybe BuildName
-> Maybe BuildName
-> BuildDependencies
-> BuildConfig
BuildConfig (\[CommandFragment]
i CommandFragment
o CommandFragment
_ -> [CommandFragment] -> CommandFragment -> [[CommandFragment]]
f [CommandFragment]
i CommandFragment
o) (BuildName -> Maybe BuildName
forall a. a -> Maybe a
Just BuildName
n) Maybe BuildName
forall a. Maybe a
Nothing (BuildDependencies -> BuildConfig)
-> (BuildName -> BuildDependencies) -> BuildName -> BuildConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
BuildName -> BuildDependencies
BcSingle
nativeBinary :: Maybe Runnable
nativeBinary :: Maybe Runnable
nativeBinary = Runnable -> Maybe Runnable
forall a. a -> Maybe a
Just (Runnable -> Maybe Runnable) -> Runnable -> Maybe Runnable
forall a b. (a -> b) -> a -> b
$ BuildName -> NameOpts -> RunType -> Runnable
Runnable BuildName
executable NameOpts
nameOpts RunType
Standalone
executable :: BuildName
executable :: BuildName
executable = BuildName -> Ext -> BuildName
BWithExt BuildName
BPackName (Ext -> BuildName) -> Ext -> BuildName
forall a b. (a -> b) -> a -> b
$ CommandFragment -> Ext
OtherExt (CommandFragment -> Ext) -> CommandFragment -> Ext
forall a b. (a -> b) -> a -> b
$
String -> String -> String -> CommandFragment
osClassDefault String
"TARGET_EXTENSION" String
".exe" String
""
sharedLibrary :: BuildName
sharedLibrary :: BuildName
sharedLibrary = BuildName -> Ext -> BuildName
BWithExt BuildName
BPackName (Ext -> BuildName) -> Ext -> BuildName
forall a b. (a -> b) -> a -> b
$ CommandFragment -> Ext
OtherExt (CommandFragment -> Ext) -> CommandFragment -> Ext
forall a b. (a -> b) -> a -> b
$
String -> String -> String -> String -> CommandFragment
mkOSVar String
"LIB_EXTENSION" String
".dll" String
".dylib" String
".so"
interp :: BuildName -> NameOpts -> InterpreterCommand -> [InterpreterOption]
-> Maybe Runnable
interp :: BuildName -> NameOpts -> String -> [String] -> Maybe Runnable
interp BuildName
b NameOpts
n String
c = Runnable -> Maybe Runnable
forall a. a -> Maybe a
Just (Runnable -> Maybe Runnable)
-> ([String] -> Runnable) -> [String] -> Maybe Runnable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuildName -> NameOpts -> RunType -> Runnable
Runnable BuildName
b NameOpts
n (RunType -> Runnable)
-> ([String] -> RunType) -> [String] -> Runnable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [CommandFragment] -> RunType
Interpreter ([CommandFragment] -> RunType)
-> ([String] -> [CommandFragment]) -> [String] -> RunType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> CommandFragment) -> [String] -> [CommandFragment]
forall a b. (a -> b) -> [a] -> [b]
map String -> CommandFragment
makeS ([String] -> [CommandFragment])
-> ([String] -> [String]) -> [String] -> [CommandFragment]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String
cString -> [String] -> [String]
forall a. a -> [a] -> [a]
:)
interpMM :: InterpreterCommand -> Maybe Runnable
interpMM :: String -> Maybe Runnable
interpMM = Runnable -> Maybe Runnable
forall a. a -> Maybe a
Just (Runnable -> Maybe Runnable)
-> (String -> Runnable) -> String -> Maybe Runnable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuildName -> NameOpts -> RunType -> Runnable
Runnable BuildName
mainModuleFile NameOpts
nameOpts (RunType -> Runnable) -> (String -> RunType) -> String -> Runnable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [CommandFragment] -> RunType
Interpreter ([CommandFragment] -> RunType)
-> (String -> [CommandFragment]) -> String -> RunType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CommandFragment -> [CommandFragment] -> [CommandFragment]
forall a. a -> [a] -> [a]
:[]) (CommandFragment -> [CommandFragment])
-> (String -> CommandFragment) -> String -> [CommandFragment]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> CommandFragment
makeS
mainModule :: BuildName
mainModule :: BuildName
mainModule = BuildName
BMain
mainModuleFile :: BuildName
mainModuleFile :: BuildName
mainModuleFile = BuildName -> Ext -> BuildName
BWithExt BuildName
BMain Ext
CodeExt
inCodePackage :: BuildName -> BuildName
inCodePackage :: BuildName -> BuildName
inCodePackage = BuildName -> BuildName
BPack
withExt :: BuildName -> String -> BuildName
withExt :: BuildName -> String -> BuildName
withExt BuildName
b = BuildName -> Ext -> BuildName
BWithExt BuildName
b (Ext -> BuildName) -> (String -> Ext) -> String -> BuildName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CommandFragment -> Ext
OtherExt (CommandFragment -> Ext)
-> (String -> CommandFragment) -> String -> Ext
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> CommandFragment
makeS
cCompiler :: CommandFragment
cCompiler :: CommandFragment
cCompiler = String -> CommandFragment
mkImplicitVar String
"CC"
cppCompiler :: CommandFragment
cppCompiler :: CommandFragment
cppCompiler = String -> CommandFragment
mkImplicitVar String
"CXX"
doxygenDocConfig :: FilePath -> DocConfig
doxygenDocConfig :: String -> DocConfig
doxygenDocConfig String
fp = [CommandFragment] -> [Command] -> DocConfig
DocConfig [String -> CommandFragment
makeS String
fp]
[CommandFragment -> Command
mkCheckedCommand (CommandFragment -> Command) -> CommandFragment -> Command
forall a b. (a -> b) -> a -> b
$ String -> CommandFragment
makeS (String -> CommandFragment) -> String -> CommandFragment
forall a b. (a -> b) -> a -> b
$ String
"doxygen " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
fp]