From c0c70f5c9b87ac0188ee95867e11693fa5d9c22c Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Tue, 17 Mar 2020 22:43:45 +0100 Subject: [PATCH] Abstract over make So on FreeBSD we get gmake. --- lib/GHCup.hs | 22 ++++------------------ lib/GHCup/Utils.hs | 11 ++++++++++- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/lib/GHCup.hs b/lib/GHCup.hs index de6ddaa..54fc2e9 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -140,12 +140,7 @@ installGHCBin bDls ver mpfReq = do [rel|ghc-configure.log|] (Just path) Nothing - lEM $ liftIO $ execLogged [s|make|] - True - [[s|install|]] - [rel|ghc-make.log|] - (Just path) - Nothing + lEM $ liftIO $ make [[s|install|]] (Just path) pure () @@ -541,20 +536,11 @@ GhcWithLlvmCodeGen = YES|] lift $ $(logInfo) [i|Building (this may take a while)... Run 'tail -f ~/.ghcup/logs/ghc-make.log' to see the progress.|] - lEM $ liftIO $ execLogged [s|make|] - True - (maybe [] (\j -> [[s|-j|] <> fS (show j)]) jobs) - [rel|ghc-make.log|] - (Just workdir) - Nothing + lEM $ liftIO $ make (maybe [] (\j -> [[s|-j|] <> fS (show j)]) jobs) + (Just workdir) lift $ $(logInfo) [i|Installing...|] - lEM $ liftIO $ execLogged [s|make|] - True - [[s|install|]] - [rel|ghc-make.log|] - (Just workdir) - Nothing + lEM $ liftIO $ make [[s|install|]] (Just workdir) markSrcBuilt ghcdir workdir = do let dest = (ghcdir ghcUpSrcBuiltFile) diff --git a/lib/GHCup/Utils.hs b/lib/GHCup/Utils.hs index e7b89b0..7396bdb 100644 --- a/lib/GHCup/Utils.hs +++ b/lib/GHCup/Utils.hs @@ -44,7 +44,7 @@ import Prelude hiding ( abs ) import Safe import System.IO.Error -import System.Posix.FilePath ( takeFileName ) +import System.Posix.FilePath ( getSearchPath, takeFileName ) import System.Posix.Files.ByteString ( readSymbolicLink ) import URI.ByteString @@ -325,3 +325,12 @@ ghcToolFiles ver = do -- this GHC was built from source. It contains the build config. ghcUpSrcBuiltFile :: Path Rel ghcUpSrcBuiltFile = [rel|.ghcup_src_built|] + + +-- | Calls gmake if it exists in PATH, otherwise make. +make :: [ByteString] -> Maybe (Path Abs) -> IO (Either ProcessError ()) +make args workdir = do + spaths <- catMaybes . fmap parseAbs <$> getSearchPath + has_gmake <- isJust <$> searchPath spaths [rel|gmake|] + let mymake = if has_gmake then [s|gmake|] else [s|make|] + execLogged mymake True args [rel|ghc-make.log|] workdir Nothing