module DDC.Driver.Build.Main
( buildSpec
, buildComponent
, buildModule)
where
import DDC.Driver.Command.Compile
import DDC.Driver.Build.Locate
import DDC.Driver.Config
import DDC.Build.Spec
import Control.Monad
import Control.Monad.Trans.Except
import Control.Monad.IO.Class
import DDC.Build.Interface.Store (Store)
import qualified DDC.Core.Module as C
buildSpec
:: Config
-> Store
-> Spec
-> ExceptT String IO ()
buildSpec config store spec
= do mapM_ (buildComponent config store)
(specComponents spec)
buildComponent
:: Config
-> Store
-> Component
-> ExceptT String IO ()
buildComponent config store component@SpecLibrary{}
= do
when (configLogBuild config)
$ liftIO $ putStrLn $ "* Building library " ++ specLibraryName component
buildLibrary config store
$ specLibraryTetraModules component
return ()
buildComponent config store component@SpecExecutable{}
= do
when (configLogBuild config)
$ liftIO $ putStrLn $ "* Building executable " ++ specExecutableName component
buildExecutable config store
(specExecutableTetraMain component)
(specExecutableTetraOther component)
return ()
buildLibrary
:: Config
-> Store
-> [C.ModuleName]
-> ExceptT String IO ()
buildLibrary config store ms0
= go ms0
where
go []
= return ()
go (m : more)
= do buildModule config store m
go more
buildExecutable
:: Config
-> Store
-> C.ModuleName
-> [C.ModuleName]
-> ExceptT String IO ()
buildExecutable config store mMain msOther0
= go msOther0
where
go []
= do let dirs = configModuleBaseDirectories config
path <- locateModuleFromPaths dirs mMain "ds"
_ <- cmdCompile config True store path
return ()
go (m : more)
= do buildModule config store m
go more
buildModule
:: Config
-> Store
-> C.ModuleName
-> ExceptT String IO ()
buildModule config store name
= do let dirs = configModuleBaseDirectories config
path <- locateModuleFromPaths dirs name "ds"
_ <- cmdCompile config False store path
return ()