-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSetup.hs
50 lines (45 loc) · 1.77 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
{-# LANGUAGE CPP #-}
module Main (main) where
import Distribution.Simple
import Distribution.Simple.Setup
import Distribution.Simple.Program
import Distribution.Simple.LocalBuildInfo
import Distribution.PackageDescription
import System.FilePath
import System.Environment (getEnv, setEnv)
import Distribution.Simple.LocalBuildInfo (installedPkgs)
import Distribution.Simple.PackageIndex (lookupDependency)
import Distribution.Package (Dependency, PackageName)
import Distribution.Version (anyVersion)
import Distribution.System (buildOS, OS(Windows, OSX))
import Distribution.InstalledPackageInfo
import System.IO.Error
_PackageName :: String -> PackageName
#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(2,0,0)
_PackageName = mkPackageName
#else
_PackageName = PackageName
#endif
main :: IO ()
main = defaultMainWithHooks (simpleUserHooks { buildHook = myBuildHook })
myBuildHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags -> IO ()
myBuildHook pkg_descr local_bld_info user_hooks bld_flags =
let fltkhsDependency = lookupDependency (installedPkgs local_bld_info) (_PackageName "fltkhs") anyVersion
keepBuilding = (buildHook simpleUserHooks) pkg_descr local_bld_info user_hooks bld_flags
in
case fmap snd fltkhsDependency of
[] -> keepBuilding
(packageInfo:_):_ ->
mapM_ (updateEnv "LIBRARY_PATH") (libraryDirs packageInfo) >>
keepBuilding
updateEnv :: String -> String -> IO ()
updateEnv env value = do
old <- tryIOError (getEnv env)
setEnv env ((either (const value)
(\old' -> value ++
(case buildOS of
Windows -> ";"
_ -> ":") ++
old'
)
old))