This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Setup.hs
46 lines (38 loc) · 1.65 KB
/
Setup.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wall -Werror #-}
module Main (main) where
import Prelude
import Data.Foldable (forM_)
import Data.List (isPrefixOf)
import System.Directory
import System.FilePath ((</>))
import Distribution.PackageDescription (PackageDescription)
import Distribution.Simple
import Distribution.Simple.InstallDirs (InstallDirs(..))
import Distribution.Simple.LocalBuildInfo
(LocalBuildInfo(..), absoluteInstallDirs)
import Distribution.Simple.Setup
import Distribution.Simple.Utils (installExecutableFile)
main :: IO ()
main = defaultMainWithHooks simpleUserHooks
{postCopy = copySubCommands}
-- | Installs all files matching @bin/rad-*@ into the configured
-- @bindir@, say @/usr/local/bin@.
copySubCommands :: Args -> CopyFlags -> PackageDescription -> LocalBuildInfo -> IO ()
copySubCommands _args copyFlags packageDescription localBuildInfo = do
let copyDest' = fromFlag $ copyDest copyFlags
let targetBindir = bindir $ absoluteInstallDirs packageDescription localBuildInfo copyDest'
let verbosity = fromFlag $ configVerbosity $ configFlags localBuildInfo
subCommands <- getSubCommands
forM_ subCommands $ \name ->
installExecutableFile verbosity (searchDir </> name) (targetBindir </> name)
where
radPrefix :: String
radPrefix = "rad-"
searchDir :: FilePath
searchDir = "bin"
getSubCommands :: IO [String]
getSubCommands = do
files <- listDirectory searchDir
pure $ filter (isPrefixOf radPrefix) files