on d1663cc help sign in
Idris-dev/Setup.hs
157 lines 5.1 kB history raw
1{-# LANGUAGE CPP #-}
2import Control.Monad
3import Data.IORef
5import Distribution.Simple
6import Distribution.Simple.InstallDirs as I
7import Distribution.Simple.LocalBuildInfo as L
8import qualified Distribution.Simple.Setup as S
9import qualified Distribution.Simple.Program as P
10import Distribution.PackageDescription
11import Distribution.Text
13import System.Exit
14import System.FilePath ((</>), splitDirectories)
15import System.Directory
16import qualified System.FilePath.Posix as Px
17import System.Process
18import qualified Data.Text as T
19import qualified Data.Text.IO as TIO
21-- After Idris is built, we need to check and install the prelude and other libs
23-- -----------------------------------------------------------------------------
24-- Idris Command Path
26-- make on mingw32 exepects unix style separators
27#ifdef mingw32_HOST_OS
28(<//>) = (Px.</>)
29idrisCmd local = Px.joinPath $ splitDirectories $ ".." <//> buildDir local <//> "idris" <//> "idris"
30#else
31idrisCmd local = ".." </> buildDir local </> "idris" </> "idris"
32#endif
34-- -----------------------------------------------------------------------------
35-- Make Commands
37make verbosity =
38 P.runProgramInvocation verbosity . P.simpleProgramInvocation "make"
40-- -----------------------------------------------------------------------------
41-- Flags
43usesLLVM :: S.ConfigFlags -> Bool
44usesLLVM flags =
45 case lookup (FlagName "llvm") (S.configConfigurationsFlags flags) of
46 Just True -> True
47 Just False -> False
48 Nothing -> True
50usesEffects :: S.ConfigFlags -> Bool
51usesEffects flags =
52 case lookup (FlagName "effects") (S.configConfigurationsFlags flags) of
53 Just True -> True
54 Just False -> False
55 Nothing -> True
57-- -----------------------------------------------------------------------------
58-- Clean
60idrisClean _ flags _ _ = do
61 cleanStdLib
62 cleanLLVM
63 where
64 verbosity = S.fromFlag $ S.cleanVerbosity flags
66 cleanStdLib = do
67 makeClean "lib"
68 makeClean "effects"
69 makeClean "javascript"
71 cleanLLVM = makeClean "llvm"
73 makeClean dir = make verbosity [ "-C", dir, "clean", "IDRIS=idris" ]
76-- -----------------------------------------------------------------------------
77-- Configure
79idrisConfigure _ flags _ local = do
80 configureRTS
81 where
82 verbosity = S.fromFlag $ S.configVerbosity flags
83 version = pkgVersion . package $ localPkgDescr local
85 -- This is a hack. I don't know how to tell cabal that a data file needs
86 -- installing but shouldn't be in the distribution. And it won't make the
87 -- distribution if it's not there, so instead I just delete
88 -- the file after configure.
89 configureRTS = make verbosity ["-C", "rts", "clean"]
91-- -----------------------------------------------------------------------------
92-- Build
94idrisBuild _ flags _ local = do
95 buildStdLib
96 buildRTS
97 when (usesLLVM $ configFlags local) buildLLVM
98 where
99 verbosity = S.fromFlag $ S.buildVerbosity flags
101 buildStdLib = do
102 putStrLn "Building libraries..."
103 makeBuild "lib"
104 when (usesEffects $ configFlags local) $ makeBuild "effects"
105 makeBuild "javascript"
106 where
107 makeBuild dir = make verbosity [ "-C", dir, "build" , "IDRIS=" ++ idrisCmd local]
109 buildRTS = make verbosity ["-C", "rts", "build"]
111 buildLLVM = make verbosity ["-C", "llvm", "build"]
113-- -----------------------------------------------------------------------------
114-- Copy/Install
116idrisInstall verbosity copy pkg local = do
117 installStdLib
118 installRTS
119 when (usesLLVM $ configFlags local) installLLVM
120 where
121 target = datadir $ L.absoluteInstallDirs pkg local copy
123 installStdLib = do
124 putStrLn $ "Installing libraries in " ++ target
125 makeInstall "lib" target
126 when (usesEffects $ configFlags local) $ makeInstall "effects" target
127 makeInstall "javascript" target
129 installRTS = do
130 let target' = target </> "rts"
131 putStrLn $ "Installing run time system in " ++ target'
132 makeInstall "rts" target'
134 installLLVM = do
135 let target' = target </> "llvm"
136 putStrLn $ "Installing LLVM library in " ++ target
137 makeInstall "llvm" target'
139 makeInstall src target =
140 make verbosity [ "-C", src, "install" , "TARGET=" ++ target, "IDRIS=" ++ idrisCmd local]
142-- -----------------------------------------------------------------------------
143-- Main
145-- Install libraries during both copy and install
146-- See http://hackage.haskell.org/trac/hackage/ticket/718
147main = defaultMainWithHooks $ simpleUserHooks
148 { postClean = idrisClean
149 , postConf = idrisConfigure
150 , postBuild = idrisBuild
151 , postCopy = \_ flags pkg local ->
152 idrisInstall (S.fromFlag $ S.copyVerbosity flags)
153 (S.fromFlag $ S.copyDest flags) pkg local
154 , postInst = \_ flags pkg local ->
155 idrisInstall (S.fromFlag $ S.installVerbosity flags)
156 NoCopyDest pkg local
157 }