Skip to content

Commit

Permalink
Added Distribution.Program support for ranlib and ar.
Browse files Browse the repository at this point in the history
Cleaned up calls to these programs so that they're detected at
configure time, and both have --with-ranlib and --ranlib-args flags
(thanks to Distribution.Program support).
  • Loading branch information
SyntaxPolice committed Oct 16, 2005
1 parent 9f4c23e commit fc8e045
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
14 changes: 12 additions & 2 deletions Distribution/Program.hs
Expand Up @@ -15,6 +15,8 @@ module Distribution.Program( Program(..)
, ghcPkgProgram
, nhcProgram
, hugsProgram
, ranlibProgram
, arProgram
, alexProgram
, hsc2hsProgram
, c2hsProgram
Expand Down Expand Up @@ -68,8 +70,9 @@ instance Read ProgramConfiguration where
defaultProgramConfiguration :: ProgramConfiguration
defaultProgramConfiguration = progListToFM
[ haddockProgram
, pfesetupProgram]
-- FIXME: Add ranlib!
, pfesetupProgram
, ranlibProgram
, arProgram]
-- haddock is currently the only one that really works.
{- [ ghcProgram
, ghcPkgProgram
Expand All @@ -84,6 +87,7 @@ defaultProgramConfiguration = progListToFM
, ldProgram
, cppProgram
, pfesetupProgram
, ranlib, ar
]-}

-- |The flag for giving a path to this program. eg --with-alex=\/usr\/bin\/alex
Expand Down Expand Up @@ -119,6 +123,12 @@ hugsProgram = simpleProgram "hugs"
alexProgram :: Program
alexProgram = simpleProgram "alex"

ranlibProgram :: Program
ranlibProgram = simpleProgram "ranlib"

arProgram :: Program
arProgram = simpleProgram "ar"

hsc2hsProgram :: Program
hsc2hsProgram = simpleProgram "hsc2hs"

Expand Down
7 changes: 6 additions & 1 deletion Distribution/Simple/Configure.hs
Expand Up @@ -84,7 +84,8 @@ import System.Directory
import Distribution.Compat.FilePath (splitFileName, joinFileName,
joinFileExt, exeExtension)
import Distribution.Program(Program(..), ProgramLocation(..), lookupProgram,
updateProgram, haddockProgram, pfesetupProgram)
updateProgram, haddockProgram, pfesetupProgram,
ranlibProgram, arProgram)
import System.Cmd ( system )
import System.Exit ( ExitCode(..) )
import Control.Monad ( when, unless )
Expand Down Expand Up @@ -171,6 +172,8 @@ configure pkg_descr cfg
-- FIX: just do a map over all of them :)
haddock <- lookupProgram haddockName (configPrograms cfg)
pfe <- lookupProgram (programName pfesetupProgram) (configPrograms cfg)
ranlib <- lookupProgram (programName ranlibProgram) (configPrograms cfg)
ar <- lookupProgram (programName arProgram) (configPrograms cfg)

happy <- findProgram "happy" (configHappy cfg)
alex <- findProgram "alex" (configAlex cfg)
Expand Down Expand Up @@ -219,6 +222,8 @@ configure pkg_descr cfg

