-
Notifications
You must be signed in to change notification settings - Fork 1
/
Setup.hs
73 lines (63 loc) · 2.84 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
63
64
65
66
67
68
69
70
71
72
73
import Distribution.PackageDescription
import Distribution.Simple
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program
import Distribution.Simple.Program.Db
import Distribution.Simple.Setup
import Distribution.Simple.Utils
import Distribution.Verbosity
import System.FilePath
import System.Process (callProcess)
libdet, libdetC, libdetSO :: FilePath
libdet = "cbits" </> "libdet"
libdetC = libdet <.> "c"
libdetSO = libdet <.> "so"
detMonadBuildHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags
-> IO ()
detMonadBuildHook pkgDesc lbi hooks buildFlags = do
buildSO (\pd -> buildHook simpleUserHooks pd lbi hooks buildFlags)
(fromFlag $ buildVerbosity buildFlags) pkgDesc
detMonadReplHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> ReplFlags
-> [String] -> IO ()
detMonadReplHook pkgDesc lbi hooks replFlags args = do
buildSO (\pd -> replHook simpleUserHooks pd lbi hooks replFlags args)
(fromFlag $ replVerbosity replFlags) pkgDesc
detMonadCopyHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> CopyFlags
-> IO ()
detMonadCopyHook pkgDesc lbi hooks copyFlags =
copySOToDataFiles (\pd -> copyHook simpleUserHooks pd lbi hooks copyFlags)
(fromFlag $ copyVerbosity copyFlags) pkgDesc
detMonadInstHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> InstallFlags
-> IO ()
detMonadInstHook pkgDesc lbi hooks instFlags =
copySOToDataFiles (\pd -> instHook simpleUserHooks pd lbi hooks instFlags)
(fromFlag $ installVerbosity instFlags) pkgDesc
buildSO :: (PackageDescription -> IO ())
-> Verbosity -> PackageDescription -> IO ()
buildSO act verbosity pkgDesc = do
notice verbosity $ "Building libdet.so"
(gcc, _) <- requireProgram verbosity gccProgram defaultProgramDb
runProgram verbosity gcc $ words $
"-std=c99 -Wall -fPIC -shared -Wl,--no-as-needed -o " ++
libdetSO ++ " " ++ libdetC ++ " " ++ "-ldl -lm"
copySOToDataFiles act verbosity pkgDesc
copySOToDataFiles :: (PackageDescription -> IO ())
-> Verbosity -> PackageDescription -> IO ()
copySOToDataFiles act verbosity pkgDesc = do
notice verbosity $ "Copying " ++ libdetSO ++ " to data-files"
let pkgDesc' = pkgDesc { dataFiles = libdetSO : dataFiles pkgDesc }
act pkgDesc'
detMonadPostClean :: Args -> CleanFlags -> PackageDescription -> ()
-> IO ()
detMonadPostClean args cleanFlags pkgDesc lbi = do
let verbosity = fromFlag $ cleanVerbosity cleanFlags
notice verbosity $ "Removing libdet.so"
callProcess "rm" ["-f", libdetSO]
main :: IO ()
main = defaultMainWithHooks simpleUserHooks
{ buildHook = detMonadBuildHook
, replHook = detMonadReplHook
, postClean = detMonadPostClean
, copyHook = detMonadCopyHook
, instHook = detMonadInstHook
}