-
Notifications
You must be signed in to change notification settings - Fork 1
/
Setup.hs
47 lines (38 loc) · 1.3 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
import Distribution.Simple
import Distribution.PackageDescription
import Distribution.Version
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program
import Distribution.Verbosity
import Control.Applicative
import Control.Monad
import Data.List
import Data.Maybe
main = defaultMainWithHooks simpleUserHooks {
hookedPrograms = [gpgmeConfigProgram],
confHook = \pkg flags -> do
lbi <- confHook simpleUserHooks pkg flags
bi <- psqlBuildInfo lbi
return lbi {
localPkgDescr = updatePackageDescription
(Just bi, []) (localPkgDescr lbi)
}
}
gpgmeConfigProgram = simpleProgram "gpgme-config"
psqlBuildInfo :: LocalBuildInfo -> IO BuildInfo
psqlBuildInfo lbi = do
(pgconfigProg, _) <- requireProgram verbosity
gpgmeConfigProgram (withPrograms lbi)
let gpgmeConfig = rawSystemProgramStdout verbosity pgconfigProg
incDirs <- hasPrefix "-I" <$> gpgmeConfig ["--cflags"]
libInfo <- gpgmeConfig ["--libs"]
let libDirs = hasPrefix "-L" libInfo
extraLibs = hasPrefix "-l" libInfo
return emptyBuildInfo
{ includeDirs = incDirs
, extraLibs = extraLibs
, extraLibDirs = libDirs
}
where
verbosity = normal -- honestly, this is a hack
hasPrefix pre = catMaybes . map (stripPrefix pre) . words