forked from ryantm/hdbc-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.lhs
58 lines (47 loc) · 1.73 KB
/
Setup.lhs
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
#!/usr/bin/env runhaskell
\begin{code}
import Distribution.Simple
import Distribution.PackageDescription
import Distribution.Version
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program
import Distribution.Verbosity
import Data.Char (isSpace)
import Data.List (dropWhile,span)
import Control.Monad
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 _ -> do
mysql_config <- findProgramOnSearchPath verbosity defaultProgramSearchPath "mysql_config"
mysql_config5 <- findProgramOnSearchPath verbosity defaultProgramSearchPath "mysql_config5"
return (mysql_config `mplus` mysql_config5)
}
mysqlBuildInfo :: LocalBuildInfo -> IO BuildInfo
mysqlBuildInfo lbi = do
let mysqlConfig = rawSystemProgramStdoutConf verbosity mysqlConfigProgram (withPrograms lbi)
ws = " \n\r\t"
includeDirs <- return . map (drop 2) . split ws =<< mysqlConfig ["--include"]
ldOptions <- return . split ws =<< mysqlConfig ["--libs"]
return emptyBuildInfo {
ldOptions = ldOptions,
includeDirs = includeDirs
}
where
verbosity = normal -- honestly, this is a hack
split :: Eq a => [a] -> [a] -> [[a]]
split xs cs = split' $ dropWhile (`elem` xs) cs
where split' [] = []
split' cs0 =
let (run, cs1) = span (`notElem` xs) cs0
cs2 = dropWhile (`elem` xs) cs1
in run:(split' cs2)
\end{code}