11{-# LANGUAGE MultiWayIf #-}
22module Build
3- ( buildLibrary
3+ ( CompilerSettings (.. )
4+ , buildLibrary
45 , buildProgram
56 , buildWithScript
67 )
@@ -50,22 +51,28 @@ import System.Directory ( createDirectoryIfMissing
5051 , withCurrentDirectory
5152 )
5253
54+ data CompilerSettings = CompilerSettings {
55+ compilerSettingsCompiler :: FilePath
56+ , compilerSettingsFlags :: [String ]
57+ , compilerSettingsModuleFlag :: String
58+ , compilerSettingsIncludeFlag :: String
59+ }
60+
5361buildProgram
5462 :: FilePath
5563 -> [FilePath ]
5664 -> [FilePattern ]
5765 -> FilePath
58- -> FilePath
59- -> [String ]
66+ -> CompilerSettings
6067 -> String
6168 -> FilePath
6269 -> [FilePath ]
6370 -> IO ()
64- buildProgram programDirectory' libraryDirectories sourceExtensions buildDirectory' compiler flags programName programSource archives
71+ buildProgram programDirectory' libraryDirectories sourceExtensions buildDirectory' ( CompilerSettings { compilerSettingsCompiler = compiler, compilerSettingsFlags = flags, compilerSettingsModuleFlag = moduleFlag, compilerSettingsIncludeFlag = includeFlag }) programName programSource archives
6572 = do
6673 let programDirectory = foldl1 (</>) (splitDirectories programDirectory')
67- let buildDirectory = foldl1 (</>) (splitDirectories buildDirectory')
68- let includeFlags = map (" -I " ++ ) libraryDirectories
74+ let buildDirectory = foldl1 (</>) (splitDirectories buildDirectory')
75+ let includeFlags = map (includeFlag ++ ) libraryDirectories
6976 sourceFiles <- getDirectoriesFiles [programDirectory] sourceExtensions
7077 rawSources <- mapM sourceFileToRawSource sourceFiles
7178 let sources' = map processRawSource rawSources
@@ -98,7 +105,7 @@ buildProgram programDirectory' libraryDirectories sourceExtensions buildDirector
98105 in fileMatcher &?> \ (objectFile : _) -> do
99106 need (sourceFile : directDependencies)
100107 cmd compiler
101- [" -c" , " -J " ++ buildDirectory]
108+ [" -c" , moduleFlag ++ buildDirectory]
102109 includeFlags
103110 flags
104111 [" -o" , objectFile, sourceFile]
@@ -113,14 +120,13 @@ buildLibrary
113120 :: FilePath
114121 -> [FilePattern ]
115122 -> FilePath
116- -> FilePath
117- -> [String ]
123+ -> CompilerSettings
118124 -> String
119125 -> [FilePath ]
120126 -> IO (FilePath )
121- buildLibrary libraryDirectory sourceExtensions buildDirectory compiler flags libraryName otherLibraryDirectories
127+ buildLibrary libraryDirectory sourceExtensions buildDirectory ( CompilerSettings { compilerSettingsCompiler = compiler, compilerSettingsFlags = flags, compilerSettingsModuleFlag = moduleFlag, compilerSettingsIncludeFlag = includeFlag }) libraryName otherLibraryDirectories
122128 = do
123- let includeFlags = map (" -I " ++ ) otherLibraryDirectories
129+ let includeFlags = map (includeFlag ++ ) otherLibraryDirectories
124130 sourceFiles <- getDirectoriesFiles [libraryDirectory] sourceExtensions
125131 rawSources <- mapM sourceFileToRawSource sourceFiles
126132 let sources = map processRawSource rawSources
@@ -150,7 +156,7 @@ buildLibrary libraryDirectory sourceExtensions buildDirectory compiler flags lib
150156 in fileMatcher &?> \ (objectFile : _) -> do
151157 need (sourceFile : directDependencies)
152158 cmd compiler
153- [" -c" , " -J " ++ buildDirectory]
159+ [" -c" , moduleFlag ++ buildDirectory]
154160 includeFlags
155161 flags
156162 [" -o" , objectFile, sourceFile]
@@ -165,18 +171,19 @@ buildWithScript
165171 :: String
166172 -> FilePath
167173 -> FilePath
168- -> FilePath
169- -> [String ]
174+ -> CompilerSettings
170175 -> String
171176 -> [FilePath ]
172177 -> IO (FilePath )
173- buildWithScript script projectDirectory buildDirectory compiler flags libraryName otherLibraryDirectories
178+ buildWithScript script projectDirectory buildDirectory ( CompilerSettings { compilerSettingsCompiler = compiler, compilerSettingsFlags = flags, compilerSettingsModuleFlag = moduleFlag, compilerSettingsIncludeFlag = includeFlag }) libraryName otherLibraryDirectories
174179 = do
175180 absoluteBuildDirectory <- makeAbsolute buildDirectory
176181 createDirectoryIfMissing True absoluteBuildDirectory
177182 absoluteLibraryDirectories <- mapM makeAbsolute otherLibraryDirectories
178- setEnv " FC" compiler
179- setEnv " FFLAGS" (intercalate " " flags)
183+ setEnv " FC" compiler
184+ setEnv " FFLAGS" (intercalate " " flags)
185+ setEnv " FINCLUDEFLAG" includeFlag
186+ setEnv " FMODUELFLAG" moduleFlag
180187 setEnv " BUILD_DIR" $ unWindowsPath absoluteBuildDirectory
181188 setEnv " INCLUDE_DIRS"
182189 (intercalate " " (map unWindowsPath absoluteLibraryDirectories))
0 commit comments