summaryrefslogtreecommitdiff
path: root/Setup.hs
blob: 3f282e0aa9191313bd087e563f42a7f99db18b26 (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{-# LANGUAGE NamedFieldPuns #-}
{- cabal setup file -}

import Distribution.Simple
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Setup
import Distribution.Simple.Utils (installOrdinaryFiles, rawSystemExit)
import Distribution.PackageDescription (PackageDescription(..))
import Distribution.Verbosity (Verbosity)
import System.FilePath

import qualified Build.Configure as Configure

main = defaultMainWithHooks simpleUserHooks
	{ preConf = configure
	, postInst = myPostInst
	, postCopy = myPostCopy
	}

configure _ _ = do
	Configure.run Configure.tests
	return (Nothing, [])

myPostInst :: Args -> InstallFlags -> PackageDescription
           -> LocalBuildInfo -> IO ()
myPostInst _ (InstallFlags { installVerbosity }) pkg lbi = do
	installGitAnnexShell dest verbosity pkg lbi
	installManpages      dest verbosity pkg lbi
	where
		dest      = NoCopyDest
		verbosity = fromFlag installVerbosity

-- ???: Not sure how you're supposed to use this.  E.g., when I do
--
--    cabal install --prefix=/tmp/git-annex-install
--    cabal copy --deistdir=/tmp/git-annex-copy
--
-- I get the copy under
--
--   /tmp/git-annex-copy/tmp/git-annex-install
--
-- Also, `cabal install` fails when given a relative --prefix.
myPostCopy :: Args -> CopyFlags -> PackageDescription
           -> LocalBuildInfo -> IO ()
myPostCopy _ (CopyFlags { copyDest, copyVerbosity }) pkg lbi = do
	installGitAnnexShell dest verbosity pkg lbi
	installManpages      dest verbosity pkg lbi
	where
		dest      = fromFlag copyDest
		verbosity = fromFlag copyVerbosity

installGitAnnexShell :: CopyDest -> Verbosity -> PackageDescription
                     -> LocalBuildInfo -> IO ()
installGitAnnexShell copyDest verbosity pkg lbi =
	rawSystemExit verbosity "ln"
		["-sf", "git-annex", dstBinDir </> "git-annex-shell"]
	where
		dstBinDir = bindir $ absoluteInstallDirs pkg lbi copyDest

-- See http://www.haskell.org/haskellwiki/Cabal/Developer-FAQ#Installing_manpages.
--
-- Based on pandoc's and lhs2tex's 'Setup.installManpages' and
-- 'postInst' hooks.
--
-- My understanding: 'postCopy' is run for `cabal copy`, 'postInst' is
-- run for `cabal inst`, and copy is not a generalized install, so you
-- have to write two nearly identical hooks. 
--
-- Summary of hooks:
-- http://www.haskell.org/cabal/release/cabal-latest/doc/API/Cabal/Distribution-Simple-UserHooks.htm--
-- Other people are also confused:
--
-- * Bug: 'postCopy' and 'postInst' are confusing:
-- http://hackage.haskell.org/trac/hackage/ticket/718
--
-- * A cabal maintainer suggests using 'postCopy' instead of
-- 'postInst', because `cabal install` is `cabal copy` followed by
-- `cabal register`:
-- http://www.haskell.org/pipermail/libraries/2008-March/009416.html
-- Although that sounds desirable, it's not true, as the reply and
-- experiments indicate.
installManpages :: CopyDest -> Verbosity -> PackageDescription
                -> LocalBuildInfo -> IO ()
installManpages copyDest verbosity pkg lbi =
	installOrdinaryFiles verbosity dstManDir srcManpages
	where
		dstManDir   = mandir (absoluteInstallDirs pkg lbi copyDest) </> "man1"
		srcManpages = zip (repeat srcManDir) manpages
		srcManDir   = ""
		manpages    = ["git-annex.1", "git-annex-shell.1"]