Merge pull request #60 from eagletmt/ffi-link

Enable dynamic linking for FFI
This commit is contained in:
Kazu Yamamoto 2012-03-23 21:16:29 -07:00
commit eb48b8290a
2 changed files with 9 additions and 15 deletions

View File

@ -1,4 +1,4 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
module Cabal (initializeGHC) where
@ -16,7 +16,6 @@ import GHC
import GHCApi
import GHCChoice
import qualified Gap
import Language.Haskell.Extension
import System.Directory
import System.FilePath
import Types
@ -34,12 +33,13 @@ initializeGHC opt fileName ghcOptions logging = withCabal ||> withoutCabal
return (fileName,logReader)
withCabal = do
(owdir,cdir,cfile) <- liftIO getDirs
binfo <- liftIO $ parseCabalFile cfile
let (idirs',exts',mlang) = extractBuildInfo binfo
exts = map (addX . Gap.extensionToString) exts'
lang = maybe "-XHaskell98" (addX . show) mlang
gopts = ghcOptions ++ exts ++ [lang]
idirs = case idirs' of
binfo@BuildInfo{..} <- liftIO $ parseCabalFile cfile
let exts = map (addX . Gap.extensionToString) $ usedExtensions binfo
lang = maybe "-XHaskell98" (addX . show) defaultLanguage
libs = map ("-l" ++) extraLibs
libDirs = map ("-L" ++) extraLibDirs
gopts = ghcOptions ++ exts ++ [lang] ++ libs ++ libDirs
idirs = case hsSourceDirs of
[] -> [cdir,owdir]
dirs -> map (cdir </>) dirs ++ [owdir]
logReader <- initSession opt gopts idirs logging
@ -59,12 +59,6 @@ parseCabalFile file = do
toMaybe [] = Nothing
toMaybe (x:_) = Just x
-- SourceDirs, Extensions, and Language
extractBuildInfo :: BuildInfo -> ([String],[Extension],Maybe Language)
extractBuildInfo binfo = (hsSourceDirs binfo
,usedExtensions binfo
,defaultLanguage binfo)
----------------------------------------------------------------
-- CurrentWorkingDir, CabalDir, CabalFile

View File

@ -45,7 +45,7 @@ setFlags opt d idirs
d' = d {
packageFlags = ghcPackage : packageFlags d
, importPaths = idirs
, ghcLink = NoLink
, ghcLink = LinkInMemory
, hscTarget = HscInterpreted
, flags = flags d
}