forked from paul-rouse/mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.hs
59 lines (46 loc) · 1.8 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
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE CPP #-}
{- OPTIONS_GHC -Wall #-}
import Control.Monad (liftM2, mplus)
import Data.List (isPrefixOf)
import Distribution.PackageDescription
import Distribution.Simple
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program
import Distribution.Verbosity
-- A Cabal 1.16 vs 1.18 compatibility hack, as in 1.18
-- findProgramLocation has a new (unused in this case) parameter.
-- ConstOrId adds this parameter when types say it is mandatory.
class ConstOrId a b where
constOrId :: a -> b
instance ConstOrId a a where
constOrId = id
instance ConstOrId a (b -> a) where
constOrId = const
main = defaultMainWithHooks simpleUserHooks {
hookedPrograms = [mysqlConfigProgram],
confHook = \pkg flags -> do
lbi <- confHook simpleUserHooks pkg flags
bi <- mysqlBuildInfo lbi
return lbi {
localPkgDescr = updatePackageDescription (Just bi, []) (localPkgDescr lbi)
}
}
mysqlConfigProgram = (simpleProgram "mysql_config") {
programFindLocation = \verbosity -> constOrId $ liftM2 mplus
(findProgramOnSearchPath verbosity [ProgramSearchPathDefault] "mysql_config")
(findProgramOnSearchPath verbosity [ProgramSearchPathDefault] "mysql_config5")
}
mysqlBuildInfo :: LocalBuildInfo -> IO BuildInfo
mysqlBuildInfo lbi = do
let mysqlConfig = fmap words . rawSystemProgramStdoutConf normal
mysqlConfigProgram (withPrograms lbi)
include <- mysqlConfig ["--include"]
libs <- mysqlConfig ["--libs"]
return emptyBuildInfo {
extraLibDirs = map (drop 2) . filter ("-L" `isPrefixOf`) $ libs
, extraLibs = map (drop 2) . filter ("-l" `isPrefixOf`) .
filter (/= "-lmygcc") $ libs
, includeDirs = map (drop 2) include
}