From 5d122c2854dbec1470a660bf80cd0544a8806a78 Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Wed, 28 Oct 2020 12:49:26 -0500 Subject: Add command line options to specify compiler flags --- bootstrap/src/Fpm.hs | 86 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 26 deletions(-) (limited to 'bootstrap/src/Fpm.hs') diff --git a/bootstrap/src/Fpm.hs b/bootstrap/src/Fpm.hs index 49c7ee8..cfb67df 100644 --- a/bootstrap/src/Fpm.hs +++ b/bootstrap/src/Fpm.hs @@ -43,6 +43,7 @@ import Options.Applicative ( Parser , helper , info , long + , many , metavar , optional , progDesc @@ -81,16 +82,19 @@ data Arguments = | Build { buildRelease :: Bool , buildCompiler :: FilePath + , buildFlags :: [String] } | Run { runRelease :: Bool , runCompiler :: FilePath + , runFlags :: [String] , runTarget :: Maybe String , runArgs :: Maybe String } | Test { testRelease :: Bool , testCompiler :: FilePath + , testFlags :: [String] , testTarget :: Maybe String , testArgs :: Maybe String } @@ -384,6 +388,14 @@ buildArguments = <> help "specify the compiler to use" <> showDefault ) + <*> many + (strOption + ( long "flag" + <> metavar "FLAG" + <> help + "specify an addional argument to pass to the compiler (can appear multiple times)" + ) + ) runArguments :: Parser Arguments runArguments = @@ -399,6 +411,14 @@ runArguments = <> help "specify the compiler to use" <> showDefault ) + <*> many + (strOption + ( long "flag" + <> metavar "FLAG" + <> help + "specify an addional argument to pass to the compiler (can appear multiple times)" + ) + ) <*> optional (strArgument (metavar "TARGET" <> help "Name of the executable to run") @@ -420,6 +440,14 @@ testArguments = <> help "specify the compiler to use" <> showDefault ) + <*> many + (strOption + ( long "flag" + <> metavar "FLAG" + <> help + "specify an addional argument to pass to the compiler (can appear multiple times)" + ) + ) <*> optional (strArgument (metavar "TARGET" <> help "Name of the test to run")) <*> optional (strArgument (metavar "ARGS" <> help "Arguments to the test")) @@ -531,38 +559,44 @@ toml2AppSettings tomlSettings args = do let projectName = tomlSettingsProjectName tomlSettings let compiler = case args of Build { buildCompiler = c } -> c - Run { runCompiler = c } -> c - Test { testCompiler = c } -> c + Run { runCompiler = c } -> c + Test { testCompiler = c } -> c + let specifiedFlags = case args of + Build { buildFlags = f } -> f + Run { runFlags = f } -> f + Test { testFlags = f } -> f librarySettings <- getLibrarySettings $ tomlSettingsLibrary tomlSettings executableSettings <- getExecutableSettings (tomlSettingsExecutables tomlSettings) projectName testSettings <- getTestSettings $ tomlSettingsTests tomlSettings let flags = if compiler == "gfortran" - then if release - then - [ "-Wall" - , "-Wextra" - , "-Wimplicit-interface" - , "-fPIC" - , "-fmax-errors=1" - , "-O3" - , "-march=native" - , "-ffast-math" - , "-funroll-loops" - ] - else - [ "-Wall" - , "-Wextra" - , "-Wimplicit-interface" - , "-fPIC" - , "-fmax-errors=1" - , "-g" - , "-fbounds-check" - , "-fcheck-array-temporaries" - , "-fbacktrace" - ] - else [] + then case specifiedFlags of + [] -> if release + then + [ "-Wall" + , "-Wextra" + , "-Wimplicit-interface" + , "-fPIC" + , "-fmax-errors=1" + , "-O3" + , "-march=native" + , "-ffast-math" + , "-funroll-loops" + ] + else + [ "-Wall" + , "-Wextra" + , "-Wimplicit-interface" + , "-fPIC" + , "-fmax-errors=1" + , "-g" + , "-fbounds-check" + , "-fcheck-array-temporaries" + , "-fbacktrace" + ] + flags -> flags + else specifiedFlags buildPrefix <- makeBuildPrefix compiler flags let dependencies = tomlSettingsDependencies tomlSettings let devDependencies = tomlSettingsDevDependencies tomlSettings -- cgit v1.2.3