summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2021-10-27 01:10:55 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-11-17 05:11:03 -0500
commit20a4f2513d67a454edaa207bac97a9dd6f4db757 (patch)
tree555b7e72e4567fe666dc1c1a257bf14adf1ffd8f
parent083a7583d70c190b090fedcf9f955eff65d4baeb (diff)
downloadhaskell-20a4f2513d67a454edaa207bac97a9dd6f4db757.tar.gz
hadrian: Factor out --extra-*-dirs=... pattern
We repeated this idiom quite a few times. Give it a name.
-rw-r--r--hadrian/src/Settings/Packages.hs28
1 files changed, 19 insertions, 9 deletions
diff --git a/hadrian/src/Settings/Packages.hs b/hadrian/src/Settings/Packages.hs
index bcdd62191a..416e3bd430 100644
--- a/hadrian/src/Settings/Packages.hs
+++ b/hadrian/src/Settings/Packages.hs
@@ -210,10 +210,7 @@ ghcBignumArgs = package ghcBignum ? do
-- Ensure that the ghc-bignum package registration includes
-- knowledge of the system gmp's library and include directories.
- , notM (flag GmpInTree) ? mconcat
- [ if not (null librariesGmp) then arg ("--extra-lib-dirs=" ++ librariesGmp) else mempty
- , if not (null includesGmp) then arg ("--extra-include-dirs=" ++ includesGmp) else mempty
- ]
+ , notM (flag GmpInTree) ? cabalExtraDirs includesGmp librariesGmp
]
]
_ -> mempty
@@ -357,11 +354,9 @@ rtsPackageArgs = package rts ? do
, Debug `wayUnit` way `cabalFlag` "find-ptr"
]
, builder (Cabal Setup) ? mconcat
- [ if not (null libdwLibraryDir) then arg ("--extra-lib-dirs="++libdwLibraryDir) else mempty
- , if not (null libdwIncludeDir) then arg ("--extra-include-dirs="++libdwIncludeDir) else mempty
- , if not (null libnumaLibraryDir) then arg ("--extra-lib-dirs="++libnumaLibraryDir) else mempty
- , if not (null libnumaIncludeDir) then arg ("--extra-include-dirs="++libnumaIncludeDir) else mempty
- ]
+ [ cabalExtraDirs libdwIncludeDir libdwLibraryDir
+ , cabalExtraDirs libnumaIncludeDir libnumaLibraryDir
+ ]
, builder (Cc (FindCDependencies CDep)) ? cArgs
, builder (Cc (FindCDependencies CxxDep)) ? cArgs
, builder (Ghc CompileCWithGhc) ? map ("-optc" ++) <$> cArgs
@@ -429,3 +424,18 @@ rtsWarnings = mconcat
, arg "-Wredundant-decls"
, arg "-Wundef"
, arg "-fno-strict-aliasing" ]
+
+-- | Expands to Cabal `--extra-lib-dirs` and `--extra-include-dirs` flags if
+-- the respective paths are not null.
+cabalExtraDirs :: FilePath -- ^ include path
+ -> FilePath -- ^ libraries path
+ -> Args
+cabalExtraDirs include lib = mconcat
+ [ extraDirFlag "--extra-lib-dirs" lib
+ , extraDirFlag "--extra-include-dirs" include
+ ]
+ where
+ extraDirFlag :: String -> FilePath -> Args
+ extraDirFlag flag dir
+ | null dir = mempty
+ | otherwise = arg (flag++"="++dir)