2012-12-14 15:52:44 -04:00
|
|
|
{- Makes standalone bundle.
|
|
|
|
-
|
2015-01-21 12:50:09 -04:00
|
|
|
- Copyright 2012 Joey Hess <id@joeyh.name>
|
2012-12-14 15:52:44 -04:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2013-04-17 11:57:46 -04:00
|
|
|
module Main where
|
|
|
|
|
2012-12-14 15:52:44 -04:00
|
|
|
import Control.Monad.IfElse
|
|
|
|
import System.Environment
|
|
|
|
import System.FilePath
|
|
|
|
import System.Directory
|
|
|
|
import Control.Monad
|
2013-05-14 19:59:14 -05:00
|
|
|
import Build.BundledPrograms
|
2012-12-14 15:52:44 -04:00
|
|
|
|
|
|
|
import Utility.SafeCommand
|
|
|
|
import Utility.Path
|
|
|
|
|
|
|
|
progDir :: FilePath -> FilePath
|
|
|
|
#ifdef darwin_HOST_OS
|
|
|
|
progDir topdir = topdir
|
|
|
|
#else
|
|
|
|
progDir topdir = topdir </> "bin"
|
|
|
|
#endif
|
|
|
|
|
2013-04-22 13:33:29 -04:00
|
|
|
installProg :: FilePath -> FilePath -> IO (FilePath, FilePath)
|
2012-12-14 15:52:44 -04:00
|
|
|
installProg dir prog = searchPath prog >>= go
|
|
|
|
where
|
|
|
|
go Nothing = error $ "cannot find " ++ prog ++ " in PATH"
|
2013-04-22 13:33:29 -04: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 15:52:44 -04:00
|
|
|
|
2013-12-30 13:19:22 -04:00
|
|
|
main :: IO ()
|
2012-12-14 15:52:44 -04:00
|
|
|
main = getArgs >>= go
|
|
|
|
where
|
|
|
|
go [] = error "specify topdir"
|
2014-10-09 15:09:26 -04:00
|
|
|
go (topdir:_) = do
|
2012-12-14 15:52:44 -04:00
|
|
|
let dir = progDir topdir
|
|
|
|
createDirectoryIfMissing True dir
|
2013-05-14 19:59:14 -05:00
|
|
|
installed <- forM bundledPrograms $ installProg dir
|
2013-04-22 13:33:29 -04:00
|
|
|
writeFile "tmp/standalone-installed" (show installed)
|