forked from WebAssembly/binaryen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup.hs
62 lines (59 loc) · 2.33 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{-# OPTIONS_GHC -Wall -threaded -rtsopts #-}
import Data.Foldable
import Distribution.Simple
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program
import Distribution.Simple.Setup
import Distribution.Types.LocalBuildInfo
import System.Directory
import System.FilePath
main :: IO ()
main =
defaultMainWithHooks
simpleUserHooks
{ hookedPrograms = [simpleProgram "cmake"],
postConf = \_ _ _ _ -> pure (),
buildHook = \pkg_descr lbi hooks flags -> do
buildHook simpleUserHooks pkg_descr lbi hooks flags
let verbosity = fromFlag (configVerbosity (configFlags lbi))
binaryen_builddir = binaryenBuildDir lbi
run prog args =
let Just conf_prog = lookupProgram prog (withPrograms lbi)
in runProgramInvocation
verbosity
(programInvocation conf_prog args)
for_
[ [ "-DCMAKE_BUILD_TYPE=Release",
"-DBUILD_STATIC_LIB=ON",
"-G",
"Unix Makefiles",
"-S",
"binaryen",
"-B",
binaryen_builddir
],
["--build", binaryen_builddir]
]
$ \args -> run (simpleProgram "cmake") args,
copyHook = \pkg_descr lbi hooks flags -> do
copyHook simpleUserHooks pkg_descr lbi hooks flags
let binaryen_builddir = binaryenBuildDir lbi
[clbi] = componentNameCLBIs lbi CLibName
binaryen_installdirs =
absoluteComponentInstallDirs
pkg_descr
lbi
(componentUnitId clbi)
(fromFlag (copyDest flags))
binaryen_libdir = libdir binaryen_installdirs
binaryen_bindir = bindir binaryen_installdirs
for_ [binaryen_libdir, binaryen_bindir] $ createDirectoryIfMissing True
renameFile
(binaryen_builddir </> "lib" </> "libbinaryen.a")
(binaryen_libdir </> "libbinaryen.a")
binaryen_bins <- listDirectory $ binaryen_builddir </> "bin"
for_ binaryen_bins $ \b ->
renameFile (binaryen_builddir </> "bin" </> b) (binaryen_bindir </> b)
}
binaryenBuildDir :: LocalBuildInfo -> FilePath
binaryenBuildDir = (</> "binaryen") . buildDir