2012-11-27 05:59:43 +04:00
|
|
|
{-# LANGUAGE CPP #-}
|
2013-03-13 05:26:06 +04:00
|
|
|
import Control.Monad
|
|
|
|
import Data.IORef
|
|
|
|
|
2011-12-15 21:01:40 +04:00
|
|
|
import Distribution.Simple
|
|
|
|
import Distribution.Simple.InstallDirs as I
|
|
|
|
import Distribution.Simple.LocalBuildInfo as L
|
2012-02-20 08:20:38 +04:00
|
|
|
import qualified Distribution.Simple.Setup as S
|
|
|
|
import qualified Distribution.Simple.Program as P
|
2011-12-15 21:01:40 +04:00
|
|
|
import Distribution.PackageDescription
|
2013-03-13 05:26:06 +04:00
|
|
|
import Distribution.Text
|
2011-12-15 21:01:40 +04:00
|
|
|
|
|
|
|
import System.Exit
|
2012-11-29 07:31:06 +04:00
|
|
|
import System.FilePath ((</>), splitDirectories)
|
2013-03-13 05:26:06 +04:00
|
|
|
import System.Directory
|
2012-11-29 07:31:06 +04:00
|
|
|
import qualified System.FilePath.Posix as Px
|
2011-12-15 21:01:40 +04:00
|
|
|
import System.Process
|
2013-03-16 21:11:25 +04:00
|
|
|
import qualified Data.Text as T
|
|
|
|
import qualified Data.Text.IO as TIO
|
2011-12-15 21:01:40 +04:00
|
|
|
|
|
|
|
-- After Idris is built, we need to check and install the prelude and other libs
|
|
|
|
|
2012-02-20 08:20:38 +04:00
|
|
|
make verbosity = P.runProgramInvocation verbosity . P.simpleProgramInvocation "make"
|
2013-03-13 05:26:06 +04:00
|
|
|
mvn verbosity = P.runProgramInvocation verbosity . P.simpleProgramInvocation "mvn"
|
2012-02-20 08:20:38 +04:00
|
|
|
|
2012-11-27 05:59:43 +04:00
|
|
|
#ifdef mingw32_HOST_OS
|
|
|
|
-- make on mingw32 exepects unix style separators
|
2012-11-29 07:31:06 +04:00
|
|
|
(<//>) = (Px.</>)
|
2013-03-13 05:26:06 +04:00
|
|
|
idrisCmd local = Px.joinPath $ splitDirectories $
|
2012-11-29 07:31:06 +04:00
|
|
|
".." <//> buildDir local <//> "idris" <//> "idris"
|
2013-04-04 18:01:08 +04:00
|
|
|
rtsDir local = Px.joinPath $ splitDirectories $
|
|
|
|
".." <//> buildDir local <//> "rts" <//> "libidris_rts"
|
2012-11-27 05:59:43 +04:00
|
|
|
#else
|
2012-11-29 07:31:06 +04:00
|
|
|
idrisCmd local = ".." </> buildDir local </> "idris" </> "idris"
|
2013-04-04 18:01:08 +04:00
|
|
|
rtsDir local = ".." </> buildDir local </> "rts" </> "libidris_rts"
|
2012-11-27 05:59:43 +04:00
|
|
|
#endif
|
|
|
|
|
2012-02-20 08:20:38 +04:00
|
|
|
cleanStdLib verbosity
|
2013-03-01 17:52:51 +04:00
|
|
|
= do make verbosity [ "-C", "lib", "clean", "IDRIS=idris" ]
|
|
|
|
make verbosity [ "-C", "effects", "clean", "IDRIS=idris" ]
|
2011-12-15 21:01:40 +04:00
|
|
|
|
2013-03-13 05:26:06 +04:00
|
|
|
cleanJavaLib verbosity
|
|
|
|
= do dirty <- doesDirectoryExist ("java" </> "target")
|
|
|
|
when dirty $ mvn verbosity [ "-f", "java/pom.xml", "clean" ]
|
|
|
|
pomExists <- doesFileExist ("java" </> "pom.xml")
|
|
|
|
when pomExists $ removeFile ("java" </> "pom.xml")
|
2013-03-16 21:11:25 +04:00
|
|
|
execPomExists <- doesFileExist ("java" </> "executable_pom.xml")
|
|
|
|
when pomExists $ removeFile ("java" </> "executable_pom.xml")
|
2013-03-13 05:26:06 +04:00
|
|
|
|
2013-03-23 03:56:54 +04:00
|
|
|
installStdLib pkg local withoutEffects verbosity copy
|
2012-02-20 08:20:38 +04:00
|
|
|
= do let dirs = L.absoluteInstallDirs pkg local copy
|
|
|
|
let idir = datadir dirs
|
2012-11-27 05:59:43 +04:00
|
|
|
let icmd = idrisCmd local
|
2012-02-20 08:20:38 +04:00
|
|
|
putStrLn $ "Installing libraries in " ++ idir
|
|
|
|
make verbosity
|
2012-04-27 15:59:49 +04:00
|
|
|
[ "-C", "lib", "install"
|
2012-02-20 08:20:38 +04:00
|
|
|
, "TARGET=" ++ idir
|
|
|
|
, "IDRIS=" ++ icmd
|
|
|
|
]
|
2013-03-23 03:56:54 +04:00
|
|
|
unless withoutEffects $
|
|
|
|
make verbosity
|
|
|
|
[ "-C", "effects", "install"
|
|
|
|
, "TARGET=" ++ idir
|
|
|
|
, "IDRIS=" ++ icmd
|
|
|
|
]
|
2012-11-27 05:59:43 +04:00
|
|
|
let idirRts = idir </> "rts"
|
|
|
|
putStrLn $ "Installing run time system in " ++ idirRts
|
2012-04-10 17:49:03 +04:00
|
|
|
make verbosity
|
2012-05-14 17:06:47 +04:00
|
|
|
[ "-C", "rts", "install"
|
2012-11-27 05:59:43 +04:00
|
|
|
, "TARGET=" ++ idirRts
|
2012-05-14 17:06:47 +04:00
|
|
|
, "IDRIS=" ++ icmd
|
|
|
|
]
|
|
|
|
|
2013-03-16 21:11:25 +04:00
|
|
|
installJavaLib pkg local verbosity copy version = do
|
|
|
|
let rtsFile = "idris-" ++ display version ++ ".jar"
|
2013-03-17 13:18:57 +04:00
|
|
|
putStrLn $ "Installing java libraries"
|
2013-03-16 21:11:25 +04:00
|
|
|
mvn verbosity [ "install:install-file"
|
|
|
|
, "-Dfile=" ++ ("java" </> "target" </> rtsFile)
|
|
|
|
, "-DgroupId=org.idris-lang"
|
|
|
|
, "-DartifactId=idris"
|
|
|
|
, "-Dversion=" ++ display version
|
|
|
|
, "-Dpackaging=jar"
|
|
|
|
, "-DgeneratePom=True"
|
|
|
|
]
|
|
|
|
let dir = datadir $ L.absoluteInstallDirs pkg local copy
|
|
|
|
copyFile ("java" </> "executable_pom.xml") (dir </> "executable_pom.xml")
|
2013-03-13 05:26:06 +04:00
|
|
|
|
2012-05-14 17:06:47 +04:00
|
|
|
-- This is a hack. I don't know how to tell cabal that a data file needs
|
|
|
|
-- installing but shouldn't be in the distribution. And it won't make the
|
|
|
|
-- distribution if it's not there, so instead I just delete
|
|
|
|
-- the file after configure.
|
|
|
|
|
|
|
|
removeLibIdris local verbosity
|
2012-11-27 05:59:43 +04:00
|
|
|
= do let icmd = idrisCmd local
|
2012-05-14 17:06:47 +04:00
|
|
|
make verbosity
|
|
|
|
[ "-C", "rts", "clean"
|
2012-04-10 17:49:03 +04:00
|
|
|
, "IDRIS=" ++ icmd
|
|
|
|
]
|
2012-02-20 08:20:38 +04:00
|
|
|
|
2013-03-23 03:56:54 +04:00
|
|
|
checkStdLib local withoutEffects verbosity
|
2012-11-27 05:59:43 +04:00
|
|
|
= do let icmd = idrisCmd local
|
2012-02-20 08:20:38 +04:00
|
|
|
putStrLn $ "Building libraries..."
|
|
|
|
make verbosity
|
2012-04-27 15:59:49 +04:00
|
|
|
[ "-C", "lib", "check"
|
2013-03-01 17:52:51 +04:00
|
|
|
, "IDRIS=" ++ icmd
|
|
|
|
]
|
2013-03-23 03:56:54 +04:00
|
|
|
unless withoutEffects $
|
|
|
|
make verbosity
|
2013-03-01 17:52:51 +04:00
|
|
|
[ "-C", "effects", "check"
|
2012-02-20 08:20:38 +04:00
|
|
|
, "IDRIS=" ++ icmd
|
|
|
|
]
|
2012-04-10 17:49:03 +04:00
|
|
|
make verbosity
|
2012-05-14 17:06:47 +04:00
|
|
|
[ "-C", "rts", "check"
|
2012-04-10 17:49:03 +04:00
|
|
|
, "IDRIS=" ++ icmd
|
|
|
|
]
|
2012-02-20 08:20:38 +04:00
|
|
|
|
2013-03-16 21:11:25 +04:00
|
|
|
checkJavaLib verbosity = mvn verbosity [ "-f", "java" </> "pom.xml", "package" ]
|
2013-03-13 05:26:06 +04:00
|
|
|
|
2013-03-17 13:18:57 +04:00
|
|
|
javaFlag flags =
|
|
|
|
case lookup (FlagName "java") (S.configConfigurationsFlags flags) of
|
2013-03-13 05:26:06 +04:00
|
|
|
Just True -> True
|
|
|
|
Just False -> False
|
|
|
|
Nothing -> False
|
|
|
|
|
2013-03-23 03:56:54 +04:00
|
|
|
noEffectsFlag flags =
|
|
|
|
case lookup (FlagName "noeffects") (S.configConfigurationsFlags flags) of
|
|
|
|
Just True -> True
|
|
|
|
Just False -> False
|
|
|
|
Nothing -> False
|
|
|
|
|
2013-03-16 21:11:25 +04:00
|
|
|
preparePoms version
|
|
|
|
= do pomTemplate <- TIO.readFile ("java" </> "pom_template.xml")
|
|
|
|
TIO.writeFile ("java" </> "pom.xml") (insertVersion pomTemplate)
|
|
|
|
execPomTemplate <- TIO.readFile ("java" </> "executable_pom_template.xml")
|
|
|
|
TIO.writeFile ("java" </> "executable_pom.xml") (insertVersion execPomTemplate)
|
2013-03-13 05:26:06 +04:00
|
|
|
where
|
2013-03-16 21:11:25 +04:00
|
|
|
insertVersion template =
|
|
|
|
T.replace (T.pack "$RTS-VERSION$") (T.pack $ display version) template
|
2013-03-13 05:26:06 +04:00
|
|
|
|
2012-02-20 08:20:38 +04:00
|
|
|
-- Install libraries during both copy and install
|
|
|
|
-- See http://hackage.haskell.org/trac/hackage/ticket/718
|
2013-03-13 05:26:06 +04:00
|
|
|
main = do
|
|
|
|
defaultMainWithHooks $ simpleUserHooks
|
2012-02-20 08:20:38 +04:00
|
|
|
{ postCopy = \ _ flags pkg lbi -> do
|
2013-03-13 05:26:06 +04:00
|
|
|
let verb = S.fromFlag $ S.copyVerbosity flags
|
2013-03-23 03:56:54 +04:00
|
|
|
let withoutEffects = noEffectsFlag $ configFlags lbi
|
|
|
|
installStdLib pkg lbi withoutEffects verb
|
2012-02-20 08:20:38 +04:00
|
|
|
(S.fromFlag $ S.copyDest flags)
|
|
|
|
, postInst = \ _ flags pkg lbi -> do
|
2013-03-13 05:26:06 +04:00
|
|
|
let verb = (S.fromFlag $ S.installVerbosity flags)
|
2013-03-23 03:56:54 +04:00
|
|
|
let withoutEffects = noEffectsFlag $ configFlags lbi
|
|
|
|
installStdLib pkg lbi withoutEffects verb
|
2012-02-20 08:20:38 +04:00
|
|
|
NoCopyDest
|
2013-03-17 13:18:57 +04:00
|
|
|
when (javaFlag $ configFlags lbi)
|
|
|
|
(installJavaLib pkg
|
|
|
|
lbi
|
|
|
|
verb
|
|
|
|
NoCopyDest
|
|
|
|
(pkgVersion . package $ localPkgDescr lbi)
|
|
|
|
)
|
2012-05-14 17:06:47 +04:00
|
|
|
, postConf = \ _ flags _ lbi -> do
|
|
|
|
removeLibIdris lbi (S.fromFlag $ S.configVerbosity flags)
|
2013-03-17 13:18:57 +04:00
|
|
|
when (javaFlag $ configFlags lbi)
|
|
|
|
(preparePoms . pkgVersion . package $ localPkgDescr lbi)
|
2012-02-20 08:20:38 +04:00
|
|
|
, postClean = \ _ flags _ _ -> do
|
2013-03-13 05:26:06 +04:00
|
|
|
let verb = S.fromFlag $ S.cleanVerbosity flags
|
|
|
|
cleanStdLib verb
|
|
|
|
cleanJavaLib verb
|
2012-02-20 08:20:38 +04:00
|
|
|
, postBuild = \ _ flags _ lbi -> do
|
2013-03-13 05:26:06 +04:00
|
|
|
let verb = S.fromFlag $ S.buildVerbosity flags
|
2013-03-23 03:56:54 +04:00
|
|
|
let withoutEffects = noEffectsFlag $ configFlags lbi
|
|
|
|
checkStdLib lbi withoutEffects verb
|
2013-03-17 13:18:57 +04:00
|
|
|
when (javaFlag $ configFlags lbi) (checkJavaLib verb)
|
2012-02-20 08:20:38 +04:00
|
|
|
}
|