summaryrefslogtreecommitdiff
path: root/Setup.hs
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2019-09-28 13:43:29 -0400
committerJoe Crayne <joe@jerkface.net>2020-01-01 19:27:53 -0500
commit11987749fc6e6d3e53ea737d46d5ab13a16faeb8 (patch)
tree5716463275c2d3e902889db619908ded2a73971c /Setup.hs
parentadd2c76bced51fde5e9917e7449ef52be70faf87 (diff)
Factor out some new libraries
word64-map: Data.Word64Map network-addr: Network.Address tox-crypto: Crypto.Tox lifted-concurrent: Control.Concurrent.Lifted.Instrument Control.Concurrent.Async.Lifted.Instrument psq-wrap: Data.Wrapper.PSQInt Data.Wrapper.PSQ minmax-psq: Data.MinMaxPSQ tasks: Control.Concurrent.Tasks kad: Network.Kademlia Network.Kademlia.Bootstrap Network.Kademlia.Routing Network.Kademlia.CommonAPI Network.Kademlia.Persistence Network.Kademlia.Search
Diffstat (limited to 'Setup.hs')
-rw-r--r--Setup.hs97
1 files changed, 0 insertions, 97 deletions
diff --git a/Setup.hs b/Setup.hs
deleted file mode 100644
index bd7c6d3e..00000000
--- a/Setup.hs
+++ /dev/null
@@ -1,97 +0,0 @@
1import Control.Applicative
2import Control.Monad
3import Data.List
4import Distribution.Simple
5import Distribution.Simple.LocalBuildInfo
6import Distribution.Simple.Setup
7import Distribution.Simple.Utils
8import System.Directory
9
10main = defaultMainWithHooks hooks
11
12hooks :: UserHooks
13hooks = simpleUserHooks
14 { buildHook = \pkgDesc localBuildInfo hooks flags -> do
15 let paths = (absoluteInstallDirs pkgDesc localBuildInfo dest)
16 {- libsubdir = "<undef>"
17 , datasubdir = "<undef>"
18 -}
19 dest = maybe NoCopyDest CopyTo $
20 flagToMaybe $ buildDistPref flags
21 buildSystemDConfig localBuildInfo paths
22 buildHook simpleUserHooks pkgDesc localBuildInfo hooks flags
23 , copyHook = \pkgDesc localBuildInfo hooks flags -> do
24 let paths = (absoluteInstallDirs pkgDesc localBuildInfo (fromFlag $ copyDest flags))
25 {- libsubdir = "<undef>"
26 , datasubdir = "<undef>"
27 -}
28 dest = maybe NoCopyDest CopyTo $
29 flagToMaybe $ copyDistPref flags
30 copySystemDConfig localBuildInfo paths flags
31 copyHook simpleUserHooks pkgDesc localBuildInfo hooks flags
32 }
33
34-- Drop a /-terminated prefix from a Filepath. The / is not dropped.
35dropPrefix :: String -> FilePath -> FilePath
36dropPrefix prefix s | prefix `isPrefixOf` s = drop (length prefix - 1) s
37 | otherwise = s
38
39exestart :: FilePath -> InstallDirs FilePath -> String -> String
40exestart buildprefix paths cmd
41 | "ExecStart=" `isPrefixOf` cmd = "ExecStart="++(dropPrefix buildprefix $ bindir paths) ++ "/presence"
42 | otherwise = cmd
43
44buildSystemDConfig :: LocalBuildInfo -> InstallDirs FilePath -> IO ()
45buildSystemDConfig buildInfo paths = do
46 template <- lines <$> readFile "presence.service"
47 let buildprefix = takeWhile (/='/') (buildDir buildInfo) ++ "/"
48 service = map (exestart buildprefix paths) template
49 createDirectoryIfMissing True (buildDir buildInfo)
50 writeFile (buildDir buildInfo ++ "/presence.service") $ unlines service
51
52preferredSystemDPath prefix =
53 case removeSlashes prefix of
54 "" -> "/lib/systemd/system"
55 "usr" -> "/lib/systemd/system"
56 _ -> "/etc/systemd/system"
57
58removeSlashes prefix = reverse $ dropWhile (=='/') $ reverse $ dropWhile (=='/') prefix
59
60-- InstallDirs {prefix = "dest/usr/local"
61-- , bindir = "dest/usr/local/bin"
62-- , libdir = "dest/usr/local/lib/x86_64-linux-ghc-8.0.2/presence-0.0.1-1fqjx0Frxyf1ESoA9cNUiZ"
63-- , libsubdir = "<undef>"
64-- , dynlibdir = "dest/usr/local/lib/x86_64-linux-ghc-8.0.2"
65-- , libexecdir = "dest/usr/local/libexec"
66-- , includedir = "dest/usr/local/lib/x86_64-linux-ghc-8.0.2/presence-0.0.1-1fqjx0Frxyf1ESoA9cNUiZ/include"
67-- , datadir = "dest/usr/local/share/x86_64-linux-ghc-8.0.2/presence-0.0.1"
68-- , datasubdir = "<undef>"
69-- , docdir = "dest/usr/local/share/doc/x86_64-linux-ghc-8.0.2/presence-0.0.1"
70-- , mandir = "dest/usr/local/share/man"
71-- , htmldir = "dest/usr/local/share/doc/x86_64-linux-ghc-8.0.2/presence-0.0.1/html"
72-- , haddockdir = "dest/usr/local/share/doc/x86_64-linux-ghc-8.0.2/presence-0.0.1/html"
73-- , sysconfdir = "dest/usr/local/etc"}
74-- CopyFlags
75-- { copyDest = Flag (CopyTo "dest/")
76-- , copyDistPref = Flag "dist"
77-- , copyVerbosity = Flag Verbose}
78-- realprefix = dest/usr/local
79
80copySystemDConfig :: LocalBuildInfo -> InstallDirs FilePath -> CopyFlags -> IO ()
81copySystemDConfig buildInfo paths flags = do
82 -- print paths
83 -- print flags
84 let verbosity = fromFlag (copyVerbosity flags)
85 built = buildDir buildInfo ++ "/presence.service"
86 realprefix = dropPrefix dest (prefix paths)
87 dest = case fromFlag (copyDest flags) of
88 NoCopyDest -> ""
89 CopyTo p -> p
90 sysddir = dest ++ drop 1 (preferredSystemDPath realprefix)
91 sysdpath = sysddir ++ "/presence.service"
92 -- putStrLn $ "realprefix = " ++ realprefix
93 -- putStrLn $ "no slashes = " ++ removeSlashes realprefix
94 -- putStrLn $ "sysdpath = " ++ sysdpath
95 createDirectoryIfMissing True sysddir
96 installOrdinaryFile verbosity built sysdpath
97