reportProgram' haddockName haddock
reportProgram' (programName pfesetupProgram) pfe
reportProgram' (programName ranlibProgram) ranlib
reportProgram' (programName arProgram) ar
reportProgram "happy" happy
reportProgram "alex" alex
reportProgram "hsc2hs" hsc2hs
Expand Down
43 changes: 28 additions & 15 deletions Distribution/Simple/Install.hs
Expand Up @@ -63,6 +63,9 @@ import Distribution.PackageDescription (
setupMessage, hasLibs, withLib, libModules, withExe,
hcOptions)
import Distribution.Package (showPackageId, PackageIdentifier(pkgName))
import Distribution.Program(ProgramConfiguration, Program(..), ProgramLocation(..),
rawSystemProgram, ranlibProgram,
lookupProgram, arProgram)
import Distribution.Simple.LocalBuildInfo (
LocalBuildInfo(..), mkLibDir, mkBinDir, mkDataDir, mkProgDir)
import Distribution.Simple.Utils(smartCopySources, copyFileVerbose, mkLibName,
Expand Down Expand Up @@ -100,7 +103,7 @@ install pkg_descr lbi (copydest, verbose) = do
let binPref = mkBinDir pkg_descr lbi copydest
setupMessage ("Installing: " ++ libPref ++ " & " ++ binPref) pkg_descr
case compilerFlavor (compiler lbi) of
GHC -> do when (hasLibs pkg_descr) (installLibGHC verbose (withProfLib lbi) (withGHCiLib lbi) libPref buildPref pkg_descr)
GHC -> do when (hasLibs pkg_descr) (installLibGHC verbose (withPrograms lbi) (withProfLib lbi) (withGHCiLib lbi) libPref buildPref pkg_descr)
installExeGhc verbose binPref buildPref pkg_descr
Hugs -> do
let progPref = mkProgDir pkg_descr lbi copydest
Expand All @@ -123,13 +126,15 @@ installExeGhc verbose pref buildPref pkg_descr

-- |Install for ghc, .hi, .a and, if --with-ghci given, .o
installLibGHC :: Int -- ^verbose
-> ProgramConfiguration
-> Bool -- ^has profiling library
-> Bool -- ^has GHCi libs
-> FilePath -- ^install location
-> FilePath -- ^Build location
-> PackageDescription -> IO ()
installLibGHC verbose hasProf hasGHCi pref buildPref pd@PackageDescription{library=Just l,
package=p}
installLibGHC verbose programConf hasProf hasGHCi pref buildPref
pd@PackageDescription{library=Just l,
package=p}
= do smartCopySources verbose [buildPref] pref (libModules pd) ["hi"] True
ifProf $ smartCopySources verbose [buildPref] pref (libModules pd) ["p_hi"] True
let libTargetLoc = mkLibName pref (showPackageId p)
Expand All @@ -142,22 +147,30 @@ installLibGHC verbose hasProf hasGHCi pref buildPref pd@PackageDescription{libra
-- use ranlib or ar -s to build an index. this is necessary
-- on some systems like MacOS X. If we can't find those,
-- don't worry too much about it.
mRanlibLoc <- findExecutable "ranlib"
case mRanlibLoc of
Just ranLibLoc -> do rawSystemVerbose verbose ranLibLoc [libTargetLoc]
ifProf $ rawSystemVerbose verbose ranLibLoc [profLibTargetLoc]
return ()
Nothing -> do mArLoc <- findExecutable "ar"
case mArLoc of
Nothing -> setupMessage "Warning: Unable to generate index for library (missing ranlib and ar)" pd
Just arLoc -> do rawSystemVerbose verbose "ar" ["-s", libTargetLoc]
ifProf $ rawSystemVerbose verbose "ar" ["-s", profLibTargetLoc]
return ()
let progName = programName $ ranlibProgram
mProg <- lookupProgram progName programConf
case foundProg mProg of
Just rl -> do rawSystemProgram verbose rl [libTargetLoc]
ifProf $ rawSystemProgram verbose rl [profLibTargetLoc]

Nothing -> do let progName = programName $ arProgram
mProg <- lookupProgram progName programConf
case mProg of
Just ar -> do rawSystemProgram verbose ar ["-s", libTargetLoc]
ifProf $ rawSystemProgram verbose ar ["-s", profLibTargetLoc]
Nothing -> setupMessage "Warning: Unable to generate index for library (missing ranlib and ar)" pd
return ()
where ifProf action = when hasProf (action >> return ())
ifGHCi action = when hasGHCi (action >> return ())
installLibGHC _ _ _ _ _ PackageDescription{library=Nothing}
installLibGHC _ _ _ _ _ _ PackageDescription{library=Nothing}
= die $ "Internal Error. installLibGHC called with no library."

-- Also checks whether the program was actually found.
foundProg :: Maybe Program -> Maybe Program
foundProg Nothing = Nothing
foundProg (Just Program{programLocation=EmptyLocation}) = Nothing
foundProg x = x

-- Install for Hugs
-- For install, copy-prefix = prefix, but for copy they're different.
-- The library goes in <copy-prefix>/lib/hugs/packages/<pkgname>
Expand Down

0 comments on commit fc8e045

Please sign in to comment.