Skip to content

Commit 3c6440b

Browse files
Refactor flag definition for easier support of other compilers
1 parent b38b29f commit 3c6440b

File tree

1 file changed

+11
-27
lines changed

1 file changed

+11
-27
lines changed

bootstrap/src/Fpm.hs

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Control.Monad.Extra ( concatMapM
1818
)
1919
import Data.Hashable ( hash )
2020
import Data.List ( intercalate
21+
, isInfixOf
2122
, isSuffixOf
2223
, find
2324
, nub
@@ -590,33 +591,7 @@ toml2AppSettings tomlSettings args = do
590591
(tomlSettingsExecutables tomlSettings)
591592
projectName
592593
testSettings <- getTestSettings $ tomlSettingsTests tomlSettings
593-
let flags = if compiler == "gfortran"
594-
then case specifiedFlags of
595-
[] -> if release
596-
then
597-
[ "-Wall"
598-
, "-Wextra"
599-
, "-Wimplicit-interface"
600-
, "-fPIC"
601-
, "-fmax-errors=1"
602-
, "-O3"
603-
, "-march=native"
604-
, "-ffast-math"
605-
, "-funroll-loops"
606-
]
607-
else
608-
[ "-Wall"
609-
, "-Wextra"
610-
, "-Wimplicit-interface"
611-
, "-fPIC"
612-
, "-fmax-errors=1"
613-
, "-g"
614-
, "-fbounds-check"
615-
, "-fcheck-array-temporaries"
616-
, "-fbacktrace"
617-
]
618-
flags -> flags
619-
else specifiedFlags
594+
flags <- defineFlags specifiedFlags compiler release
620595
buildPrefix <- makeBuildPrefix compiler flags
621596
let dependencies = tomlSettingsDependencies tomlSettings
622597
let devDependencies = tomlSettingsDevDependencies tomlSettings
@@ -631,6 +606,15 @@ toml2AppSettings tomlSettings args = do
631606
, appSettingsDevDependencies = devDependencies
632607
}
633608

609+
defineFlags :: [String] -> FilePath -> Bool -> IO [String]
610+
defineFlags [] compiler release
611+
| "gfortran" `isInfixOf` compiler = return $ 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"]
612+
| "caf" `isInfixOf` compiler = return $ 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"]
613+
| otherwise = do
614+
putStrLn $ "Sorry, compiler is currently unsupported: " ++ compiler
615+
exitWith (ExitFailure 1)
616+
defineFlags specifiedFlags _ _ = return specifiedFlags
617+
634618
getLibrarySettings :: Maybe Library -> IO (Maybe Library)
635619
getLibrarySettings maybeSettings = case maybeSettings of
636620
Just settings -> return maybeSettings

0 commit comments

Comments
 (0)