Skip to content

Commit

Permalink
[ghc8] compleat: refresh Setup.hs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Tsirakis authored and forbesrodney committed Mar 27, 2024
1 parent 255c478 commit b7ac8fd
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions compleat/Setup.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Distribution.Simple
import Distribution.Simple hiding (Version)
import Distribution.Simple.PreProcess
import Distribution.Simple.PreProcess.Unlit (unlit)
import Distribution.Package
Expand All @@ -7,26 +7,27 @@ import Distribution.ModuleName (ModuleName)
import qualified Distribution.ModuleName as ModuleName
import Distribution.PackageDescription as PD
( PackageDescription(..), BuildInfo(..), Executable(..), withExe
, Library(..), withLib, libModules )
import qualified Distribution.InstalledPackageInfo as Installed
( InstalledPackageInfo_(..) )
, Library(..), withLib )
import qualified Distribution.Types.InstalledPackageInfo as Installed
( InstalledPackageInfo(..) )
import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Simple.Compiler
( CompilerFlavor(..), Compiler(..), compilerFlavor, compilerVersion )
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..))
import Distribution.Simple.BuildPaths (autogenModulesDir,cppHeaderName)
import Distribution.Types.ComponentLocalBuildInfo (ComponentLocalBuildInfo(..))
import Distribution.Simple.BuildPaths (cppHeaderName)
import Distribution.Simple.Utils
( createDirectoryIfMissingVerbose, withUTF8FileContents, writeUTF8File
, die, setupMessage, intercalate, copyFileVerbose
, setupMessage, intercalate, copyFileVerbose
, findFileWithExtension, findFileWithExtension' )
import Distribution.Simple.Program
( Program(..), ConfiguredProgram(..), lookupProgram, programPath
, rawSystemProgramConf, rawSystemProgram
, runDbProgram, runProgram
, greencardProgram, cpphsProgram, hsc2hsProgram, c2hsProgram
, happyProgram, alexProgram, haddockProgram, ghcProgram, gccProgram, ldProgram )
import Distribution.Version
import Distribution.System
( OS(OSX, Windows), buildOS )
import Distribution.Version (Version(..))
import Distribution.Verbosity
import Distribution.Text
( display )
Expand All @@ -35,6 +36,7 @@ import Control.Monad (when, unless)
import Data.Maybe (fromMaybe)
import Data.List (nub)
import System.Directory (getModificationTime, doesFileExist)
import System.Exit (die)
import System.Info (os, arch)
import System.FilePath (splitExtension, dropExtensions, (</>), (<.>),
takeDirectory, normalise, replaceExtension)
Expand All @@ -44,16 +46,16 @@ import Distribution.Simple.Program (simpleProgram)

hsc2hsLdProgram = simpleProgram "hsc2hs-ld"

my_ppHsc2hs :: BuildInfo -> LocalBuildInfo -> PreProcessor
my_ppHsc2hs bi lbi = standardPP lbi hsc2hsProgram $
my_ppHsc2hs :: BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor
my_ppHsc2hs bi lbi _ = standardPP lbi hsc2hsProgram $
[ "--cc=" ++ programPath gccProg
, "--ld=" ++ programPath ldProg ]
-- [ "--cc=" ++ cc
-- , "--ld=" ++ ld ]

-- Additional gcc options
++ [ "--cflag=" ++ opt | opt <- programArgs gccProg ]
++ [ "--lflag=" ++ opt | opt <- programArgs gccProg ]
++ [ "--cflag=" ++ opt | opt <- programDefaultArgs gccProg ]
++ [ "--lflag=" ++ opt | opt <- programDefaultArgs gccProg ]

-- OSX frameworks:
++ [ what ++ "=-F" ++ opt
Expand Down Expand Up @@ -107,7 +109,7 @@ my_ppHsc2hs bi lbi = standardPP lbi hsc2hsProgram $
-- OS X (it's ld is a tad stricter than gnu ld). Thus we remove the
-- ldOptions for GHC's rts package:
hackRtsPackage index =
case PackageIndex.lookupPackageName index (PackageName "rts") of
case PackageIndex.lookupPackageName index (mkPackageName "rts") of
[(_, [rts])]
-> PackageIndex.insert rts { Installed.ldOptions = [] } index
_ -> error "No (or multiple) ghc rts package is registered!!"
Expand All @@ -117,10 +119,11 @@ my_ppHsc2hs bi lbi = standardPP lbi hsc2hsProgram $
-- FIXME: this forces GHC's crazy 4.8.2 -> 408 convention on all the other
-- compilers. Check if that's really what they want.
versionInt :: Version -> String
versionInt (Version { versionBranch = [] }) = "1"
versionInt (Version { versionBranch = [n] }) = show n
versionInt (Version { versionBranch = n1:n2:_ })
= -- 6.8.x -> 608
versionInt v = case versionNumbers v of
[] -> "1"
[n] -> show n
n1:n2:_ ->
-- 6.8.x -> 608
-- 6.10.x -> 610
let s1 = show n1
s2 = show n2
Expand All @@ -134,7 +137,7 @@ standardPP lbi prog args =
PreProcessor {
platformIndependent = False,
runPreProcessor = mkSimplePreProcessor $ \inFile outFile verbosity ->
do rawSystemProgramConf verbosity prog (withPrograms lbi)
do runDbProgram verbosity prog (withPrograms lbi)
(args ++ ["-o", outFile, inFile])
-- XXX This is a nasty hack. GHC requires that hs-boot files
-- be in the same place as the hs files, so if we put the hs
Expand Down

0 comments on commit b7ac8fd

Please sign in to comment.