Commit 5b2637d6 authored by Andres Loeh's avatar Andres Loeh
Browse files

started on UHC support

parent ece620a1
......@@ -102,6 +102,7 @@ Library
Distribution.Simple.Register,
Distribution.Simple.Setup,
Distribution.Simple.SrcDist,
Distribution.Simple.UHC,
Distribution.Simple.UserHooks,
Distribution.Simple.Utils,
Distribution.System,
......
......@@ -73,12 +73,12 @@ import Text.PrettyPrint ((<>))
import qualified Data.Char as Char (toLower, isDigit, isAlphaNum)
import Control.Monad (when)
data CompilerFlavor = GHC | NHC | YHC | Hugs | HBC | Helium | JHC | LHC
data CompilerFlavor = GHC | NHC | YHC | Hugs | HBC | Helium | JHC | LHC | UHC
| OtherCompiler String
deriving (Show, Read, Eq, Ord)
knownCompilerFlavors :: [CompilerFlavor]
knownCompilerFlavors = [GHC, NHC, YHC, Hugs, HBC, Helium, JHC, LHC]
knownCompilerFlavors = [GHC, NHC, YHC, Hugs, HBC, Helium, JHC, LHC, UHC]
instance Text CompilerFlavor where
disp (OtherCompiler name) = Disp.text name
......
......@@ -57,6 +57,7 @@ import qualified Distribution.Simple.JHC as JHC
import qualified Distribution.Simple.LHC as LHC
import qualified Distribution.Simple.NHC as NHC
import qualified Distribution.Simple.Hugs as Hugs
import qualified Distribution.Simple.UHC as UHC
import qualified Distribution.Simple.Build.Macros as Build.Macros
import qualified Distribution.Simple.Build.PathsModule as Build.PathsModule
......@@ -159,6 +160,7 @@ buildLib verbosity pkg_descr lbi lib clbi =
LHC -> LHC.buildLib verbosity pkg_descr lbi lib clbi
Hugs -> Hugs.buildLib verbosity pkg_descr lbi lib clbi
NHC -> NHC.buildLib verbosity pkg_descr lbi lib clbi
UHC -> UHC.buildLib verbosity pkg_descr lbi lib clbi
_ -> die "Building is not supported with this compiler."
buildExe :: Verbosity -> PackageDescription -> LocalBuildInfo
......
......@@ -118,6 +118,7 @@ import qualified Distribution.Simple.JHC as JHC
import qualified Distribution.Simple.LHC as LHC
import qualified Distribution.Simple.NHC as NHC
import qualified Distribution.Simple.Hugs as Hugs
import qualified Distribution.Simple.UHC as UHC
import Control.Monad
( when, unless, foldM, filterM )
......@@ -775,6 +776,7 @@ configCompiler (Just hcFlavor) hcPath hcPkg conf verbosity = do
LHC.configure verbosity hcPath Nothing ghcConf
Hugs -> Hugs.configure verbosity hcPath hcPkg conf
NHC -> NHC.configure verbosity hcPath hcPkg conf
UHC -> UHC.configure verbosity hcPath hcPkg conf
_ -> die "Unknown compiler"
......
......@@ -93,6 +93,7 @@ module Distribution.Simple.Program (
, jhcProgram
, hugsProgram
, ffihugsProgram
, uhcProgram
, gccProgram
, ranlibProgram
, arProgram
......
......@@ -25,6 +25,7 @@ module Distribution.Simple.Program.Builtin (
jhcProgram,
hugsProgram,
ffihugsProgram,
uhcProgram,
gccProgram,
ranlibProgram,
arProgram,
......@@ -67,6 +68,7 @@ builtinPrograms =
, jhcProgram
, lhcProgram
, lhcPkgProgram
, uhcProgram
-- preprocessors
, hscolourProgram
, haddockProgram
......@@ -148,6 +150,10 @@ jhcProgram = (simpleProgram "jhc") {
_ -> ""
}
uhcProgram = (simpleProgram "uhc") {
programFindVersion = findProgramVersion "--numeric-version" id
}
-- AArgh! Finding the version of hugs or ffihugs is almost impossible.
hugsProgram :: Program
......
......@@ -333,7 +333,8 @@ configureOptions showOrParseArgs =
, (Flag NHC, ([] , ["nhc98"]), "compile with NHC")
, (Flag JHC, ([] , ["jhc"]), "compile with JHC")
, (Flag LHC, ([] , ["lhc"]), "compile with LHC")
, (Flag Hugs,([] , ["hugs"]), "compile with Hugs")])
, (Flag Hugs,([] , ["hugs"]), "compile with Hugs")
, (Flag UHC, ([] , ["uhc"]), "compile with UHC")])
,option "w" ["with-compiler"]
"give the path to a particular compiler"
......
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.Simple.UHC
-- Copyright : Andres Loeh 2009
--
-- Maintainer : cabal-devel@haskell.org
-- Portability : portable
--
-- This module contains most of the UHC-specific code for configuring, building
-- and installing packages.
{-
Copyright (c) 2009, Andres Loeh
Copyright (c) 2003-2005, Isaac Jones
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Isaac Jones nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Simple.UHC (
configure, buildLib
) where
import Data.List
import Distribution.Package
import Distribution.PackageDescription
import Distribution.Simple.BuildPaths
import Distribution.Simple.Compiler as C
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program
import Distribution.Text
import Distribution.Verbosity
import Distribution.Version
import Language.Haskell.Extension
import System.FilePath
-- -----------------------------------------------------------------------------
-- Configuring
configure :: Verbosity -> Maybe FilePath -> Maybe FilePath
-> ProgramConfiguration -> IO (Compiler, ProgramConfiguration)
configure verbosity hcPath _hcPkgPath conf = do
(_uhcProg, uhcVersion, conf') <-
requireProgramVersion verbosity uhcProgram
(orLaterVersion (Version [1,0,2] []))
(userMaybeSpecifyPath "uhc" hcPath conf)
let comp = Compiler {
compilerId = CompilerId UHC uhcVersion,
compilerExtensions = uhcLanguageExtensions
}
return (comp, conf')
-- | The flags for the supported extensions.
uhcLanguageExtensions :: [(Extension, C.Flag)]
uhcLanguageExtensions = []
-- -----------------------------------------------------------------------------
-- Building
buildLib :: Verbosity -> PackageDescription -> LocalBuildInfo
-> Library -> ComponentLocalBuildInfo -> IO ()
buildLib verbosity pkg_descr lbi lib clbi = do
let runUhcProg = rawSystemProgramConf verbosity uhcProgram (withPrograms lbi)
let uhcArgs = -- set package name
["--pkg-build=" ++ display (packageId pkg_descr)]
-- common flags lib/exe
++ constructUHCCmdLine lbi (libBuildInfo lib) clbi
(buildDir lbi) verbosity
-- source files
-- suboptimal: UHC does not understand module names, so
-- we replace periods by path separators
++ map (map (\ c -> if c == '.' then pathSeparator else c))
(map display (libModules lib))
runUhcProg uhcArgs
return ()
constructUHCCmdLine :: LocalBuildInfo -> BuildInfo -> ComponentLocalBuildInfo
-> FilePath -> Verbosity -> [String]
constructUHCCmdLine lbi bi clbi odir verbosity =
-- verbosity
(if verbosity >= deafening then ["-v4"]
else if verbosity >= normal then []
else ["-v0"])
-- packages
++ ["--hide-all-packages"]
++ ["--package=" ++ display (pkgName pkgid) | (_, pkgid) <- componentPackageDeps clbi ]
-- search paths
++ ["-i" ++ odir]
++ ["-i" ++ l | l <- nub (hsSourceDirs bi)]
++ ["-i" ++ autogenModulesDir lbi]
-- output path
++ ["--odir=" ++ odir]
-- optimization
++ (case withOptimization lbi of
NoOptimisation -> ["-O0"]
NormalOptimisation -> ["-O1"]
MaximumOptimisation -> ["-O2"])
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