Commit 104de038 authored by simonmar's avatar simonmar
Browse files

Add --with-hc-pkg; some Windows fixes

* Add --with-hc-pkg flag to specify the hc-pkg path separately from
  the compiler
* #include config.h where necessary to get the definition of
  mingw32_TARGET_OS.
* Flush stdout before writing to stderr on Windows (gets some
  messages in the right order).
parent 61d176bd
......@@ -101,11 +101,12 @@ data Action = ConfigCmd ConfigFlags -- config
type ConfigFlags = (Maybe CompilerFlavor,
Maybe FilePath, -- given compiler location
Maybe FilePath, -- given hc-pkg location
Maybe FilePath) -- prefix
-- |Most of these flags are for Configure, but InstPrefix is for Install.
data Flag a = GhcFlag | NhcFlag | HugsFlag
| WithCompiler FilePath | Prefix FilePath
| WithCompiler FilePath | WithHcPkg FilePath | Prefix FilePath
| UserFlag | GlobalFlag
| HelpFlag
-- For install:
......@@ -199,10 +200,12 @@ configureCmd = Cmd {
Option "" ["hugs"] (NoArg HugsFlag) "compile with hugs",
Option "w" ["with-compiler"] (ReqArg WithCompiler "PATH")
"give the path to a particular compiler",
Option "w" ["with-hc-pkg"] (ReqArg WithHcPkg "PATH")
"give the path to the package tool",
Option "" ["prefix"] (ReqArg Prefix "DIR")
"bake this prefix in preparation of installation"
],
cmdAction = ConfigCmd (Nothing, Nothing, Nothing)
cmdAction = ConfigCmd (Nothing, Nothing, Nothing, Nothing)
}
parseConfigureArgs :: ConfigFlags -> [String] -> [OptDescr a] ->
......@@ -216,13 +219,14 @@ parseConfigureArgs cfg args customOpts =
return (updateCfg flags cfg, unliftFlags flags, args')
(_, _, errs) -> do mapM_ putStrLn errs
exitWith (ExitFailure 1)
where updateCfg (fl:flags) t@(mcf, mpath, mprefix) = updateCfg flags $
where updateCfg (fl:flags) t@(mcf, mpath, mhcpkg, mprefix) = updateCfg flags $
case fl of
GhcFlag -> (Just GHC, mpath, mprefix)
NhcFlag -> (Just NHC, mpath, mprefix)
HugsFlag -> (Just Hugs, mpath, mprefix)
WithCompiler path -> (mcf, Just path, mprefix)
Prefix path -> (mcf, mpath, Just path)
GhcFlag -> (Just GHC, mpath, mhcpkg, mprefix)
NhcFlag -> (Just NHC, mpath, mhcpkg, mprefix)
HugsFlag -> (Just Hugs, mpath, mhcpkg, mprefix)
WithCompiler path -> (mcf, Just path, mhcpkg, mprefix)
WithHcPkg path -> (mcf, mpath, Just path, mprefix)
Prefix path -> (mcf, mpath, mhcpkg, Just path)
Lift _ -> t
_ -> error $ "Unexpected flag!"
updateCfg [] t = t
......
......@@ -53,6 +53,10 @@ module Distribution.Simple.Configure (writePersistBuildConfig,
)
where
#if __GLASGOW_HASKELL__ < 603
#include "config.h"
#endif
import Distribution.Misc(Dependency(..), Extension(..),
extensionsToGHCFlag, extensionsToNHCFlag, extensionsToHugsFlag)
import Distribution.Setup(ConfigFlags,CompilerFlavor(..), Compiler(..))
......@@ -125,7 +129,7 @@ localBuildInfoFile = "./.setup-config"
-- -----------------------------------------------------------------------------
configure :: PackageDescription -> ConfigFlags -> IO LocalBuildInfo
configure pkg_descr (maybe_hc_flavor, maybe_hc_path, maybe_prefix)
configure pkg_descr (maybe_hc_flavor, maybe_hc_path, maybe_hc_pkg, maybe_prefix)
= do
setupMessage "Configuring" pkg_descr
let lib = library pkg_descr
......@@ -134,7 +138,7 @@ configure pkg_descr (maybe_hc_flavor, maybe_hc_path, maybe_prefix)
Just path -> path
Nothing -> system_default_prefix pkg_descr
-- detect compiler
compiler@(Compiler f' p' pkg) <- configCompiler maybe_hc_flavor maybe_hc_path pkg_descr
compiler@(Compiler f' p' pkg) <- configCompiler maybe_hc_flavor maybe_hc_path maybe_hc_pkg pkg_descr
-- check extensions
let extlist = nub $ maybe [] extensions lib ++
concat [ extensions exeBi | Executable _ _ exeBi <- executables pkg_descr ]
......@@ -180,24 +184,27 @@ system_default_prefix PackageDescription{package=package} =
-- -----------------------------------------------------------------------------
-- Determining the compiler details
configCompiler :: Maybe CompilerFlavor -> Maybe FilePath -> PackageDescription
-> IO Compiler
configCompiler :: Maybe CompilerFlavor -> Maybe FilePath -> Maybe FilePath
-> PackageDescription -> IO Compiler
configCompiler (Just flavor) (Just path) _
= do pkgtool <- guessPkgToolFromHCPath flavor path
return (Compiler{compilerFlavor=flavor,
compilerPath=path,
compilerPkgTool=pkgtool})
configCompiler (Just flavor) maybe_compiler maybe_pkgtool _
= do compiler <-
case maybe_compiler of
Just path -> return path
Nothing -> findCompiler flavor
pkgtool <-
case maybe_pkgtool of
Just path -> return path
Nothing -> guessPkgToolFromHCPath flavor compiler
configCompiler (Just flavor) Nothing _
= do path <- findCompiler flavor
pkgtool <- guessPkgToolFromHCPath flavor path
return (Compiler{compilerFlavor=flavor,
compilerPath=path,
compilerPath=compiler,
compilerPkgTool=pkgtool})
configCompiler Nothing maybe_path pkg_descr
= configCompiler (Just defaultCompilerFlavor) maybe_path pkg_descr
configCompiler Nothing maybe_path maybe_hc_pkg pkg_descr
= configCompiler (Just defaultCompilerFlavor)
maybe_path maybe_hc_pkg pkg_descr
defaultCompilerFlavor =
#if defined(__GLASGOW_HASKELL__)
......
......@@ -50,6 +50,10 @@ module Distribution.Simple.Install (
#endif
) where
#if __GLASGOW_HASKELL__ < 603
#include "config.h"
#endif
import Distribution.Package (PackageDescription(..), BuildInfo(..), Executable(..),
showPackageId, hasLibs)
import Distribution.Simple.Configure(LocalBuildInfo(..))
......
......@@ -68,12 +68,16 @@ module Distribution.Simple.Utils (
#endif
) where
#if __GLASGOW_HASKELL__ < 603
#include "config.h"
#endif
import Distribution.Package (PackageDescription(..), showPackageId)
import Control.Monad(when, unless, liftM, mapM)
import Data.List(inits, nub, intersperse, findIndices, partition)
import Data.Maybe(Maybe, listToMaybe, isNothing, fromJust, catMaybes)
import System.IO (hPutStr, stderr
import System.IO (hPutStr, stderr, hFlush, stdout
#ifdef __GLASGOW_HASKELL__
, openBinaryFile, IOMode(..), hGetBuf, hPutBuf, hClose
#endif
......@@ -228,7 +232,7 @@ setupMessage msg pkg_descr =
putStrLn (msg ++ ' ':showPackageId (package pkg_descr) ++ "...")
die :: String -> IO a
die msg = do hPutStr stderr (msg++"\n"); exitWith (ExitFailure 1)
die msg = do hFlush stdout; hPutStr stderr (msg++"\n"); exitWith (ExitFailure 1)
-- -----------------------------------------------------------------------------
-- rawSystem variants
......
......@@ -88,6 +88,7 @@
** configure should check for 'ar' args + properties (see fptools/aclocal.m4)
** most commands should accept a -v flag to show command lines?
** configure should check sanity of PackageDescription, eg. library /= "" ?
** configure should check version of compiler
------------------------------------------------------------
* Setup Command-line interface
......
......@@ -13,7 +13,7 @@ all: moduleTest
# build the library itself
setup:
setup::
mkdir -p dist/tmp
ghc $(GHCFLAGS) -odir dist/tmp -hidir dist/tmp Setup -o setup
......
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