2012-12-14 19:52:44 +00:00
|
|
|
{- Makes standalone bundle.
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2012 Joey Hess <id@joeyh.name>
|
2012-12-14 19:52:44 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2013-04-17 15:57:46 +00:00
|
|
|
module Main where
|
|
|
|
|
2012-12-14 19:52:44 +00:00
|
|
|
import Control.Monad.IfElse
|
|
|
|
import System.Environment
|
|
|
|
import System.FilePath
|
|
|
|
import System.Directory
|
|
|
|
import Control.Monad
|
2013-05-15 00:59:14 +00:00
|
|
|
import Build.BundledPrograms
|
2012-12-14 19:52:44 +00:00
|
|
|
|
|
|
|
import Utility.SafeCommand
|
|
|
|
import Utility.Path
|
|
|
|
|
|
|
|
progDir :: FilePath -> FilePath
|
|
|
|
#ifdef darwin_HOST_OS
|
|
|
|
progDir topdir = topdir
|
|
|
|
#else
|
|
|
|
progDir topdir = topdir </> "bin"
|
|
|
|
#endif
|
|
|
|
|
2016-02-19 20:19:19 +00:00
|
|
|
extraProgDir :: FilePath -> FilePath
|
|
|
|
extraProgDir topdir = topdir </> "extra"
|
|
|
|
|
2013-04-22 17:33:29 +00:00
|
|
|
installProg :: FilePath -> FilePath -> IO (FilePath, FilePath)
|
2012-12-14 19:52:44 +00:00
|
|
|
installProg dir prog = searchPath prog >>= go
|
|
|
|
where
|
|
|
|
go Nothing = error $ "cannot find " ++ prog ++ " in PATH"
|
2013-04-22 17:33:29 +00:00
|
|
|
go (Just f) = do
|
|
|
|
let dest = dir </> takeFileName f
|
|
|
|
unlessM (boolSystem "install" [File f, File dest]) $
|
|
|
|
error $ "install failed for " ++ prog
|
|
|
|
return (dest, f)
|
2012-12-14 19:52:44 +00:00
|
|
|
|
2013-12-30 17:19:22 +00:00
|
|
|
main :: IO ()
|
2012-12-14 19:52:44 +00:00
|
|
|
main = getArgs >>= go
|
|
|
|
where
|
|
|
|
go [] = error "specify topdir"
|
2014-10-09 19:09:26 +00:00
|
|
|
go (topdir:_) = do
|
2016-02-19 20:19:19 +00:00
|
|
|
installed <- forM
|
|
|
|
[ (progDir topdir, preferredBundledPrograms)
|
|
|
|
, (extraProgDir topdir, extraBundledPrograms) ] $ \(dir, progs) -> do
|
|
|
|
createDirectoryIfMissing True dir
|
|
|
|
forM progs $ installProg dir
|
|
|
|
writeFile "tmp/standalone-installed" (show (concat installed))
|