Commit edd539fc authored by Ben Gamari's avatar Ben Gamari 🐢 Committed by Andrey Mokhov
Browse files

Various portability fixes (#331)

* Don't assume location of bash interpreter

* Pass curses library directory path to configure
parent ae7358b5
......@@ -104,6 +104,8 @@ conf-ld-linker-args-stage2 = @CONF_LD_LINKER_OPTS_STAGE2@
# Include and library directories:
#=================================
curses-lib-dir = @CURSES_LIB_DIRS@
iconv-include-dir = @ICONV_INCLUDE_DIRS@
iconv-lib-dir = @ICONV_LIB_DIRS@
......
......@@ -52,6 +52,7 @@ data Setting = BuildArch
| GmpLibDir
| IconvIncludeDir
| IconvLibDir
| CursesLibDir
-- Paths to where GHC is installed
-- ref: mk/install.mk
| InstallPrefix
......@@ -73,6 +74,7 @@ data SettingList = ConfCcArgs Stage
| ConfLdLinkerArgs Stage
| HsCppArgs
-- | Maps 'Setting's to names in @cfg/system.config.in@.
setting :: Setting -> Action String
setting key = unsafeAskConfig $ case key of
BuildArch -> "build-arch"
......@@ -109,6 +111,7 @@ setting key = unsafeAskConfig $ case key of
GmpLibDir -> "gmp-lib-dir"
IconvIncludeDir -> "iconv-include-dir"
IconvLibDir -> "iconv-lib-dir"
CursesLibDir -> "curses-lib-dir"
InstallPrefix -> "install-prefix"
InstallBinDir -> "install-bindir"
InstallLibDir -> "install-libdir"
......
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Oracles.Path (
topDirectory, getTopDirectory, systemBuilderPath, pathOracle
topDirectory, getTopDirectory, systemBuilderPath, pathOracle, bashPath
) where
import Control.Monad.Trans.Reader
......@@ -28,7 +28,7 @@ systemBuilderPath builder = case builder of
Cc _ Stage0 -> fromKey "system-cc"
Cc _ _ -> fromKey "cc"
-- We can't ask configure for the path to configure!
Configure _ -> return "bash configure"
Configure _ -> return "sh configure"
Ghc _ Stage0 -> fromKey "system-ghc"
GhcPkg _ Stage0 -> fromKey "system-ghc-pkg"
Happy -> fromKey "happy"
......@@ -55,6 +55,10 @@ systemBuilderPath builder = case builder of
return "" -- TODO: Use a safe interface.
else fixAbsolutePathOnWindows =<< lookupInPath path
-- | Lookup the path to the @bash@ interpreter.
bashPath :: Action FilePath
bashPath = lookupInPath "bash"
-- | Lookup an executable in @PATH@.
lookupInPath :: FilePath -> Action FilePath
lookupInPath name
......@@ -95,4 +99,3 @@ pathOracle = do
path <- unifyPath <$> unpack <$> liftIO (findExecutable name)
putLoud $ "Executable found: " ++ name ++ " => " ++ path
return path
......@@ -7,7 +7,7 @@ import Expression
import GHC
import Settings.Install (installPackageDbDirectory)
import Settings.Path (inplacePackageDbDirectory)
import Oracles.Path (getTopDirectory)
import Oracles.Path (getTopDirectory, bashPath)
import Oracles.Config.Setting (SettingList(..), settingList)
-- | Wrapper is an expression depending on the 'FilePath' to the
......@@ -22,16 +22,18 @@ type Wrapper = WrappedBinary -> Expr String
ghcWrapper :: WrappedBinary -> Expr String
ghcWrapper WrappedBinary{..} = do
lift $ need [sourcePath -/- "Rules/Wrappers.hs"]
bash <- lift bashPath
return $ unlines
[ "#!/bin/bash"
[ "#!"++bash
, "exec " ++ (binaryLibPath -/- "bin" -/- binaryName)
++ " -B" ++ binaryLibPath ++ " ${1+\"$@\"}" ]
inplaceRunGhcWrapper :: WrappedBinary -> Expr String
inplaceRunGhcWrapper WrappedBinary{..} = do
lift $ need [sourcePath -/- "Rules/Wrappers.hs"]
bash <- lift bashPath
return $ unlines
[ "#!/bin/bash"
[ "#!"++bash
, "exec " ++ (binaryLibPath -/- "bin" -/- binaryName)
++ " -f" ++ (binaryLibPath -/- "bin/ghc-stage2") -- TODO: use ProgramName
++ " -B" ++ binaryLibPath ++ " ${1+\"$@\"}" ]
......@@ -39,8 +41,9 @@ inplaceRunGhcWrapper WrappedBinary{..} = do
installRunGhcWrapper :: WrappedBinary -> Expr String
installRunGhcWrapper WrappedBinary{..} = do
lift $ need [sourcePath -/- "Rules/Wrappers.hs"]
bash <- lift bashPath
return $ unlines
[ "#!/bin/bash"
[ "#!"++bash
, "exec " ++ (binaryLibPath -/- "bin" -/- binaryName)
++ " -f" ++ (binaryLibPath -/- "bin/ghc") -- TODO: use ProgramName
++ " -B" ++ binaryLibPath ++ " ${1+\"$@\"}" ]
......@@ -53,8 +56,9 @@ inplaceGhcPkgWrapper WrappedBinary{..} = do
-- Use the package configuration for the next stage in the wrapper.
-- The wrapper is generated in StageN, but used in StageN+1.
let packageDb = top -/- inplacePackageDbDirectory (succ stage)
bash <- lift bashPath
return $ unlines
[ "#!/bin/bash"
[ "#!"++bash
, "exec " ++ (binaryLibPath -/- "bin" -/- binaryName)
++ " --global-package-db " ++ packageDb ++ " ${1+\"$@\"}" ]
......@@ -66,23 +70,26 @@ installGhcPkgWrapper WrappedBinary{..} = do
-- Use the package configuration for the next stage in the wrapper.
-- The wrapper is generated in StageN, but used in StageN+1.
let packageDb = installPackageDbDirectory binaryLibPath top (succ stage)
bash <- lift bashPath
return $ unlines
[ "#!/bin/bash"
[ "#!"++bash
, "exec " ++ (binaryLibPath -/- "bin" -/- binaryName)
++ " --global-package-db " ++ packageDb ++ " ${1+\"$@\"}" ]
hp2psWrapper :: WrappedBinary -> Expr String
hp2psWrapper WrappedBinary{..} = do
lift $ need [sourcePath -/- "Rules/Wrappers.hs"]
bash <- lift bashPath
return $ unlines
[ "#!/bin/bash"
[ "#!"++bash
, "exec " ++ (binaryLibPath -/- "bin" -/- binaryName) ++ " ${1+\"$@\"}" ]
hpcWrapper :: WrappedBinary -> Expr String
hpcWrapper WrappedBinary{..} = do
lift $ need [sourcePath -/- "Rules/Wrappers.hs"]
bash <- lift bashPath
return $ unlines
[ "#!/bin/bash"
[ "#!"++bash
, "exec " ++ (binaryLibPath -/- "bin" -/- binaryName) ++ " ${1+\"$@\"}" ]
hsc2hsWrapper :: WrappedBinary -> Expr String
......@@ -95,8 +102,9 @@ hsc2hsWrapper WrappedBinary{..} = do
confGccLinkerArgs <- lift $ settingList (ConfGccLinkerArgs Stage1)
let hsc2hsExtra = unwords (map ("-cflags=" ++) confCcArgs) ++ " " ++
unwords (map ("-lflags=" ++) confGccLinkerArgs)
bash <- lift bashPath
return $ unlines
[ "#!/bin/bash"
[ "#!"++bash
, "executablename=\"" ++ executableName ++ "\""
, "HSC2HS_EXTRA=\"" ++ hsc2hsExtra ++ "\""
, contents ]
......
......@@ -77,6 +77,7 @@ configureArgs = do
, conf "--with-iconv-libraries" $ argSetting IconvLibDir
, conf "--with-gmp-includes" $ argSetting GmpIncludeDir
, conf "--with-gmp-libraries" $ argSetting GmpLibDir
, conf "--with-curses-libraries" $ argSetting CursesLibDir
, crossCompiling ? (conf "--host" $ argSetting TargetPlatformFull)
, conf "--with-cc" $ argStagedBuilderPath (Cc CompileC) ]
......
......@@ -63,8 +63,10 @@ customBuild rs opts target@Target {..} = do
cmd [Cwd output] [path] "x" (top -/- input)
Configure dir -> do
-- Inject /bin/bash into `libtool`, instead of /bin/sh
let env = AddEnv "CONFIG_SHELL" "/bin/bash"
-- Inject /bin/bash into `libtool`, instead of /bin/sh, otherwise Windows breaks.
-- TODO: Figure out why.
bash <- bashPath
let env = AddEnv "CONFIG_SHELL" bash
cmd Shell cmdEcho env [Cwd dir] [path] opts argList
HsCpp -> captureStdout target path argList
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment