Skip to content

Commit

Permalink
Add a cSettingOutputDirectory setting for codegen.
Browse files Browse the repository at this point in the history
If set, this option defines an output destination directory
for generated files.  It will be created if necessary.

Fixes #255
  • Loading branch information
robdockins committed Sep 23, 2021
1 parent 6de857e commit 93b1df6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions copilot-c99/src/Copilot/Compile/C99/Compile/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module Copilot.Compile.C99.Compile.Internal
import Text.PrettyPrint (render)
import Data.List (nub)
import Data.Maybe (catMaybes)
import System.Directory (createDirectoryIfMissing)
import System.FilePath ((</>))

import Language.C99.Pretty (pretty)
import qualified Language.C99.Simple as C
Expand Down Expand Up @@ -41,8 +43,14 @@ compileWith cSettings prefix spec = do
, ""
]

writeFile (prefix ++ ".c") $ cmacros ++ cfile
writeFile (prefix ++ ".h") hfile
case cSettingsOutputDirectory cSettings of
Nothing ->
do writeFile (prefix ++ ".c") $ cmacros ++ cfile
writeFile (prefix ++ ".h") hfile
Just dir ->
do createDirectoryIfMissing True dir
writeFile (dir </> prefix ++ ".c") $ cmacros ++ cfile
writeFile (dir </> prefix ++ ".h") hfile

-- | Compile a specification to a .h and a .c file.
--
Expand Down
3 changes: 2 additions & 1 deletion copilot-c99/src/Copilot/Compile/C99/Settings/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ module Copilot.Compile.C99.Settings.Internal where
-- | Settings used to customize the code generated.
data CSettings = CSettings
{ cSettingsStepFunctionName :: String
, cSettingsOutputDirectory :: Maybe FilePath
}

-- | Default settings with a step function called @step@.
mkDefaultCSettings :: CSettings
mkDefaultCSettings = CSettings "step"
mkDefaultCSettings = CSettings "step" Nothing

0 comments on commit 93b1df6

Please sign in to comment.