Setup.hs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. {-# LANGUAGE CPP #-}
  2. import Distribution.Simple
  3. import Distribution.Simple.LocalBuildInfo
  4. import Distribution.Simple.Setup
  5. import Distribution.Simple.BuildPaths (exeExtension)
  6. import Distribution.PackageDescription
  7. -- ASR (2018-07-20): GHC 7.10 does not support the macro
  8. -- @MIN_VERSION_Cabal@.
  9. #if __GLASGOW_HASKELL__ > 710
  10. #if MIN_VERSION_Cabal(2,3,0)
  11. import Distribution.System ( buildPlatform )
  12. #endif
  13. #endif
  14. import System.FilePath
  15. import System.FilePath.Find
  16. import System.Process
  17. import System.Exit
  18. main = defaultMainWithHooks hooks
  19. hooks = simpleUserHooks { regHook = checkAgdaPrimitiveAndRegister }
  20. builtins :: FilePath -> IO [FilePath]
  21. builtins = find always (extension ==? ".agda")
  22. agdaExeExtension :: String
  23. -- ASR (2018-07-20): GHC 7.10 does not support the macro
  24. -- @MIN_VERSION_Cabal@.
  25. #if __GLASGOW_HASKELL__ > 710
  26. #if MIN_VERSION_Cabal(2,3,0)
  27. agdaExeExtension = exeExtension buildPlatform
  28. #else
  29. agdaExeExtension = exeExtension
  30. #endif
  31. #else
  32. agdaExeExtension = exeExtension
  33. #endif
  34. checkAgdaPrimitive :: PackageDescription -> LocalBuildInfo -> RegisterFlags -> IO ()
  35. -- ASR (2018-12-23): This fun run twice using Cabal < 2.0.0.0. Because
  36. -- GHC 7.10 does not support the macro @MIN_VERSION_Cabal@, I only
  37. -- could avoid the second run of this function on GHC > 7.10. See
  38. -- Issue #3444.
  39. #if __GLASGOW_HASKELL__ > 710
  40. #if !MIN_VERSION_Cabal(2,0,0)
  41. checkAgdaPrimitive pkg info flags | regGenPkgConf flags /= NoFlag = return () -- Gets run twice, only do this the second time
  42. #endif
  43. #endif
  44. checkAgdaPrimitive pkg info flags = do
  45. let dirs = absoluteInstallDirs pkg info NoCopyDest
  46. agda = buildDir info </> "agda" </> "agda" <.> agdaExeExtension
  47. auxDir = datadir dirs </> "lib" </> "prim" </> "Agda"
  48. prim = auxDir </> "Primitive" <.> "agda"
  49. checkPrim file = do
  50. ok <- rawSystem agda [file, "-v0"]
  51. case ok of
  52. ExitSuccess -> return ()
  53. ExitFailure _ -> putStrLn $ "WARNING: Failed to typecheck " ++ file ++ "!"
  54. putStrLn "Generating Agda library interface files..."
  55. checkPrim prim
  56. auxBuiltins <- builtins (auxDir </> "Builtin")
  57. mapM_ checkPrim auxBuiltins
  58. checkAgdaPrimitiveAndRegister :: PackageDescription -> LocalBuildInfo -> UserHooks -> RegisterFlags -> IO ()
  59. checkAgdaPrimitiveAndRegister pkg info hooks flags = do
  60. checkAgdaPrimitive pkg info flags
  61. regHook simpleUserHooks pkg info hooks flags -- This actually does something useful