forked from paul-rouse/mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.hs
executable file
·79 lines (66 loc) · 2.46 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
74
75
76
77
78
79
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE CPP #-}
{- OPTIONS_GHC -Wall #-}
#ifndef MIN_VERSION_Cabal
#define MIN_VERSION_Cabal(x,y,z) 0
#endif
import Control.Monad (liftM, msum, sequence)
import Data.List (isPrefixOf, nub)
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 $ liftM msum $ sequence
#if MIN_VERSION_Cabal(1,24,0)
[ (findProgramOnSearchPath verbosity [ProgramSearchPathDefault] "mysql_config")
, (findProgramOnSearchPath verbosity [ProgramSearchPathDefault] "mysql_config5")
, (findProgramOnSearchPath verbosity [ProgramSearchPathDefault] "mariadb_config")
]
#else
[ (findProgramLocation verbosity "mysql_config")
, (findProgramLocation verbosity "mysql_config5")
, (findProgramLocation verbosity "mariadb_config")
]
#endif
}
mysqlBuildInfo :: LocalBuildInfo -> IO BuildInfo
mysqlBuildInfo lbi = do
#if MIN_VERSION_Cabal(2,0,0)
let mysqlConfig = fmap words . getDbProgramOutput normal
mysqlConfigProgram (withPrograms lbi)
#else
let mysqlConfig = fmap words . rawSystemProgramStdoutConf normal
mysqlConfigProgram (withPrograms lbi)
#endif
include <- mysqlConfig ["--include"]
libs <- mysqlConfig ["--libs"]
libsR <- mysqlConfig ["--libs_r"]
return emptyBuildInfo {
extraLibDirs = map (drop 2) . filter ("-L" `isPrefixOf`) $ libs
, extraLibs = map (drop 2) . filter ("-l" `isPrefixOf`) .
filter (/= "-lmygcc") $
filter (/= "-lmysqlclient_r") $
nub (libs ++ libsR)
, includeDirs = map (drop 2) include
}