forked from haskoin/secp256k1-haskell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.hs
63 lines (57 loc) · 2.14 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
import Control.Monad
import Distribution.PackageDescription
import Distribution.Simple
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Setup
import Distribution.Simple.Utils
import Distribution.Verbosity
import System.Environment
import System.Exit
main :: IO ()
main = defaultMainWithHooks autoconfUserHooks
{ preConf = autogen
, postConf = configure
, preBuild = make
, preClean = clean
}
runInRepo :: Verbosity
-> FilePath
-> [String]
-> Maybe [(String, String)]
-> IO ExitCode
runInRepo v prog args envM = rawSystemIOWithEnv v
prog args (Just "secp256k1") envM Nothing Nothing Nothing
autogen :: Args -> ConfigFlags -> IO HookedBuildInfo
autogen _ flags = do
maybeExit $ runInRepo v "sh" ["./autogen.sh"] Nothing
return emptyHookedBuildInfo
where
v = fromFlag $ configVerbosity flags
configure :: Args -> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO ()
configure args flags pd lbi = do
(ccProg, ccFlags) <- configureCCompiler v programConfig
env <- getEnvironment
let env' = appendToEnvironment ("CFLAGS", unwords ccFlags) env
args' = args ++ ["--with-gcc=" ++ ccProg]
maybeExit $ runInRepo v "sh" args' (Just env')
where
args = "./configure" : "--enable-module-recovery" : configureArgs False flags
v = fromFlag $ configVerbosity flags
appendToEnvironment (key, val) [] = [(key, val)]
appendToEnvironment (key, val) (kv@(k, v) : rest)
| key == k = (key, v ++ " " ++ val) : rest
| otherwise = kv : appendToEnvironment (key, val) rest
programConfig = withPrograms lbi
make :: Args -> BuildFlags -> IO HookedBuildInfo
make _ flags = do
runInRepo v "make" ["clean"] Nothing
runInRepo v "make" ["src/ecmult_static_context.h"] Nothing
return emptyHookedBuildInfo
where
v = fromFlag $ buildVerbosity flags
clean :: Args -> CleanFlags -> IO HookedBuildInfo
clean _ flags = do
runInRepo v "make" ["clean"] Nothing
return emptyHookedBuildInfo
where
v = fromFlag $ cleanVerbosity flags