aboutsummaryrefslogtreecommitdiff
path: root/src/Build.hs
diff options
context:
space:
mode:
authorBrad Richardson <everythingfunctional@protonmail.com>2020-03-30 15:01:34 -0500
committerGitHub <noreply@github.com>2020-03-30 15:01:34 -0500
commitd0f51b8cb936e550110e44b0dcde4ac4c0f3a282 (patch)
tree83b2d6593ec48913f9c211358ff42ae4d3873812 /src/Build.hs
parentab9d22f9a266ec540bc9b0248f180b26dc185ea6 (diff)
parentb551da522ac590d1d3b81f1183cf7f3d1f8c48ad (diff)
downloadfpm-d0f51b8cb936e550110e44b0dcde4ac4c0f3a282.tar.gz
fpm-d0f51b8cb936e550110e44b0dcde4ac4c0f3a282.zip
Merge pull request #48 from everythingfunctional/SimplifyExampleProject
Simplify example project
Diffstat (limited to 'src/Build.hs')
-rw-r--r--src/Build.hs76
1 files changed, 52 insertions, 24 deletions
diff --git a/src/Build.hs b/src/Build.hs
index e7a43f6..0c692cb 100644
--- a/src/Build.hs
+++ b/src/Build.hs
@@ -1,6 +1,6 @@
module Build
( buildLibrary
- , buildPrograms
+ , buildProgram
)
where
@@ -58,26 +58,35 @@ type ModuleName = String
data LineContents = ModuleUsed ModuleName | Other
-buildPrograms
+buildProgram
:: FilePath
-> [FilePath]
-> [FilePattern]
-> FilePath
-> FilePath
-> [String]
+ -> String
+ -> FilePath
-> IO ()
-buildPrograms programDirectory libraryDirectories sourceExtensions buildDirectory compiler flags
+buildProgram programDirectory libraryDirectories sourceExtensions buildDirectory compiler flags programName programSource
= do
sourceFiles <- getDirectoriesFiles [programDirectory] sourceExtensions
- let sourceFileLookupMap =
- createSourceFileLookupMap buildDirectory programDirectory sourceFiles
- libraryModuleMaps <- mapM getLibraryModuleMap libraryDirectories
- let libraryModuleMap = foldl Map.union Map.empty libraryModuleMaps
- let includeFlags = map ("-I" ++) libraryDirectories
+ let moduleSourceFiles =
+ filter (/= programDirectory </> programSource) sourceFiles
+ let moduleObjectFiles = map
+ (sourceFileToObjectFile buildDirectory programDirectory)
+ moduleSourceFiles
+ let sourceFileLookupMap = createSourceFileLookupMap buildDirectory
+ programDirectory
+ moduleSourceFiles
+ let moduleLookupMap = createModuleLookupMap buildDirectory
+ programDirectory
+ moduleSourceFiles
+ otherModuleMaps <- mapM getLibraryModuleMap libraryDirectories
+ let allModuleMaps =
+ moduleLookupMap `Map.union` foldl Map.union Map.empty otherModuleMaps
+ let includeFlags = map ("-I" ++) libraryDirectories
archives <- getDirectoriesFiles libraryDirectories [".a"]
- let executables = map
- (sourceFileToExecutable buildDirectory programDirectory)
- sourceFiles
shake shakeOptions { shakeFiles = buildDirectory
, shakeChange = ChangeModtimeAndDigest
, shakeColor = True
@@ -85,28 +94,47 @@ buildPrograms programDirectory libraryDirectories sourceExtensions buildDirector
, shakeProgress = progressSimple
}
$ do
- buildDirectory </> "*" <.> "o" %> \objectFile -> do
+ want [buildDirectory </> programName <.> exe]
+ buildDirectory </> programName <.> exe %> \executable -> do
+ let objectFile = sourceFileToObjectFile buildDirectory
+ programDirectory
+ programSource
+ let allObjectFiles = objectFile : moduleObjectFiles
+ need allObjectFiles
+ need archives
+ cmd compiler allObjectFiles archives ["-o", executable] flags
+ buildDirectory </> programSource -<.> "o" %> \objectFile -> do
let realObjectFile = foldl (</>) "" $ splitDirectories objectFile
- let sourceFile = fromMaybe
- undefined
- (Map.lookup realObjectFile sourceFileLookupMap)
+ let sourceFile = programDirectory </> programSource
need [sourceFile]
modulesUsed <- liftIO $ getModulesUsed sourceFile
let moduleFilesNeeded =
- mapMaybe (`Map.lookup` libraryModuleMap) modulesUsed
+ mapMaybe (`Map.lookup` allModuleMaps) modulesUsed
+ let includeFlags = map ("-I" ++) libraryDirectories
need moduleFilesNeeded
cmd compiler
- ["-c"]
+ ["-c", "-J" ++ buildDirectory]
includeFlags
flags
["-o", objectFile, sourceFile]
- (\file -> foldl (</>) "" (splitDirectories file) `elem` executables)
- ?> \exe -> do
- let objectFile = map toLower exe -<.> "o"
- need [objectFile]
- need archives
- cmd compiler objectFile archives ["-o", exe] flags
- want executables
+ map (\ext -> buildDirectory </> "*" <.> ext) ["o", "mod"]
+ &%> \[objectFile, moduleFile] -> do
+ let realObjectFile =
+ foldl (</>) "" $ splitDirectories objectFile
+ let sourceFile = fromMaybe
+ undefined
+ (Map.lookup realObjectFile sourceFileLookupMap)
+ need [sourceFile]
+ modulesUsed <- liftIO $ getModulesUsed sourceFile
+ let moduleFilesNeeded =
+ mapMaybe (`Map.lookup` allModuleMaps) modulesUsed
+ let includeFlags = map ("-I" ++) libraryDirectories
+ need moduleFilesNeeded
+ cmd compiler
+ ["-c", "-J" ++ buildDirectory]
+ includeFlags
+ flags
+ ["-o", objectFile, sourceFile]
buildLibrary
:: FilePath