on ef93607 help sign in
Idris-dev/Setup.hs
177 lines 6.8 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
23make verbosity = P.runProgramInvocation verbosity . P.simpleProgramInvocation "make"
25#ifdef mingw32_HOST_OS
26-- make on mingw32 exepects unix style separators
27(<//>) = (Px.</>)
28idrisCmd local = Px.joinPath $ splitDirectories $
29 ".." <//> buildDir local <//> "idris" <//> "idris"
30rtsDir local = Px.joinPath $ splitDirectories $
31 ".." <//> buildDir local <//> "rts" <//> "libidris_rts"
32#else
33idrisCmd local = ".." </> buildDir local </> "idris" </> "idris"
34rtsDir local = ".." </> buildDir local </> "rts" </> "libidris_rts"
35#endif
37cleanStdLib verbosity
38 = do make verbosity [ "-C", "lib", "clean", "IDRIS=idris" ]
39 make verbosity [ "-C", "effects", "clean", "IDRIS=idris" ]
40 make verbosity [ "-C", "javascript", "clean", "IDRIS=idris" ]
42cleanJavaPom verbosity
43 = do execPomExists <- doesFileExist ("java" </> "executable_pom.xml")
44 when execPomExists $ removeFile ("java" </> "executable_pom.xml")
46cleanLLVMLib verbosity = make verbosity ["-C", "llvm", "clean"]
48installStdLib pkg local withoutEffects verbosity copy
49 = do let dirs = L.absoluteInstallDirs pkg local copy
50 let idir = datadir dirs
51 let icmd = idrisCmd local
52 putStrLn $ "Installing libraries in " ++ idir
53 make verbosity
54 [ "-C", "lib", "install"
55 , "TARGET=" ++ idir
56 , "IDRIS=" ++ icmd
57 ]
58 unless withoutEffects $
59 make verbosity
60 [ "-C", "effects", "install"
61 , "TARGET=" ++ idir
62 , "IDRIS=" ++ icmd
63 ]
64 make verbosity
65 [ "-C", "javascript", "install"
66 , "TARGET=" ++ idir
67 , "IDRIS=" ++ icmd
68 ]
69 let idirRts = idir </> "rts"
70 putStrLn $ "Installing run time system in " ++ idirRts
71 make verbosity
72 [ "-C", "rts", "install"
73 , "TARGET=" ++ idirRts
74 , "IDRIS=" ++ icmd
75 ]
77installLLVMLib verbosity pkg local copy =
78 let idir = datadir $ L.absoluteInstallDirs pkg local copy in
79 make verbosity ["-C", "llvm", "install", "TARGET=" ++ idir </> "llvm"]
81buildLLVMLib verbosity = make verbosity ["-C", "llvm", "all"]
83installJavaPom pkg local verbosity copy version = do
84 putStrLn $ "Installing java pom template"
85 let dir = datadir $ L.absoluteInstallDirs pkg local copy
86 copyFile ("java" </> "executable_pom.xml") (dir </> "executable_pom.xml")
88-- This is a hack. I don't know how to tell cabal that a data file needs
89-- installing but shouldn't be in the distribution. And it won't make the
90-- distribution if it's not there, so instead I just delete
91-- the file after configure.
93removeLibIdris local verbosity
94 = do let icmd = idrisCmd local
95 make verbosity
96 [ "-C", "rts", "clean"
97 , "IDRIS=" ++ icmd
98 ]
100checkStdLib local withoutEffects verbosity
101 = do let icmd = idrisCmd local
102 putStrLn $ "Building libraries..."
103 make verbosity
104 [ "-C", "lib", "check"
105 , "IDRIS=" ++ icmd
106 ]
107 unless withoutEffects $
108 make verbosity
109 [ "-C", "effects", "check"
110 , "IDRIS=" ++ icmd
111 ]
112 make verbosity
113 [ "-C", "javascript", "check"
114 , "IDRIS=" ++ icmd
115 ]
116 make verbosity
117 [ "-C", "rts", "check"
118 , "IDRIS=" ++ icmd
119 ]
121llvmFlag flags =
122 case lookup (FlagName "llvm") (S.configConfigurationsFlags flags) of
123 Just True -> True
124 Just False -> False
125 Nothing -> True
127noEffectsFlag flags =
128 case lookup (FlagName "noeffects") (S.configConfigurationsFlags flags) of
129 Just True -> True
130 Just False -> False
131 Nothing -> False
133preparePoms version
134 = do execPomTemplate <- TIO.readFile ("java" </> "executable_pom_template.xml")
135 TIO.writeFile ("java" </> "executable_pom.xml") (insertVersion execPomTemplate)
136 where
137 insertVersion template =
138 T.replace (T.pack "$RTS-VERSION$") (T.pack $ display version) template
140-- Install libraries during both copy and install
141-- See http://hackage.haskell.org/trac/hackage/ticket/718
142main = do
143 defaultMainWithHooks $ simpleUserHooks
144 { postCopy = \ _ flags pkg lbi -> do
145 let verb = S.fromFlag $ S.copyVerbosity flags
146 let withoutEffects = noEffectsFlag $ configFlags lbi
147 installStdLib pkg lbi withoutEffects verb
148 (S.fromFlag $ S.copyDest flags)
149 installJavaPom pkg lbi verb
150 (S.fromFlag $ S.copyDest flags)
151 (pkgVersion . package $ localPkgDescr lbi)
152 when (llvmFlag $ configFlags lbi)
153 (installLLVMLib verb pkg lbi (S.fromFlag $ S.copyDest flags))
154 , postInst = \ _ flags pkg lbi -> do
155 let verb = (S.fromFlag $ S.installVerbosity flags)
156 let withoutEffects = noEffectsFlag $ configFlags lbi
157 installStdLib pkg lbi withoutEffects verb
158 NoCopyDest
159 installJavaPom pkg lbi verb
160 NoCopyDest
161 (pkgVersion . package $ localPkgDescr lbi)
162 when (llvmFlag $ configFlags lbi)
163 (installLLVMLib verb pkg lbi NoCopyDest)
164 , postConf = \ _ flags _ lbi -> do
165 removeLibIdris lbi (S.fromFlag $ S.configVerbosity flags)
166 preparePoms . pkgVersion . package $ localPkgDescr lbi
167 , postClean = \ _ flags _ _ -> do
168 let verb = S.fromFlag $ S.cleanVerbosity flags
169 cleanStdLib verb
170 cleanLLVMLib verb
171 cleanJavaPom verb
172 , postBuild = \ _ flags _ lbi -> do
173 let verb = S.fromFlag $ S.buildVerbosity flags
174 when (llvmFlag $ configFlags lbi) (buildLLVMLib verb)
175 let withoutEffects = noEffectsFlag $ configFlags lbi
176 checkStdLib lbi withoutEffects verb
177 }