on master help sign in
Merge pull request #12 from tomprince/cabal-install

Rewrite cabal config to be distribution friendly.

commit0607514258613f9546c779ad0eb42a05825a3771 authorEdwin Brady <eb@cs.st-andrews.ac.uk> dateMon 20 Feb 2012, 02:31 (15 years ago) parent97e28f774a25e8
1 file changed+40−29
Setup.hs+40−29
Setup.hs+40−29
@@ -1,42 +1,53 @@
11import Distribution.Simple
22import Distribution.Simple.InstallDirs as I
33import Distribution.Simple.LocalBuildInfo as L
4+import qualified Distribution.Simple.Setup as S
5+import qualified Distribution.Simple.Program as P
46import Distribution.PackageDescription
57
68import System.Exit
9+import System.FilePath ((</>))
710import System.Process
811
912-- After Idris is built, we need to check and install the prelude and other libs
1013
11−system' cmd = do
12− exit <- system cmd
13− case exit of
14− ExitSuccess -> return ()
15− ExitFailure _ -> exitWith exit
16−
17−postCleanLib args flags desc _
18− = system' "make -C lib clean"
19−
20−addPrefix pfx var c = "export " ++ var ++ "=" ++ show pfx ++ "/" ++ c ++ ":$" ++ var
21−
22−postInstLib args flags desc local
23− = do let pkg = localPkgDescr local
24− let penv = packageTemplateEnv (package pkg)
25− let cenv = compilerTemplateEnv (compilerId (compiler local))
26− let dirs_pkg = substituteInstallDirTemplates penv (installDirTemplates local)
27− let dirs = substituteInstallDirTemplates cenv dirs_pkg
28− let bind = fromPathTemplate (bindir dirs)
29− let progPart t = L.substPathTemplate (packageId desc) local (t local)
30− let progpfx = progPart progPrefix
31− let progsfx = progPart progSuffix
32− let PackageName pkgname = (packageName desc)
33− let icmd = bind ++ "/" ++ progpfx ++ pkgname ++ progsfx
34− let idir = fromPathTemplate (datadir dirs) ++ "/" ++
35− fromPathTemplate (datasubdir dirs)
36− putStrLn $ "Installing libraries in " ++ idir
37− system' $ "make -C lib install TARGET=" ++ idir ++ " IDRIS=" ++ icmd
14+make verbosity = P.runProgramInvocation verbosity . P.simpleProgramInvocation "make"
15+
16+cleanStdLib verbosity
17+ = make verbosity [ "-C", "lib", "clean" ]
3818
39−main = defaultMainWithHooks (simpleUserHooks { postInst = postInstLib,
40− postClean = postCleanLib })
19+installStdLib pkg local verbosity copy
20+ = do let dirs = L.absoluteInstallDirs pkg local copy
21+ let idir = datadir dirs
22+ let icmd = ".." </> buildDir local </> "idris" </> "idris"
23+ putStrLn $ "Installing libraries in " ++ idir
24+ make verbosity
25+ [ "-C", "lib", "install"
26+ , "TARGET=" ++ idir
27+ , "IDRIS=" ++ icmd
28+ ]
29+
30+checkStdLib local verbosity
31+ = do let icmd = ".." </> buildDir local </> "idris" </> "idris"
32+ putStrLn $ "Building libraries..."
33+ make verbosity
34+ [ "-C", "lib", "check"
35+ , "IDRIS=" ++ icmd
36+ ]
37+
38+-- Install libraries during both copy and install
39+-- See http://hackage.haskell.org/trac/hackage/ticket/718
40+main = defaultMainWithHooks $ simpleUserHooks
41+ { postCopy = \ _ flags pkg lbi -> do
42+ installStdLib pkg lbi (S.fromFlag $ S.copyVerbosity flags)
43+ (S.fromFlag $ S.copyDest flags)
44+ , postInst = \ _ flags pkg lbi -> do
45+ installStdLib pkg lbi (S.fromFlag $ S.installVerbosity flags)
46+ NoCopyDest
47+ , postClean = \ _ flags _ _ -> do
48+ cleanStdLib (S.fromFlag $ S.cleanVerbosity flags)
49+ , postBuild = \ _ flags _ lbi -> do
50+ checkStdLib lbi (S.fromFlag $ S.buildVerbosity flags)
51+ }
4152
4253