4import Control.Exception (SomeException, catch)
6import Distribution.Simple
7import Distribution.Simple.BuildPaths (autogenModulesDir)
8import Distribution.Simple.InstallDirs as I
9import Distribution.Simple.LocalBuildInfo as L
10import qualified Distribution.Simple.Setup as S
11import qualified Distribution.Simple.Program as P
12import Distribution.Simple.Utils (createDirectoryIfMissingVerbose, rewriteFile)
13import Distribution.PackageDescription
14import Distribution.Text
16import System.Environment
18import System.FilePath ((</>), splitDirectories,isAbsolute)
19import System.Directory
20import qualified System.FilePath.Posix as Px
22import qualified Data.Text as T
23import qualified Data.Text.IO as TIO
25-- After Idris is built, we need to check and install the prelude and other libs
27-- -----------------------------------------------------------------------------
30-- make on mingw32 exepects unix style separators
33idrisCmd local = Px.joinPath $ splitDirectories $ ".." <//> ".." <//> buildDir local <//> "idris" <//> "idris"
35idrisCmd local = ".." </> ".." </> buildDir local </> "idris" </> "idris"
38-- -----------------------------------------------------------------------------
41-- use GNU make on FreeBSD
42#if defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS)
48 P.runProgramInvocation verbosity . P.simpleProgramInvocation mymake
50-- -----------------------------------------------------------------------------
53usesGMP :: S.ConfigFlags -> Bool
55 case lookup (FlagName "gmp") (S.configConfigurationsFlags flags) of
60isRelease :: S.ConfigFlags -> Bool
62 case lookup (FlagName "release") (S.configConfigurationsFlags flags) of
67isFreestanding :: S.ConfigFlags -> Bool
69 case lookup (FlagName "freestanding") (S.configConfigurationsFlags flags) of
73-- -----------------------------------------------------------------------------
76idrisClean _ flags _ _ = do
79 verbosity = S.fromFlag $ S.cleanVerbosity flags
84 makeClean dir = make verbosity [ "-C", dir, "clean", "IDRIS=idris" ]
87-- -----------------------------------------------------------------------------
91gitHash = do h <- Control.Exception.catch (readProcess "git" ["rev-parse", "--short", "HEAD"] "")
92 (\e -> let e' = (e :: SomeException) in return "PRE")
93 return $ takeWhile (/= '\n') h
95-- Put the Git hash into a module for use in the program
96-- For release builds, just put the empty string in the module
97generateVersionModule verbosity dir release = do
99 let versionModulePath = dir </> "Version_idris" Px.<.> "hs"
100 putStrLn $ "Generating " ++ versionModulePath ++
101 if release then " for release" else (" for prerelease " ++ hash)
102 createDirectoryIfMissingVerbose verbosity True dir
103 rewriteFile versionModulePath (versionModuleContents hash)
105 where versionModuleContents h = "module Version_idris where\n\n" ++
106 "gitHash :: String\n" ++
108 then "gitHash = \"\"\n"
109 else "gitHash = \"-git:" ++ h ++ "\"\n"
111-- Generate a module that contains the lib path for a freestanding Idris
112generateTargetModule verbosity dir targetDir = do
113 absPath <- return $ isAbsolute targetDir
114 let targetModulePath = dir </> "Target_idris" Px.<.> "hs"
115 putStrLn $ "Generating " ++ targetModulePath
116 createDirectoryIfMissingVerbose verbosity True dir
117 rewriteFile targetModulePath (versionModuleContents absPath targetDir)
118 where versionModuleContents absolute td = "module Target_idris where\n\n" ++
119 "import System.FilePath\n" ++
120 "import System.Environment\n" ++
121 "getDataDir :: IO String\n" ++
123 then "getDataDir = return \"" ++ td ++ "\"\n"
124 else "getDataDir = do \n" ++
125 " expath <- getExecutablePath\n" ++
126 " execDir <- return $ dropFileName expath\n" ++
127 " return $ execDir ++ \"" ++ td ++ "\"\n"
128 ++ "getDataFileName :: FilePath -> IO FilePath\n"
129 ++ "getDataFileName name = do\n"
130 ++ " dir <- getDataDir\n"
131 ++ " return (dir ++ \"/\" ++ name)"
134idrisConfigure _ flags _ local = do
136 generateVersionModule verbosity (autogenModulesDir local) (isRelease (configFlags local))
137 when (isFreestanding $ configFlags local) (do
138 targetDir <- lookupEnv "IDRIS_INSTALL_DIR"
140 Just d -> generateTargetModule verbosity (autogenModulesDir local) d
141 Nothing -> error $ "Trying to build freestanding without a target directory."
142 ++ " Set it by defining IDRIS_INSTALL_DIR.")
144 verbosity = S.fromFlag $ S.configVerbosity flags
145 version = pkgVersion . package $ localPkgDescr local
147 -- This is a hack. I don't know how to tell cabal that a data file needs
148 -- installing but shouldn't be in the distribution. And it won't make the
149 -- distribution if it's not there, so instead I just delete
150 -- the file after configure.
151 configureRTS = make verbosity ["-C", "rts", "clean"]
153idrisPreSDist args flags = do
154 let dir = S.fromFlag (S.sDistDirectory flags)
155 let verb = S.fromFlag (S.sDistVerbosity flags)
156 generateVersionModule verb ("src") True
157 generateTargetModule verb "src" "./libs"
158 preSDist simpleUserHooks args flags
160idrisPostSDist args flags desc lbi = do
161 Control.Exception.catch (do let file = "src" </> "Version_idris" Px.<.> "hs"
162 let targetFile = "src" </> "Target_idris" Px.<.> "hs"
163 putStrLn $ "Removing generated modules:\n "
164 ++ file ++ "\n" ++ targetFile
166 removeFile targetFile)
167 (\e -> let e' = (e :: SomeException) in return ())
168 postSDist simpleUserHooks args flags desc lbi
170-- -----------------------------------------------------------------------------
173getVersion :: Args -> S.BuildFlags -> IO HookedBuildInfo
174getVersion args flags = do
176 let buildinfo = (emptyBuildInfo { cppOptions = ["-DVERSION="++hash] }) :: BuildInfo
177 return (Just buildinfo, [])
179idrisBuild _ flags _ local = do
183 verbosity = S.fromFlag $ S.buildVerbosity flags
186 putStrLn "Building libraries..."
189 makeBuild dir = make verbosity [ "-C", dir, "build" , "IDRIS=" ++ idrisCmd local]
191 buildRTS = make verbosity (["-C", "rts", "build"] ++
192 gmpflag (usesGMP (configFlags local)))
195 gmpflag True = ["GMP=-DIDRIS_GMP"]
199-- -----------------------------------------------------------------------------
202idrisInstall verbosity copy pkg local = do
206 target = datadir $ L.absoluteInstallDirs pkg local copy
209 putStrLn $ "Installing libraries in " ++ target
210 makeInstall "libs" target
213 let target' = target </> "rts"
214 putStrLn $ "Installing run time system in " ++ target'
215 makeInstall "rts" target'
217 makeInstall src target =
218 make verbosity [ "-C", src, "install" , "TARGET=" ++ target, "IDRIS=" ++ idrisCmd local]
220-- -----------------------------------------------------------------------------
223-- Install libraries during both copy and install
224-- See http://hackage.haskell.org/trac/hackage/ticket/718
225main = defaultMainWithHooks $ simpleUserHooks
226 { postClean = idrisClean
227 , postConf = idrisConfigure
228 , postBuild = idrisBuild
229 , postCopy = \_ flags pkg local ->
230 idrisInstall (S.fromFlag $ S.copyVerbosity flags)
231 (S.fromFlag $ S.copyDest flags) pkg local
232 , postInst = \_ flags pkg local ->
233 idrisInstall (S.fromFlag $ S.installVerbosity flags)
235 , preSDist = idrisPreSDist --do { putStrLn (show args) ; putStrLn (show flags) ; return emptyHookedBuildInfo }
236 , postSDist = idrisPostSDist
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list