Skip to content

Commit 93b1df6

Browse files
committed
Add a cSettingOutputDirectory setting for codegen.
If set, this option defines an output destination directory for generated files. It will be created if necessary. Fixes #255
1 parent 6de857e commit 93b1df6

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

copilot-c99/src/Copilot/Compile/C99/Compile/Internal.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module Copilot.Compile.C99.Compile.Internal
77
import Text.PrettyPrint (render)
88
import Data.List (nub)
99
import Data.Maybe (catMaybes)
10+
import System.Directory (createDirectoryIfMissing)
11+
import System.FilePath ((</>))
1012

1113
import Language.C99.Pretty (pretty)
1214
import qualified Language.C99.Simple as C
@@ -41,8 +43,14 @@ compileWith cSettings prefix spec = do
4143
, ""
4244
]
4345

44-
writeFile (prefix ++ ".c") $ cmacros ++ cfile
45-
writeFile (prefix ++ ".h") hfile
46+
case cSettingsOutputDirectory cSettings of
47+
Nothing ->
48+
do writeFile (prefix ++ ".c") $ cmacros ++ cfile
49+
writeFile (prefix ++ ".h") hfile
50+
Just dir ->
51+
do createDirectoryIfMissing True dir
52+
writeFile (dir </> prefix ++ ".c") $ cmacros ++ cfile
53+
writeFile (dir </> prefix ++ ".h") hfile
4654

4755
-- | Compile a specification to a .h and a .c file.
4856
--

copilot-c99/src/Copilot/Compile/C99/Settings/Internal.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ module Copilot.Compile.C99.Settings.Internal where
44
-- | Settings used to customize the code generated.
55
data CSettings = CSettings
66
{ cSettingsStepFunctionName :: String
7+
, cSettingsOutputDirectory :: Maybe FilePath
78
}
89

910
-- | Default settings with a step function called @step@.
1011
mkDefaultCSettings :: CSettings
11-
mkDefaultCSettings = CSettings "step"
12+
mkDefaultCSettings = CSettings "step" Nothing

0 commit comments

Comments
 (0)