hruby 0.2.3 → 0.2.4
raw patch · 2 files changed
+88/−40 lines, 2 filessetup-changed
Files
- Setup.hs +87/−39
- hruby.cabal +1/−1
Setup.hs view
@@ -5,6 +5,8 @@ import Distribution.Simple.Utils import Distribution.PackageDescription import System.Environment+import Data.List (partition,stripPrefix,foldl')+import Data.Maybe (mapMaybe) getBuildInfo :: LocalBuildInfo -> BuildInfo getBuildInfo l = case library (localPkgDescr l) of@@ -19,43 +21,89 @@ li' = li { libBuildInfo = b } lpd' = lpd { library = Just li' } -main :: IO ()-main = defaultMainWithHooks myhooks+validflags :: [String]+validflags = ["ruby18", "ruby19", "ruby20", "ruby21"]++can'tFindRuby :: String+can'tFindRuby = unlines $ [ "Could not find the ruby library. Ensure that it is present on your system (on Debian/Ubuntu, make sure you installed the ruby1.8-dev package)."+ , "If you know it to be installed, please install hruby in the following way:"+ , ""+ , "$ cabal install hruby -p --configure-option='--rubylib=ruby --rubyinc=/usr/include/ruby-2.1.0/x86_64-linux --rubyversion=21'"+ , ""+ , " --rubylib : Should be the name of the library passed to the linker (ruby for libruby.so)."+ , " --rubyinc : There can be several instances of this flag. Should be the path of the various ruby header files."+ , " --rubyversion : Mandatory for ruby 2.0 and 2.1, should have the values 20 or 21."+ ]++type InstallInfo = (String, [String], [String])++inc18,inc19,inc20,inc21 :: [String]+inc21 = ["/usr/include/ruby-2.1.0", "/usr/include/x86_64-linux-gnu/ruby-2.1.0", "/usr/include/ruby-2.1.0/x86_64-linux"]+inc20 = ["/usr/include/ruby-2.0.0", "/usr/include/x86_64-linux-gnu/ruby-2.0.0", "/usr/include/ruby-2.0.0/x86_64-linux"]+inc19 = ["/usr/lib/ruby/1.9/x86_64-linux"]+inc18 = ["/usr/lib/ruby/1.8/x86_64-linux"]++r18,r19,r20,r21 :: InstallInfo+r21 = ("ruby2.1", inc21, ["-DRUBY2","-DRUBY21"])+r20 = ("ruby2.0", inc20, ["-DRUBY2"])+r19 = ("ruby1.9", inc19, [])+r18 = ("ruby1.8", inc18, [])++defaultLib :: InstallInfo -> InstallInfo+defaultLib (_,i,c) = ("ruby",i,c)++myConfHook :: LocalBuildInfo -> IO LocalBuildInfo+myConfHook h = do+ -- hunt for libraries+ let rubies = ["ruby2.1", "ruby2.0", "ruby1.9", "ruby1.8", "ruby"]+ pathes = ["/usr/lib", "/usr/local/lib"]+ f <- findFirstFile (\(p,r) -> p ++ "/lib" ++ r ++ ".so") [(p,r) | p <- pathes, r <- rubies]+ let rubystring = maybe "" snd f+ lg s = notice normal ("Auto detected " ++ s)+ case fmap snd f of+ Just "ruby2.1" -> hookWith r21 h+ Just "ruby2.0" -> hookWith r20 h+ Just "ruby1.9" -> hookWith r19 h+ Just "ruby1.8" -> hookWith r18 h+ Just "ruby" -> do+ is21 <- findFirstFile id inc21+ is20 <- findFirstFile id inc20+ is19 <- findFirstFile id inc19+ is18 <- findFirstFile id inc18+ case filter ((/= Nothing) . fst) [(is21,r21), (is20,r20), (is19,r19), (is18,r18)] of+ ((_,(n,inc,flgs)):_) -> hookWith ("ruby",inc,flgs) h+ _ -> warn normal can'tFindRuby >> return h+ Just x -> die $ "Did find this (this should not happen): " ++ x+ _ -> warn normal can'tFindRuby >> return h++hookWith (e,i,c) h =+ let buildinfos = getBuildInfo h+ bi = buildinfos { extraLibs = e : extraLibs buildinfos+ , includeDirs = includeDirs buildinfos ++ i+ , ccOptions = ccOptions buildinfos ++ c+ }+ in putStrLn ("Detected parameters: " ++ show (e,i,c)) >> return (setBuildInfo h bi)++parseFlags :: [String] -> LocalBuildInfo -> IO LocalBuildInfo+parseFlags flags h = return $ setBuildInfo h $ foldl' parseFlags' bbi flags where- myhooks = simpleUserHooks { confHook = (\a b -> configure a b >>= myConfHook) }- myConfHook h = do- let buildinfos = getBuildInfo h- -- hunt for libraries- let rubies = ["ruby2.1", "ruby2.0", "ruby1.9", "ruby1.8", "ruby"]- pathes = ["/usr/lib", "/usr/local/lib"]- inc21 = ["/usr/include/ruby-2.1.0", "/usr/include/x86_64-linux-gnu/ruby-2.1.0", "/usr/include/ruby-2.1.0/x86_64-linux"]- inc20 = ["/usr/include/ruby-2.0.0", "/usr/include/x86_64-linux-gnu/ruby-2.0.0", "/usr/include/ruby-2.0.0/x86_64-linux"]- inc19 = ["/usr/lib/ruby/1.9/x86_64-linux"]- inc18 = ["/usr/lib/ruby/1.8/x86_64-linux"]- r21 = ("ruby2.1", inc21, ["-DRUBY2","-DRUBY21"])- r20 = ("ruby2.0", inc20, ["-DRUBY2"])- r19 = ("ruby1.9", inc19, [])- r18 = ("ruby1.8", inc18, [])- f <- findFirstFile (\(p,r) -> p ++ "/lib" ++ r ++ ".so") [(p,r) | p <- pathes, r <- rubies]- let rubystring = maybe "" snd f- lg s = notice normal ("Auto detected " ++ s)- (e,i,c) <- case fmap snd f of- Just "ruby2.1" -> lg rubystring >> return r21- Just "ruby2.0" -> lg rubystring >> return r20- Just "ruby1.9" -> lg rubystring >> return r19- Just "ruby1.8" -> lg rubystring >> return r18- Just "ruby" -> do- is21 <- findFirstFile id inc21- is20 <- findFirstFile id inc20- is19 <- findFirstFile id inc19- is18 <- findFirstFile id inc18- case filter ((/= Nothing) . fst) [(is21,r21), (is20,r20), (is19,r19), (is18,r18)] of- ((_,(n,inc,flgs)):_) -> lg n >> return ("ruby",inc,flgs)- _ -> die "Could not find the ruby library"- Just x -> die $ "Did find this (this should not happen): " ++ x- _ -> die "Could not find the ruby library"- let bi = buildinfos { extraLibs = e : extraLibs buildinfos- , includeDirs = includeDirs buildinfos ++ i- , ccOptions = ccOptions buildinfos ++ c- }- return (setBuildInfo h bi)+ bbi = getBuildInfo h+ parseFlags' bi fl = case (stripPrefix "--rubylib=" fl, stripPrefix "--rubyinc=" fl, stripPrefix "--rubyversion=" fl) of+ (Just l, _, _) -> bi { extraLibs = l : extraLibs bi }+ (_, Just l, _) -> bi { includeDirs = l : extraLibs bi }+ (_, _, Just "20") -> bi { ccOptions = "-DRUBY2" : ccOptions bi }+ (_, _, Just "21") -> bi { ccOptions = "-DRUBY2" : "-DRUBY21" : ccOptions bi }+ _ -> bi+ where+ rubylib = stripPrefix "--rubylib=" fl+ rubyinc = stripPrefix "--rubyinc=" fl++main :: IO ()+main = do+ args <- getArgs+ let flags = mapMaybe (stripPrefix "--configure-option=") args+ let hook = if null flags+ then myConfHook+ else parseFlags (concatMap words flags)+ defaultMainWithHooks $ simpleUserHooks { confHook = (\a b -> configure a b >>= hook) }+
hruby.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/ name: hruby-version: 0.2.3+version: 0.2.4 synopsis: Embed Ruby in your Haskell program. description: Warning: this is completely experimental. Everything you need should be in "Foreign.Ruby". license: BSD3