Permalink
Browse files

Retrieve the ghc lib dir at build time

  • Loading branch information...
1 parent c08458d commit d60973da14d35dc192a40e42826c9bea0fc2cdca jeanphilippe.bernardy@gmail.com committed Mar 1, 2007
Showing with 31 additions and 1 deletion.
  1. +1 −1 Makefile
  2. +30 −0 Setup.hs
View
@@ -6,7 +6,7 @@ gtk:
cd gtk && @runhaskell Setup.hs build
build:
- @runhaskell Setup.hs build
+ @runhaskell Setup.hs --with-ghc=ghc build
config:
@runhaskell Setup.hs configure
View
@@ -1,3 +1,33 @@
#!/usr/bin/env runhaskell
+module Main where
+
import Distribution.Simple
+import Distribution.PackageDescription
+import System.Info
+import System.Process
+import Data.List
+import System.IO
+--import Config
+
+main :: IO ()
main = defaultMainWithHooks defaultUserHooks
+ { preBuild = setConfigInfo }
+
+setConfigInfo args _
+ = getLibDir args >>= \libdir ->
+ return
+ (Nothing,
+ [("yi", emptyBuildInfo
+ { options = [(GHC,[mkOpt ("GHC_LIBDIR",show libdir)])] })])
+ where mkOpt (name,def) = "-D"++name++"="++def
+
+getLibDir [arg]
+ | "--with-ghc" `isPrefixOf` arg
+ = do (_, out, _, pid) <- runInteractiveProcess ghcPath ["--print-libdir"]
+ Nothing Nothing
+ libDir <- hGetLine out
+ waitForProcess pid
+ return libDir
+ where ghcPath = drop 1 (dropWhile (/='=') arg)
+
+getLibDir _ = error "failed to extract ghc path from command line"

0 comments on commit d60973d

Please sign in to comment.