[commit: packages/Cabal] ghc-head: Split the cabal_macros.h generation into a helper and wrapper (afc73a1)

git at git.haskell.org git at git.haskell.org
Mon Aug 26 23:29:03 CEST 2013


Repository : ssh://git@git.haskell.org/Cabal

On branch  : ghc-head
Link       : http://git.haskell.org/?p=packages/Cabal.git;a=commit;h=afc73a1e193b9527204f5cc5148a528f6ddef21e

>---------------------------------------------------------------

commit afc73a1e193b9527204f5cc5148a528f6ddef21e
Author: Duncan Coutts <duncan at community.haskell.org>
Date:   Wed Jul 24 15:54:42 2013 +0100

    Split the cabal_macros.h generation into a helper and wrapper
    
    Makes it easier to reuse this code in other contexts, for example if we
    want to build without a .cabal file using all the packages in the
    environment.


>---------------------------------------------------------------

afc73a1e193b9527204f5cc5148a528f6ddef21e
 Cabal/Distribution/Simple/Build/Macros.hs |   20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/Cabal/Distribution/Simple/Build/Macros.hs b/Cabal/Distribution/Simple/Build/Macros.hs
index 58e2ed4..be85622 100644
--- a/Cabal/Distribution/Simple/Build/Macros.hs
+++ b/Cabal/Distribution/Simple/Build/Macros.hs
@@ -18,7 +18,8 @@
 -- numbers.
 --
 module Distribution.Simple.Build.Macros (
-    generate
+    generate,
+    generatePackageVersionMacros,
   ) where
 
 import Distribution.Package
@@ -36,9 +37,20 @@ import Distribution.Text
 -- * Generate cabal_macros.h
 -- ------------------------------------------------------------
 
+-- | The contents of the @cabal_macros.h@ for the given configured package.
+--
 generate :: PackageDescription -> LocalBuildInfo -> String
-generate _pkg_descr lbi = concat $
-  "/* DO NOT EDIT: This file is automatically generated by Cabal */\n\n" :
+generate _pkg_descr lbi =
+  "/* DO NOT EDIT: This file is automatically generated by Cabal */\n\n" ++
+  generatePackageVersionMacros (map snd (externalPackageDeps lbi))
+
+
+-- | Helper function that generates just the @VERSION_pkg@ and @MIN_VERSION_pkg@
+-- macros for a list of package ids (usually used with the specific deps of
+-- a configured package).
+--
+generatePackageVersionMacros :: [PackageIdentifier] -> String
+generatePackageVersionMacros pkgids = concat
   [ concat
     ["/* package ",display pkgid," */\n"
     ,"#define VERSION_",pkgname," ",show (display version),"\n"
@@ -48,7 +60,7 @@ generate _pkg_descr lbi = concat $
     ,"  (major1) == ",major1," && (major2) == ",major2," && (minor) <= ",minor,")"
     ,"\n\n"
     ]
-  | (_, pkgid@(PackageIdentifier name version)) <- externalPackageDeps lbi
+  | pkgid@(PackageIdentifier name version) <- pkgids
   , let (major1:major2:minor:_) = map show (versionBranch version ++ repeat 0)
         pkgname = map fixchar (display name)
   ]





More information about the ghc-commits mailing list