Commit befa80b1 authored by Luite Stegeman's avatar Luite Stegeman
Browse files

generate CURRENT_PACKAGE_KEY macro in `cabal_macros.h`

parent 4aabb4f4
......@@ -30,8 +30,10 @@ import Distribution.Version
( Version(versionBranch) )
import Distribution.PackageDescription
( PackageDescription )
import Distribution.Simple.Compiler
( packageKeySupported )
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo(withPrograms), externalPackageDeps )
( LocalBuildInfo(compiler, pkgKey, withPrograms), externalPackageDeps )
import Distribution.Simple.Program.Db
( configuredPrograms )
import Distribution.Simple.Program.Types
......@@ -49,7 +51,8 @@ generate :: PackageDescription -> LocalBuildInfo -> String
generate _pkg_descr lbi =
"/* DO NOT EDIT: This file is automatically generated by Cabal */\n\n" ++
generatePackageVersionMacros (map snd (externalPackageDeps lbi)) ++
generateToolVersionMacros (configuredPrograms . withPrograms $ lbi)
generateToolVersionMacros (configuredPrograms . withPrograms $ lbi) ++
generatePackageKeyMacro 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
......@@ -93,6 +96,14 @@ generateMacros prefix name version =
where
(major1:major2:minor:_) = map show (versionBranch version ++ repeat 0)
-- | Generate the @CURRENT_PACKAGE_KEY@ definition for the package key
-- of the current package, if supported by the compiler
generatePackageKeyMacro :: LocalBuildInfo -> String
generatePackageKeyMacro lbi
| packageKeySupported (compiler lbi) =
"#define CURRENT_PACKAGE_KEY \"" ++ display (pkgKey lbi) ++ "\"\n\n"
| otherwise = ""
fixchar :: Char -> Char
fixchar '-' = '_'
fixchar c = c
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment