@@ -16,7 +16,7 @@ import Control.Monad.Extra ( concatMapM
16
16
, forM_
17
17
, when
18
18
)
19
- import Data.Hashable ( hash )
19
+ import Data.Hashable ( hash )
20
20
import Data.List ( isSuffixOf
21
21
, find
22
22
, nub
@@ -46,6 +46,8 @@ import Options.Applicative ( Parser
46
46
, metavar
47
47
, optional
48
48
, progDesc
49
+ , short
50
+ , showDefault
49
51
, strArgument
50
52
, strOption
51
53
, subparser
@@ -77,14 +79,18 @@ data Arguments =
77
79
, newWithLib :: Bool
78
80
}
79
81
| Build
80
- { buildRelease :: Bool }
82
+ { buildRelease :: Bool
83
+ , buildCompiler :: FilePath
84
+ }
81
85
| Run
82
86
{ runRelease :: Bool
87
+ , runCompiler :: FilePath
83
88
, runTarget :: Maybe String
84
89
, runArgs :: Maybe String
85
90
}
86
91
| Test
87
92
{ testRelease :: Bool
93
+ , testCompiler :: FilePath
88
94
, testTarget :: Maybe String
89
95
, testArgs :: Maybe String
90
96
}
@@ -365,8 +371,19 @@ newArguments =
365
371
<*> switch (long " lib" <> help " Include a library" )
366
372
367
373
buildArguments :: Parser Arguments
368
- buildArguments = Build <$> switch
369
- (long " release" <> help " Build with optimizations instead of debugging" )
374
+ buildArguments =
375
+ Build
376
+ <$> switch
377
+ ( long " release"
378
+ <> help " Build with optimizations instead of debugging"
379
+ )
380
+ <*> strOption
381
+ ( long " compiler"
382
+ <> metavar " COMPILER"
383
+ <> value " gfortran"
384
+ <> help " specify the compiler to use"
385
+ <> showDefault
386
+ )
370
387
371
388
runArguments :: Parser Arguments
372
389
runArguments =
@@ -375,6 +392,13 @@ runArguments =
375
392
( long " release"
376
393
<> help " Build with optimizations instead of debugging"
377
394
)
395
+ <*> strOption
396
+ ( long " compiler"
397
+ <> metavar " COMPILER"
398
+ <> value " gfortran"
399
+ <> help " specify the compiler to use"
400
+ <> showDefault
401
+ )
378
402
<*> optional
379
403
(strArgument
380
404
(metavar " TARGET" <> help " Name of the executable to run" )
@@ -389,6 +413,13 @@ testArguments =
389
413
( long " release"
390
414
<> help " Build with optimizations instead of debugging"
391
415
)
416
+ <*> strOption
417
+ ( long " compiler"
418
+ <> metavar " COMPILER"
419
+ <> value " gfortran"
420
+ <> help " specify the compiler to use"
421
+ <> showDefault
422
+ )
392
423
<*> optional
393
424
(strArgument (metavar " TARGET" <> help " Name of the test to run" ))
394
425
<*> optional (strArgument (metavar " ARGS" <> help " Arguments to the test" ))
@@ -498,49 +529,53 @@ toml2AppSettings tomlSettings args = do
498
529
Run { runRelease = r } -> r
499
530
Test { testRelease = r } -> r
500
531
let projectName = tomlSettingsProjectName tomlSettings
501
- let compiler = " gfortran"
532
+ let compiler = case args of
533
+ Build { buildCompiler = c } -> c
534
+ Run { runCompiler = c } -> c
535
+ Test { testCompiler = c } -> c
502
536
librarySettings <- getLibrarySettings $ tomlSettingsLibrary tomlSettings
503
537
executableSettings <- getExecutableSettings
504
538
(tomlSettingsExecutables tomlSettings)
505
539
projectName
506
540
testSettings <- getTestSettings $ tomlSettingsTests tomlSettings
507
- let flags = if release
508
- then
509
- [ " -Wall"
510
- , " -Wextra"
511
- , " -Wimplicit-interface"
512
- , " -fPIC"
513
- , " -fmax-errors=1"
514
- , " -O3"
515
- , " -march=native"
516
- , " -ffast-math"
517
- , " -funroll-loops"
518
- ]
519
- else
520
- [ " -Wall"
521
- , " -Wextra"
522
- , " -Wimplicit-interface"
523
- , " -fPIC"
524
- , " -fmax-errors=1"
525
- , " -g"
526
- , " -fbounds-check"
527
- , " -fcheck-array-temporaries"
528
- , " -fbacktrace"
529
- ]
530
- buildPrefix <- makeBuildPrefix compiler flags
541
+ 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 []
566
+ buildPrefix <- makeBuildPrefix compiler flags
531
567
let dependencies = tomlSettingsDependencies tomlSettings
532
568
let devDependencies = tomlSettingsDevDependencies tomlSettings
533
- return AppSettings
534
- { appSettingsCompiler = compiler
535
- , appSettingsProjectName = projectName
536
- , appSettingsBuildPrefix = buildPrefix
537
- , appSettingsFlags = flags
538
- , appSettingsLibrary = librarySettings
539
- , appSettingsExecutables = executableSettings
540
- , appSettingsTests = testSettings
541
- , appSettingsDependencies = dependencies
542
- , appSettingsDevDependencies = devDependencies
543
- }
569
+ return AppSettings { appSettingsCompiler = compiler
570
+ , appSettingsProjectName = projectName
571
+ , appSettingsBuildPrefix = buildPrefix
572
+ , appSettingsFlags = flags
573
+ , appSettingsLibrary = librarySettings
574
+ , appSettingsExecutables = executableSettings
575
+ , appSettingsTests = testSettings
576
+ , appSettingsDependencies = dependencies
577
+ , appSettingsDevDependencies = devDependencies
578
+ }
544
579
545
580
getLibrarySettings :: Maybe Library -> IO (Maybe Library )
546
581
getLibrarySettings maybeSettings = case maybeSettings of
@@ -596,9 +631,15 @@ makeBuildPrefix compiler flags = do
596
631
-- Probably version, and make sure to not include path to the compiler
597
632
versionInfo <- readProcess compiler [" --version" ] []
598
633
let compilerName = last (splitDirectories compiler)
599
- let versionHash = hash versionInfo
600
- let flagsHash = hash flags
601
- return $ " build" </> compilerName ++ " _" ++ show versionHash ++ " _" ++ show flagsHash
634
+ let versionHash = hash versionInfo
635
+ let flagsHash = hash flags
636
+ return
637
+ $ " build"
638
+ </> compilerName
639
+ ++ " _"
640
+ ++ show versionHash
641
+ ++ " _"
642
+ ++ show flagsHash
602
643
603
644
{-
604
645
Fetching the dependencies is done on a sort of breadth first approach. All
0 commit comments