diff options
author | Ben Gamari <ben@smart-cactus.org> | 2021-10-27 01:10:55 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2021-10-27 01:14:19 -0400 |
commit | 5ccff22d66c20e9bd9ba5a9166613967b9b329cb (patch) | |
tree | cadce7ba20d9f6fede1cb02c115b4f59a8f9c5ae | |
parent | 98aa29d3fe447cce3407e6864b015892244bb475 (diff) | |
download | haskell-5ccff22d66c20e9bd9ba5a9166613967b9b329cb.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.hs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/hadrian/src/Settings/Packages.hs b/hadrian/src/Settings/Packages.hs index 1a3d191c99..c8258db82f 100644 --- a/hadrian/src/Settings/Packages.hs +++ b/hadrian/src/Settings/Packages.hs @@ -214,10 +214,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 @@ -361,11 +358,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 @@ -433,3 +428,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) |