aboutsummaryrefslogtreecommitdiff
path: root/app/Main.hs
diff options
context:
space:
mode:
authorBrad Richardson <brichardson@structint.com>2020-04-11 15:26:40 -0500
committerBrad Richardson <brichardson@structint.com>2020-04-11 15:26:40 -0500
commitfde13b66701956a53282f558d79a8ddbfca0c905 (patch)
tree5d229ec82684ee69bcf665e5bb8ebfd7a4808cce /app/Main.hs
parenta65fed0b63ca301882c3d2a44a73cb413ac92c3f (diff)
downloadfpm-fde13b66701956a53282f558d79a8ddbfca0c905.tar.gz
fpm-fde13b66701956a53282f558d79a8ddbfca0c905.zip
Enable default settings for executables
Diffstat (limited to 'app/Main.hs')
-rw-r--r--app/Main.hs29
1 files changed, 23 insertions, 6 deletions
diff --git a/app/Main.hs b/app/Main.hs
index b951ad8..66dedb8 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -28,7 +28,9 @@ import Options.Applicative ( Parser
, subparser
, switch
)
-import System.Directory ( doesDirectoryExist )
+import System.Directory ( doesDirectoryExist
+ , doesFileExist
+ )
import Toml ( TomlCodec
, (.=)
)
@@ -177,12 +179,14 @@ executableCodec =
toml2AppSettings :: TomlSettings -> Bool -> IO AppSettings
toml2AppSettings tomlSettings release = do
+ let projectName = tomlSettingsProjectName tomlSettings
librarySettings <- getLibrarySettings $ tomlSettingsLibrary tomlSettings
executableSettings <- getExecutableSettings
- $ tomlSettingsExecutables tomlSettings
+ (tomlSettingsExecutables tomlSettings)
+ projectName
return AppSettings
{ appSettingsCompiler = tomlSettingsCompiler tomlSettings
- , appSettingsProjectName = tomlSettingsProjectName tomlSettings
+ , appSettingsProjectName = projectName
, appSettingsFlags = if release
then
[ "-Wall"
@@ -221,6 +225,19 @@ getLibrarySettings maybeSettings = case maybeSettings of
then return (Just (Library { librarySourceDir = "src" }))
else return Nothing
-getExecutableSettings :: [Executable] -> IO [Executable]
-getExecutableSettings [] = undefined
-getExecutableSettings executables = return executables
+getExecutableSettings :: [Executable] -> Text -> IO [Executable]
+getExecutableSettings [] projectName = do
+ defaultDirectoryExists <- doesDirectoryExist "app"
+ if defaultDirectoryExists
+ then do
+ defaultMainExists <- doesFileExist ("app" </> "main.f90")
+ if defaultMainExists
+ then return
+ [ Executable { executableSourceDir = "app"
+ , executableMainFile = "main.f90"
+ , executableName = projectName
+ }
+ ]
+ else return []
+ else return []
+getExecutableSettings executables _ = return executables