[allow extra C code to be bundled within .hl files, include bytestring in the standard external libraries.
John Meacham <john@repetae.net>**20120206153022
 Ignore-this: bc6f7918c92d8a0d8b62765fa7e7fa30
] hunk ./docs/make.mkd 108
+C-Sources
+: C files that should be linked into programs that utilize this library.
+
+Include-Sources
+: files that should be made available for inclusion when compiling the
+generated C code but don't need to be linked into the executable.
+
addfile ./lib/ext/bytestring.patch
hunk ./lib/ext/bytestring.patch 1
+Only in bytestring-0.9.2.0.jhc: bytestring.yaml
+diff -ru bytestring-0.9.2.0/Data/ByteString.hs bytestring-0.9.2.0.jhc/Data/ByteString.hs
+--- bytestring-0.9.2.0/Data/ByteString.hs	2011-08-25 05:19:31.000000000 -0700
++++ bytestring-0.9.2.0.jhc/Data/ByteString.hs	2012-02-06 04:48:48.116356373 -0800
+@@ -243,7 +243,7 @@
+ -- hGetBuf and hPutBuf not available in yhc or nhc
+ import System.IO                (stdin,stdout,hClose,hFileSize
+                                 ,hGetBuf,hPutBuf,openBinaryFile
+-                                ,IOMode(..))
++                                ,IOMode(..),Handle,hWaitForInput)
+ import System.IO.Error          (mkIOError, illegalOperationErrorType)
+ 
+ import Data.Monoid              (Monoid, mempty, mappend, mconcat)
+@@ -1910,7 +1910,7 @@
+   bytesWritten <- withForeignPtr ps $ \p-> hPutBufNonBlocking h (p `plusPtr` s) l
+   return $! drop bytesWritten bs
+ #else
+-hPutNonBlocking :: Handle -> B.ByteString -> IO Int
++hPutNonBlocking :: Handle -> ByteString -> IO ByteString
+ hPutNonBlocking h bs = hPut h bs >> return empty
+ #endif
+ 
addfile ./lib/ext/bytestring.yaml
hunk ./lib/ext/bytestring.yaml 1
+Name:                bytestring
+Version:             0.9.2.0
+Synopsis:            Fast, packed, strict and lazy byte arrays with a list interface
+Options: '-DMIN_VERSION_base(x,y,z)=0'
+exposed-modules:
+       - Data.ByteString
+       - Data.ByteString.Char8
+       - Data.ByteString.Unsafe
+       - Data.ByteString.Internal
+       - Data.ByteString.Lazy
+       - Data.ByteString.Lazy.Char8
+       - Data.ByteString.Lazy.Internal
+       - Data.ByteString.Fusion
+extensions:        [ CPP, ForeignFunctionInterface, NamedFieldPuns ]
+hs-source-dir:     .
+c-sources:         cbits/fpstring.c
+include-sources:   include/fpstring.h
hunk ./src/Grin/Main.hs 5
+import System.Directory
hunk ./src/Grin/Main.hs 10
+import qualified System.FilePath as FP
hunk ./src/Grin/Main.hs 92
-    let comm = shellQuote $ [cc] ++ ["-o", fn, cf] ++ args ++ (map ("-l" ++) rls)
+    tdir <- getTempDir
+    ds <- catch (getDirectoryContents (tdir FP.</> "cbits")) (\_ -> return [])
+    let extraCFiles = ["-I" ++ tdir ++ "/cbits" ] ++ [ tdir FP.</> "cbits" FP.</> fn | fn@(reverse -> 'c':'.':_) <- ds ] 
+    let comm = shellQuote $ [cc] ++ ["-o", fn, cf] ++ args ++ (map ("-l" ++) rls) ++ extraCFiles
hunk ./src/Grin/Main.hs 98
-    LBS.writeFile cf $ LBS.intercalate (LBS.fromString "\n") [globalvar "jhc_c_compile" comm, globalvar "jhc_command" argstring,globalvar "jhc_version" sversion,LBS.empty,cg]
+    LBS.writeFile cf $ LBS.intercalate (LBS.fromString "\n") [
+        globalvar "jhc_c_compile" comm, globalvar "jhc_command" argstring,
+        globalvar "jhc_version" sversion,LBS.empty,cg]
hunk ./src/Ho/Binary.hs 39
-    (_fn',hoh,fc) <- readHFile fn
+    (_fn,hoh,fc) <- readHFile fn
hunk ./src/Ho/Binary.hs 93
-    let cfflbs = mkCFFfile cff_magic [
+    let cfflbs = mkCFFfile cff_magic $ [
hunk ./src/Ho/Binary.hs 97
-            (cff_lcor, compress $ encode $ libBuildMap l)]
+            (cff_lcor, compress $ encode $ libBuildMap l),
+            (cff_file, compress $ encode $ libExtraFiles l)]
hunk ./src/Ho/Binary.hs 106
-    return Library { libHoHeader = hoh, libHoLib =  fc cff_libr, libTcMap = fc cff_ldef, libBuildMap = fc cff_lcor, libFileName = fn }
+    return Library { libHoHeader = hoh, libHoLib =  fc cff_libr,
+        libTcMap = fc cff_ldef, libBuildMap = fc cff_lcor,
+        libFileName = fn, libExtraFiles = fc cff_file }
+
+instance Binary ExtraFile where
+    put (ExtraFile a b) = put (a,b)
+    get = do
+        (x,y) <- get
+        return $ ExtraFile x y
hunk ./src/Ho/Build.hs 58
+import Support.TempDir
hunk ./src/Ho/Build.hs 445
+    forM_ (concatMap libExtraFiles (es ++ is)) $ \ef -> do
+        fileInTempDir ("cbits/" ++ unpackPS (extraFileName ef)) $ \fn -> BS.writeFile fn (extraFileData ef)
+
hunk ./src/Ho/Build.hs 659
-        (desc,name,vers,hmods,emods, modOpts) <- parse fp
+        (desc,name,vers,hmods,emods,modOpts,sources) <- parse fp
hunk ./src/Ho/Build.hs 711
-        recordHlFile Library { libHoHeader = hoh, libHoLib =  libr, libTcMap = ldef, libBuildMap = lcor, libFileName = outName }
+        efs <- mapM fetchExtraFile sources
+        recordHlFile Library { libHoHeader = hoh, libHoLib =  libr, libTcMap = ldef,
+            libBuildMap = lcor, libFileName = outName, libExtraFiles = efs }
hunk ./src/Ho/Build.hs 741
-        return (Map.toList dsing,name,vers,hmods,emods, modOpts)
+            sources = map (FP.takeDirectory fp FP.</>) $ snub $ mfield "c-sources" ++ mfield "include-sources"
+        return (Map.toList dsing,name,vers,hmods,emods,modOpts,sources)
+
+fetchExtraFile fp = do
+    c <- BS.readFile fp
+    return ExtraFile { extraFileName = packString (FP.takeFileName fp),
+                       extraFileData = c }
hunk ./src/Ho/Library.hs 221
+    "c-sources",
+    "include-sources",
hunk ./src/Ho/Type.hs 4
+import qualified Data.ByteString as BS
hunk ./src/Ho/Type.hs 35
+cff_file  = chunkType "FILE"
hunk ./src/Ho/Type.hs 115
+    libExtraFiles :: [ExtraFile],
hunk ./src/Ho/Type.hs 154
+data ExtraFile = ExtraFile {
+    extraFileName :: PackedString,
+    extraFileData :: BS.ByteString
+    }
+
hunk ./utils/build_extlibs.prl 45
-    $options = "$options --deps tmp/$name-$version.yaml" if $opt_d;
+    $options = "$options --deps tmp/$name-$version-deps.yaml" if $opt_d;
hunk ./utils/build_extlibs.prl 58
-    mysystem("./jhc $options " . ($ENV{JHC_TEST} || "") . " --build-hl $fn -L- -L. -i- '-i$tmpdir/$name-$version$src'") and die "$!: jhc";
+    mysystem("cp '$fn' '$tmpdir/$name-$version'");
+    $fn =~ s/.*\///;
+    mysystem("./jhc $options " . ($ENV{JHC_TEST} || "") .
+        " --build-hl '$tmpdir/$name-$version/$fn' -L- -L. -i- '-i$tmpdir/$name-$version$src'") and die "$!: jhc";
hunk ./utils/build_extlibs.prl 63
-
-