on ada8e73 help sign in
Idris-dev/Setup.hs
161 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
37-- use GNU make on FreeBSD
38#ifdef freebsd_HOST_OS
39mymake = "gmake"
40#else
41mymake = "make"
42#endif
43make verbosity =
44 P.runProgramInvocation verbosity . P.simpleProgramInvocation mymake
46-- -----------------------------------------------------------------------------
47-- Flags
49usesLLVM :: S.ConfigFlags -> Bool
50usesLLVM flags =
51 case lookup (FlagName "llvm") (S.configConfigurationsFlags flags) of
52 Just True -> True
53 Just False -> False
54 Nothing -> True
56usesGMP :: S.ConfigFlags -> Bool
57usesGMP flags =
58 case lookup (FlagName "gmp") (S.configConfigurationsFlags flags) of
59 Just True -> True
60 Just False -> False
61 Nothing -> True
63-- -----------------------------------------------------------------------------
64-- Clean
66idrisClean _ flags _ _ = do
67 cleanStdLib
68 cleanLLVM
69 where
70 verbosity = S.fromFlag $ S.cleanVerbosity flags
72 cleanStdLib = do
73 makeClean "libs"
75 cleanLLVM = makeClean "llvm"
77 makeClean dir = make verbosity [ "-C", dir, "clean", "IDRIS=idris" ]
80-- -----------------------------------------------------------------------------
81-- Configure
83idrisConfigure _ flags _ local = do
84 configureRTS
85 where
86 verbosity = S.fromFlag $ S.configVerbosity flags
87 version = pkgVersion . package $ localPkgDescr local
89 -- This is a hack. I don't know how to tell cabal that a data file needs
90 -- installing but shouldn't be in the distribution. And it won't make the
91 -- distribution if it's not there, so instead I just delete
92 -- the file after configure.
93 configureRTS = make verbosity ["-C", "rts", "clean"]
95-- -----------------------------------------------------------------------------
96-- Build
98idrisBuild _ flags _ local = do
99 buildStdLib
100 buildRTS
101 when (usesLLVM $ configFlags local) buildLLVM
102 where
103 verbosity = S.fromFlag $ S.buildVerbosity flags
105 buildStdLib = do
106 putStrLn "Building libraries..."
107 makeBuild "libs"
108 where
109 makeBuild dir = make verbosity [ "-C", dir, "build" , "IDRIS=" ++ idrisCmd local]
111 buildRTS = make verbosity (["-C", "rts", "build"] ++
112 gmpflag (usesGMP (configFlags local)))
114 buildLLVM = make verbosity ["-C", "llvm", "build"]
116 gmpflag False = []
117 gmpflag True = ["GMP=-DIDRIS_GMP"]
119-- -----------------------------------------------------------------------------
120-- Copy/Install
122idrisInstall verbosity copy pkg local = do
123 installStdLib
124 installRTS
125 when (usesLLVM $ configFlags local) installLLVM
126 where
127 target = datadir $ L.absoluteInstallDirs pkg local copy
129 installStdLib = do
130 putStrLn $ "Installing libraries in " ++ target
131 makeInstall "libs" target
133 installRTS = do
134 let target' = target </> "rts"
135 putStrLn $ "Installing run time system in " ++ target'
136 makeInstall "rts" target'
138 installLLVM = do
139 let target' = target </> "llvm"
140 putStrLn $ "Installing LLVM library in " ++ target
141 makeInstall "llvm" target'
143 makeInstall src target =
144 make verbosity [ "-C", src, "install" , "TARGET=" ++ target, "IDRIS=" ++ idrisCmd local]
146-- -----------------------------------------------------------------------------
147-- Main
149-- Install libraries during both copy and install
150-- See http://hackage.haskell.org/trac/hackage/ticket/718
151main = defaultMainWithHooks $ simpleUserHooks
152 { postClean = idrisClean
153 , postConf = idrisConfigure
154 , postBuild = idrisBuild
155 , postCopy = \_ flags pkg local ->
156 idrisInstall (S.fromFlag $ S.copyVerbosity flags)
157 (S.fromFlag $ S.copyDest flags) pkg local
158 , postInst = \_ flags pkg local ->
159 idrisInstall (S.fromFlag $ S.installVerbosity flags)
160 NoCopyDest pkg local
161 }