-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetup.hs
More file actions
67 lines (57 loc) · 2.79 KB
/
Copy pathSetup.hs
File metadata and controls
67 lines (57 loc) · 2.79 KB
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
{-# options_ghc -Wall -Werror -fwarn-incomplete-uni-patterns -fwarn-incomplete-record-updates #-}
{-# Language BlockArguments #-}
{-# Language NamedFieldPuns #-}
import Control.Exception (bracket_)
import Control.Monad (unless)
import Data.List (isSuffixOf)
import Distribution.PackageDescription (emptyHookedBuildInfo)
import Distribution.Simple (defaultMainWithHooks, preBuild, postBuild, simpleUserHooks)
import Distribution.Simple.Setup (BuildFlags(..), fromFlagOrDefault)
import Distribution.Simple.Utils (maybeExit, rawSystemIOWithEnv)
import Distribution.Types.LocalBuildInfo (LocalBuildInfo(..), localCompatPackageKey)
import Distribution.Verbosity (Verbosity, normal)
import System.Directory (createDirectory, doesFileExist, listDirectory, removeDirectoryRecursive)
main :: IO ()
main = defaultMainWithHooks simpleUserHooks
{ preBuild = \_ flags -> do
let verbosity = fromFlagOrDefault normal $ buildVerbosity flags
rawSystemIO command args = rawSystemIOWithCwd verbosity command args $ Just "hwloc"
autogend <- doesFileExist "hwloc/configure"
configured <- (autogend &&) <$> doesFileExist "hwloc/Makefile"
made <- (configured &&) <$> doesFileExist "hwloc/hwloc/.libs/libhwloc.a"
unless autogend $ rawSystemIO "sh" ["autogen.sh"]
unless configured $ rawSystemIO "sh"
[ "configure"
, "--enable-static"
, "--disable-shared"
, "--disable-picky"
, "--disable-cairo"
, "--disable-cpuid"
, "--disable-libxml2"
, "--disable-io"
, "--disable-pci"
, "--disable-opencl"
, "--disable-cuda"
, "--disable-nvml"
, "--disable-gl"
, "--disable-libudev"
, "--disable-netloc"
]
unless made $ rawSystemIO "make" ["-C", "hwloc", "LDFLAGS=-all-static"]
pure emptyHookedBuildInfo
, postBuild = \_ BuildFlags { buildVerbosity } _ lbi@LocalBuildInfo { buildDir } -> do
let libName = "libHS" <> localCompatPackageKey lbi <> ".a"
libPath = buildDir <> "/" <> libName
verbosity = fromFlagOrDefault normal buildVerbosity
objDir = ".objhwloc"
bracket_ (createDirectory objDir) (removeDirectoryRecursive objDir) do
let rawSystemIO command args = rawSystemIOWithCwd verbosity command args $ Just objDir
rawSystemIO "pwd" []
rawSystemIO "ar" ["-x", "../hwloc/hwloc/.libs/libhwloc.a"]
rawSystemIO "ar" ["-x", ".." <> "/" <> libPath]
objects <- filter (".o" `isSuffixOf`) <$> listDirectory ".objhwloc"
rawSystemIO "ar" $ ["-r", ".." <> "/" <> libPath] ++ objects
}
rawSystemIOWithCwd :: Verbosity -> String -> [String] -> Maybe FilePath -> IO ()
rawSystemIOWithCwd verbosity command args cwd = maybeExit do
rawSystemIOWithEnv verbosity command args cwd Nothing Nothing Nothing Nothing