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, notice, installOrdinaryFiles)
13import Distribution.Compiler
14import Distribution.PackageDescription
15import Distribution.Text
17import System.Environment
19import System.FilePath ((</>), splitDirectories,isAbsolute)
20import System.Directory
21import qualified System.FilePath.Posix as Px
24-- After Idris is built, we need to check and install the prelude and other libs
26-- -----------------------------------------------------------------------------
29-- make on mingw32 exepects unix style separators
32idrisCmd local = Px.joinPath $ splitDirectories $ ".." <//> ".." <//> buildDir local <//> "idris" <//> "idris"
34idrisCmd local = ".." </> ".." </> buildDir local </> "idris" </> "idris"
37-- -----------------------------------------------------------------------------
40-- use GNU make on FreeBSD
41#if defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS)\
42 || defined(openbsd_HOST_OS) || defined(netbsd_HOST_OS)
48 P.runProgramInvocation verbosity . P.simpleProgramInvocation mymake
51windres verbosity = P.runProgramInvocation verbosity . P.simpleProgramInvocation "windres"
53-- -----------------------------------------------------------------------------
56usesGMP :: S.ConfigFlags -> Bool
58 case lookup (FlagName "gmp") (S.configConfigurationsFlags flags) of
63execOnly :: S.ConfigFlags -> Bool
65 case lookup (FlagName "execonly") (S.configConfigurationsFlags flags) of
70isRelease :: S.ConfigFlags -> Bool
72 case lookup (FlagName "release") (S.configConfigurationsFlags flags) of
77isFreestanding :: S.ConfigFlags -> Bool
79 case lookup (FlagName "freestanding") (S.configConfigurationsFlags flags) of
83-- -----------------------------------------------------------------------------
86idrisClean _ flags _ _ = do
89 verbosity = S.fromFlag $ S.cleanVerbosity flags
94 makeClean dir = make verbosity [ "-C", dir, "clean", "IDRIS=idris" ]
97-- -----------------------------------------------------------------------------
101gitHash = do h <- Control.Exception.catch (readProcess "git" ["rev-parse", "--short", "HEAD"] "")
102 (\e -> let e' = (e :: SomeException) in return "PRE")
103 return $ takeWhile (/= '\n') h
105-- Put the Git hash into a module for use in the program
106-- For release builds, just put the empty string in the module
107generateVersionModule verbosity dir release = do
109 let versionModulePath = dir </> "Version_idris" Px.<.> "hs"
110 putStrLn $ "Generating " ++ versionModulePath ++
111 if release then " for release" else (" for prerelease " ++ hash)
112 createDirectoryIfMissingVerbose verbosity True dir
113 rewriteFile versionModulePath (versionModuleContents hash)
115 where versionModuleContents h = "module Version_idris where\n\n" ++
116 "gitHash :: String\n" ++
118 then "gitHash = \"\"\n"
119 else "gitHash = \"git:" ++ h ++ "\"\n"
121-- Generate a module that contains the lib path for a freestanding Idris
122generateTargetModule verbosity dir targetDir = do
123 absPath <- return $ isAbsolute targetDir
124 let targetModulePath = dir </> "Target_idris" Px.<.> "hs"
125 putStrLn $ "Generating " ++ targetModulePath
126 createDirectoryIfMissingVerbose verbosity True dir
127 rewriteFile targetModulePath (versionModuleContents absPath targetDir)
128 where versionModuleContents absolute td = "module Target_idris where\n\n" ++
129 "import System.FilePath\n" ++
130 "import System.Environment\n" ++
131 "getDataDir :: IO String\n" ++
133 then "getDataDir = return \"" ++ td ++ "\"\n"
134 else "getDataDir = do \n" ++
135 " expath <- getExecutablePath\n" ++
136 " execDir <- return $ dropFileName expath\n" ++
137 " return $ execDir ++ \"" ++ td ++ "\"\n"
138 ++ "getDataFileName :: FilePath -> IO FilePath\n"
139 ++ "getDataFileName name = do\n"
140 ++ " dir <- getDataDir\n"
141 ++ " return (dir ++ \"/\" ++ name)"
143-- a module that has info about existence and location of a bundled toolchain
144generateToolchainModule verbosity srcDir toolDir = do
145 let commonContent = "module Tools_idris where\n\n"
146 let toolContent = case toolDir of
147 Just dir -> "hasBundledToolchain = True\n" ++
148 "getToolchainDir = \"" ++ dir ++ "\"\n"
149 Nothing -> "hasBundledToolchain = False\n" ++
150 "getToolchainDir = \"\""
151 let toolPath = srcDir </> "Tools_idris" Px.<.> "hs"
152 createDirectoryIfMissingVerbose verbosity True srcDir
153 rewriteFile toolPath (commonContent ++ toolContent)
155idrisConfigure _ flags _ local = do
157 generateVersionModule verbosity (autogenModulesDir local) (isRelease (configFlags local))
158 if (isFreestanding $ configFlags local)
160 toolDir <- lookupEnv "IDRIS_TOOLCHAIN_DIR"
161 generateToolchainModule verbosity (autogenModulesDir local) toolDir
162 targetDir <- lookupEnv "IDRIS_LIB_DIR"
164 Just d -> generateTargetModule verbosity (autogenModulesDir local) d
165 Nothing -> error $ "Trying to build freestanding without a target directory."
166 ++ " Set it by defining IDRIS_LIB_DIR.")
168 generateToolchainModule verbosity (autogenModulesDir local) Nothing
170 verbosity = S.fromFlag $ S.configVerbosity flags
171 version = pkgVersion . package $ localPkgDescr local
173 -- This is a hack. I don't know how to tell cabal that a data file needs
174 -- installing but shouldn't be in the distribution. And it won't make the
175 -- distribution if it's not there, so instead I just delete
176 -- the file after configure.
177 configureRTS = make verbosity ["-C", "rts", "clean"]
179idrisPreSDist args flags = do
180 let dir = S.fromFlag (S.sDistDirectory flags)
181 let verb = S.fromFlag (S.sDistVerbosity flags)
182 generateVersionModule verb ("src") True
183 generateTargetModule verb "src" "./libs"
184 generateToolchainModule verb "src" Nothing
185 preSDist simpleUserHooks args flags
187idrisPostSDist args flags desc lbi = do
188 Control.Exception.catch (do let file = "src" </> "Version_idris" Px.<.> "hs"
189 let targetFile = "src" </> "Target_idris" Px.<.> "hs"
190 putStrLn $ "Removing generated modules:\n "
191 ++ file ++ "\n" ++ targetFile
193 removeFile targetFile)
194 (\e -> let e' = (e :: SomeException) in return ())
195 postSDist simpleUserHooks args flags desc lbi
197-- -----------------------------------------------------------------------------
200getVersion :: Args -> S.BuildFlags -> IO HookedBuildInfo
201getVersion args flags = do
203 let buildinfo = (emptyBuildInfo { cppOptions = ["-DVERSION="++hash] }) :: BuildInfo
204 return (Just buildinfo, [])
208idrisPreBuild args flags = do
209#ifdef mingw32_HOST_OS
210 createDirectoryIfMissingVerbose verbosity True dir
211 windres verbosity ["icons/idris_icon.rc","-o", dir++"idris_icon.o"]
212 return (Nothing, [("idris", emptyBuildInfo { ldOptions = [dir ++ "idris_icon.o"] })])
214 verbosity = S.fromFlag $ S.buildVerbosity flags
215 dir = S.fromFlagOrDefault "dist" $ S.buildDistPref flags
220idrisBuild _ flags _ local = unless (execOnly (configFlags local)) $ do
224 verbosity = S.fromFlag $ S.buildVerbosity flags
227 putStrLn "Building libraries..."
230 makeBuild dir = make verbosity [ "-C", dir, "build" , "IDRIS=" ++ idrisCmd local]
232 buildRTS = make verbosity (["-C", "rts", "build"] ++
233 gmpflag (usesGMP (configFlags local)))
236 gmpflag True = ["GMP=-DIDRIS_GMP"]
240-- -----------------------------------------------------------------------------
243idrisInstall verbosity copy pkg local = unless (execOnly (configFlags local)) $ do
248 target = datadir $ L.absoluteInstallDirs pkg local copy
251 putStrLn $ "Installing libraries in " ++ target
252 makeInstall "libs" target
255 let target' = target </> "rts"
256 putStrLn $ "Installing run time system in " ++ target'
257 makeInstall "rts" target'
260 let mandest = (mandir $ L.absoluteInstallDirs pkg local copy) ++ "/man1"
261 notice verbosity $ unwords ["Copying man page to", mandest]
262 installOrdinaryFiles verbosity mandest [("man", "idris.1")]
265 makeInstall src target =
266 make verbosity [ "-C", src, "install" , "TARGET=" ++ target, "IDRIS=" ++ idrisCmd local]
268-- -----------------------------------------------------------------------------
271-- Install libraries during both copy and install
272-- See https://github.com/haskell/cabal/issues/709
273main = defaultMainWithHooks $ simpleUserHooks
274 { postClean = idrisClean
275 , postConf = idrisConfigure
276 , preBuild = idrisPreBuild
277 , postBuild = idrisBuild
278 , postCopy = \_ flags pkg local ->
279 idrisInstall (S.fromFlag $ S.copyVerbosity flags)
280 (S.fromFlag $ S.copyDest flags) pkg local
281 , postInst = \_ flags pkg local ->
282 idrisInstall (S.fromFlag $ S.installVerbosity flags)
284 , preSDist = idrisPreSDist --do { putStrLn (show args) ; putStrLn (show flags) ; return emptyHookedBuildInfo }
285 , 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