@@ -1,3 +1,4 @@
1+{-# LANGUAGE TemplateHaskell #-}
12import Distribution.Simple
23import Distribution.Simple.LocalBuildInfo
34import Distribution.Simple.Setup
@@ -9,6 +10,7 @@ import System.Process
910import System.Directory
1011import System.FilePath
1112import System.Exit
13+import Language.Haskell.TH (appE, varE, mkName, conE)
1214
1315main = defaultMainWithHooks hk
1416 where
@@ -32,7 +34,11 @@ cArgsHC = map ("-optc" ++) cArgs
3234
3335canUseRDRAND :: FilePath -> IO Bool
3436canUseRDRAND cc = do
35− withTempDirectory normal "" "testRDRAND" $ \tmpDir -> do
37+ -- Template haskell to call withTempDirectory in a backward compatible way
38+ -- withTempDirectory normal False "" "testRDRAND" $ \tmpDir -> do
39+ $(if cabalVersion >= Version [1,17,0] []
40+ then appE (appE (varE $ mkName "withTempDirectory") (varE 'normal)) (conE (mkName "False"))
41+ else appE (varE $ mkName "withTempDirectory") (varE 'normal)) "" "testRDRAND" $ \tmpDir -> do
3642 writeFile (tmpDir ++ "/testRDRAND.c")
3743 (unlines [ "#include <stdint.h>"
3844 , "int main() {"