@@ -1,20 +1,29 @@
11{-# LANGUAGE TemplateHaskell #-}
2+{-# LANGUAGE CPP #-}
23module Data.FileEmbed
34 ( -- * Embed at compile time
45 embedFile
56 , embedDir
67 , getDir
78 -- * Inject into an executable
9+#if MIN_VERSION_template_haskell(2,5,0)
810 , dummySpace
11+#endif
912 , inject
1013 , injectFile
1114 ) where
1215
13−import Language.Haskell.TH (runQ,
14− Exp (AppE, ListE, LitE, TupE),
15− Lit (StringL, StringPrimL, IntegerL),
16− Q,
17− runIO)
16+import Language.Haskell.TH.Syntax
17+ ( runQ
18+ , Exp (AppE, ListE, LitE, TupE)
19+#if MIN_VERSION_template_haskell(2,5,0)
20+ , Lit (StringL, StringPrimL, IntegerL)
21+#else
22+ , Lit (StringL, IntegerL)
23+#endif
24+ , Q
25+ , runIO
26+ )
1827import System.Directory (doesDirectoryExist, doesFileExist,
1928 getDirectoryContents)
2029import Control.Monad (filterM)
@@ -57,7 +66,7 @@ pairToExp (path, bs) = do
5766
5867bsToExp :: B.ByteString -> Q Exp
5968bsToExp bs = do
60− helper <- runQ [| stringToBs |]
69+ helper <- [| stringToBs |]
6170 let chars = B8.unpack bs
6271 return $! AppE helper $! LitE $! StringL chars
6372
@@ -101,6 +110,7 @@ padSize i =
101110 let s = show i
102111 in replicate (sizeLen - length s) '0' ++ s
103112
113+#if MIN_VERSION_template_haskell(2,5,0)
104114dummySpace :: Int -> Q Exp
105115dummySpace space = do
106116 let size = padSize space
@@ -111,6 +121,7 @@ dummySpace space = do
111121 pack <- [|unsafePackAddressLen|]
112122 getInner' <- [|getInner|]
113123 return $ getInner' `AppE` (upi `AppE` (pack `AppE` len `AppE` chars))
124+#endif
114125
115126inject :: B.ByteString -- ^ bs to inject
116127 -> B.ByteString -- ^ original BS containing dummy