Skip to content

Commit 5d122c2

Browse files
Add command line options to specify compiler flags
1 parent 7b191a7 commit 5d122c2

File tree

2 files changed

+67
-26
lines changed

2 files changed

+67
-26
lines changed

bootstrap/src/Fpm.hs

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import Options.Applicative ( Parser
4343
, helper
4444
, info
4545
, long
46+
, many
4647
, metavar
4748
, optional
4849
, progDesc
@@ -81,16 +82,19 @@ data Arguments =
8182
| Build
8283
{ buildRelease :: Bool
8384
, buildCompiler :: FilePath
85+
, buildFlags :: [String]
8486
}
8587
| Run
8688
{ runRelease :: Bool
8789
, runCompiler :: FilePath
90+
, runFlags :: [String]
8891
, runTarget :: Maybe String
8992
, runArgs :: Maybe String
9093
}
9194
| Test
9295
{ testRelease :: Bool
9396
, testCompiler :: FilePath
97+
, testFlags :: [String]
9498
, testTarget :: Maybe String
9599
, testArgs :: Maybe String
96100
}
@@ -384,6 +388,14 @@ buildArguments =
384388
<> help "specify the compiler to use"
385389
<> showDefault
386390
)
391+
<*> many
392+
(strOption
393+
( long "flag"
394+
<> metavar "FLAG"
395+
<> help
396+
"specify an addional argument to pass to the compiler (can appear multiple times)"
397+
)
398+
)
387399

388400
runArguments :: Parser Arguments
389401
runArguments =
@@ -399,6 +411,14 @@ runArguments =
399411
<> help "specify the compiler to use"
400412
<> showDefault
401413
)
414+
<*> many
415+
(strOption
416+
( long "flag"
417+
<> metavar "FLAG"
418+
<> help
419+
"specify an addional argument to pass to the compiler (can appear multiple times)"
420+
)
421+
)
402422
<*> optional
403423
(strArgument
404424
(metavar "TARGET" <> help "Name of the executable to run")
@@ -420,6 +440,14 @@ testArguments =
420440
<> help "specify the compiler to use"
421441
<> showDefault
422442
)
443+
<*> many
444+
(strOption
445+
( long "flag"
446+
<> metavar "FLAG"
447+
<> help
448+
"specify an addional argument to pass to the compiler (can appear multiple times)"
449+
)
450+
)
423451
<*> optional
424452
(strArgument (metavar "TARGET" <> help "Name of the test to run"))
425453
<*> optional (strArgument (metavar "ARGS" <> help "Arguments to the test"))
@@ -531,38 +559,44 @@ toml2AppSettings tomlSettings args = do
531559
let projectName = tomlSettingsProjectName tomlSettings
532560
let compiler = case args of
533561
Build { buildCompiler = c } -> c
534-
Run { runCompiler = c } -> c
535-
Test { testCompiler = c } -> c
562+
Run { runCompiler = c } -> c
563+
Test { testCompiler = c } -> c
564+
let specifiedFlags = case args of
565+
Build { buildFlags = f } -> f
566+
Run { runFlags = f } -> f
567+
Test { testFlags = f } -> f
536568
librarySettings <- getLibrarySettings $ tomlSettingsLibrary tomlSettings
537569
executableSettings <- getExecutableSettings
538570
(tomlSettingsExecutables tomlSettings)
539571
projectName
540572
testSettings <- getTestSettings $ tomlSettingsTests tomlSettings
541573
let flags = if compiler == "gfortran"
542-
then if release
543-
then
544-
[ "-Wall"
545-
, "-Wextra"
546-
, "-Wimplicit-interface"
547-
, "-fPIC"
548-
, "-fmax-errors=1"
549-
, "-O3"
550-
, "-march=native"
551-
, "-ffast-math"
552-
, "-funroll-loops"
553-
]
554-
else
555-
[ "-Wall"
556-
, "-Wextra"
557-
, "-Wimplicit-interface"
558-
, "-fPIC"
559-
, "-fmax-errors=1"
560-
, "-g"
561-
, "-fbounds-check"
562-
, "-fcheck-array-temporaries"
563-
, "-fbacktrace"
564-
]
565-
else []
574+
then case specifiedFlags of
575+
[] -> if release
576+
then
577+
[ "-Wall"
578+
, "-Wextra"
579+
, "-Wimplicit-interface"
580+
, "-fPIC"
581+
, "-fmax-errors=1"
582+
, "-O3"
583+
, "-march=native"
584+
, "-ffast-math"
585+
, "-funroll-loops"
586+
]
587+
else
588+
[ "-Wall"
589+
, "-Wextra"
590+
, "-Wimplicit-interface"
591+
, "-fPIC"
592+
, "-fmax-errors=1"
593+
, "-g"
594+
, "-fbounds-check"
595+
, "-fcheck-array-temporaries"
596+
, "-fbacktrace"
597+
]
598+
flags -> flags
599+
else specifiedFlags
566600
buildPrefix <- makeBuildPrefix compiler flags
567601
let dependencies = tomlSettingsDependencies tomlSettings
568602
let devDependencies = tomlSettingsDevDependencies tomlSettings

bootstrap/test/Spec.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ testHelloWorld =
2121
withCurrentDirectory (example_path </> "hello_world") $ start $ Run
2222
{ runRelease = False
2323
, runCompiler = "gfortran"
24+
, runFlags = []
2425
, runTarget = Nothing
2526
, runArgs = Nothing
2627
}
@@ -30,6 +31,7 @@ testHelloComplex =
3031
withCurrentDirectory (example_path </> "hello_complex") $ start $ Test
3132
{ testRelease = False
3233
, testCompiler = "gfortran"
34+
, testFlags = []
3335
, testTarget = Nothing
3436
, testArgs = Nothing
3537
}
@@ -39,6 +41,7 @@ testHelloFpm =
3941
withCurrentDirectory (example_path </> "hello_fpm") $ start $ Run
4042
{ runRelease = False
4143
, runCompiler = "gfortran"
44+
, runFlags = []
4245
, runTarget = Nothing
4346
, runArgs = Nothing
4447
}
@@ -48,6 +51,7 @@ testCircular =
4851
withCurrentDirectory (example_path </> "circular_example") $ start $ Test
4952
{ testRelease = False
5053
, testCompiler = "gfortran"
54+
, testFlags = []
5155
, testTarget = Nothing
5256
, testArgs = Nothing
5357
}
@@ -57,13 +61,15 @@ testWithMakefile =
5761
withCurrentDirectory (example_path </> "with_makefile") $ start $ Build
5862
{ buildRelease = False
5963
, buildCompiler = "gfortran"
64+
, buildFlags = []
6065
}
6166

6267
testMakefileComplex :: IO ()
6368
testMakefileComplex =
6469
withCurrentDirectory (example_path </> "makefile_complex") $ start $ Run
6570
{ runRelease = False
6671
, runCompiler = "gfortran"
72+
, runFlags = []
6773
, runTarget = Nothing
6874
, runArgs = Nothing
6975
}
@@ -73,4 +79,5 @@ testSubmodule =
7379
withCurrentDirectory (example_path </> "submodules") $ start $ Build
7480
{ buildRelease = False
7581
, buildCompiler = "gfortran"
82+
, buildFlags = []
7683
}

0 commit comments

Comments
 (0)