diff --git a/Cabal/Distribution/Simple/Build/Macros/Z.hs b/Cabal/Distribution/Simple/Build/Macros/Z.hs
index 641d395d15e5a9f5f95b3d2cb370fe4d132108d1..4c14843e041d13c6958d1c1699a852db8113c796 100644
--- a/Cabal/Distribution/Simple/Build/Macros/Z.hs
+++ b/Cabal/Distribution/Simple/Build/Macros/Z.hs
@@ -72,7 +72,7 @@ render z_root = execWriter $ do
     tell " */\n"
   tell "\n"
   forM_ (zTools z_root) $ \z_var1_tool -> do
-    tell "/* package "
+    tell "/* tool "
     tell (ztoolName z_var1_tool)
     tell "-"
     tell (prettyShow (ztoolVersion z_var1_tool))
@@ -85,7 +85,7 @@ render z_root = execWriter $ do
     tell " \""
     tell (prettyShow (ztoolVersion z_var1_tool))
     tell "\"\n"
-    tell "#endif /* VERSION_"
+    tell "#endif /* TOOL_VERSION_"
     tell (zMangleStr z_root (ztoolName z_var1_tool))
     tell " */\n"
     tell "#ifndef MIN_TOOL_VERSION_"
@@ -109,14 +109,14 @@ render z_root = execWriter $ do
     tell " && (minor) <= "
     tell (ztoolZ z_var1_tool)
     tell ")\n"
-    tell "#endif /* MIN_VERSION_"
+    tell "#endif /* MIN_TOOL_VERSION_"
     tell (zMangleStr z_root (ztoolName z_var1_tool))
     tell " */\n"
   tell "\n"
   if (zNotNull z_root (zPackageKey z_root))
   then do
-    tell "#ifndef CURRENT_packageKey\n"
-    tell "#define CURRENT_packageKey \""
+    tell "#ifndef CURRENT_PACKAGE_KEY\n"
+    tell "#define CURRENT_PACKAGE_KEY \""
     tell (zPackageKey z_root)
     tell "\"\n"
     tell "#endif /* CURRENT_packageKey */\n"
diff --git a/boot/cabal_macros.template.h b/boot/cabal_macros.template.h
index 4cd5956bc2f4117e83a789577f2c2751b7758427..f50323d9668b7945f684181391b5cf378c0fc6ea 100644
--- a/boot/cabal_macros.template.h
+++ b/boot/cabal_macros.template.h
@@ -14,21 +14,21 @@
 {% endfor %}
 
 {% for tool in tools %}
-/* package {{ tool.name }}-{{ tool.version }} */
+/* tool {{ tool.name }}-{{ tool.version }} */
 #ifndef TOOL_VERSION_{{ mangleStr tool.name }}
 #define TOOL_VERSION_{{ mangleStr tool.name }} "{{ tool.version }}"
-#endif /* VERSION_{{ mangleStr tool.name }} */
+#endif /* TOOL_VERSION_{{ mangleStr tool.name }} */
 #ifndef MIN_TOOL_VERSION_{{ mangleStr tool.name }}
 #define MIN_TOOL_VERSION_{{ mangleStr tool.name }}(major1,major2,minor) (\
   (major1) <  {{ tool.x }} || \
   (major1) == {{ tool.x }} && (major2) <  {{ tool.y }} || \
   (major1) == {{ tool.x }} && (major2) == {{ tool.y }} && (minor) <= {{ tool.z }})
-#endif /* MIN_VERSION_{{ mangleStr tool.name }} */
+#endif /* MIN_TOOL_VERSION_{{ mangleStr tool.name }} */
 {% endfor %}
 
 {% if notNull packageKey %}
-#ifndef CURRENT_packageKey
-#define CURRENT_packageKey "{{ packageKey }}"
+#ifndef CURRENT_PACKAGE_KEY
+#define CURRENT_PACKAGE_KEY "{{ packageKey }}"
 #endif /* CURRENT_packageKey */
 {% endif %}
 {% if notNull componentId %}
diff --git a/cabal-testsuite/PackageTests/CabalMacros/Mdl.hs b/cabal-testsuite/PackageTests/CabalMacros/Mdl.hs
new file mode 100644
index 0000000000000000000000000000000000000000..abd5d06f1409b8426e2ed128df1ae57a24bfb88b
--- /dev/null
+++ b/cabal-testsuite/PackageTests/CabalMacros/Mdl.hs
@@ -0,0 +1,5 @@
+{-# LANGUAGE CPP #-}
+module Mdl where
+
+answer :: Int
+answer = 42
diff --git a/cabal-testsuite/PackageTests/CabalMacros/my.cabal b/cabal-testsuite/PackageTests/CabalMacros/my.cabal
new file mode 100644
index 0000000000000000000000000000000000000000..169b54740158b7bd2c5ad47eb9f19b44b4c9783a
--- /dev/null
+++ b/cabal-testsuite/PackageTests/CabalMacros/my.cabal
@@ -0,0 +1,16 @@
+cabal-version: 2.1
+name: CabalMacros
+version: 0.1
+license: BSD-3-Clause
+author: Oleg Grenrus
+stability: stable
+category: PackageTests
+build-type: Simple
+
+description:
+    Check that the generated cabal_macros.h is intact.
+
+Library
+    exposed-modules: Mdl
+    build-depends: base
+    default-language: Haskell2010
diff --git a/cabal-testsuite/PackageTests/CabalMacros/setup.cabal.out b/cabal-testsuite/PackageTests/CabalMacros/setup.cabal.out
new file mode 100644
index 0000000000000000000000000000000000000000..964a3422101d7fd3862f637099f14365fe953e54
--- /dev/null
+++ b/cabal-testsuite/PackageTests/CabalMacros/setup.cabal.out
@@ -0,0 +1,16 @@
+# Setup configure
+Resolving dependencies...
+Configuring CabalMacros-0.1...
+# Setup build
+Preprocessing library for CabalMacros-0.1..
+Building library for CabalMacros-0.1..
+# cabal_macros.h
+#ifndef CURRENT_PACKAGE_KEY
+#define CURRENT_PACKAGE_KEY "CabalMacros-0.1"
+#endif /* CURRENT_packageKey */
+#ifndef CURRENT_COMPONENT_ID
+#define CURRENT_COMPONENT_ID "CabalMacros-0.1"
+#endif /* CURRENT_COMPONENT_ID */
+#ifndef CURRENT_PACKAGE_VERSION
+#define CURRENT_PACKAGE_VERSION "0.1"
+#endif /* CURRENT_PACKAGE_VERSION */
diff --git a/cabal-testsuite/PackageTests/CabalMacros/setup.out b/cabal-testsuite/PackageTests/CabalMacros/setup.out
new file mode 100644
index 0000000000000000000000000000000000000000..dbfc1043f1a37c6d282d38561a108cb5a555ea7a
--- /dev/null
+++ b/cabal-testsuite/PackageTests/CabalMacros/setup.out
@@ -0,0 +1,15 @@
+# Setup configure
+Configuring CabalMacros-0.1...
+# Setup build
+Preprocessing library for CabalMacros-0.1..
+Building library for CabalMacros-0.1..
+# cabal_macros.h
+#ifndef CURRENT_PACKAGE_KEY
+#define CURRENT_PACKAGE_KEY "CabalMacros-0.1"
+#endif /* CURRENT_packageKey */
+#ifndef CURRENT_COMPONENT_ID
+#define CURRENT_COMPONENT_ID "CabalMacros-0.1"
+#endif /* CURRENT_COMPONENT_ID */
+#ifndef CURRENT_PACKAGE_VERSION
+#define CURRENT_PACKAGE_VERSION "0.1"
+#endif /* CURRENT_PACKAGE_VERSION */
diff --git a/cabal-testsuite/PackageTests/CabalMacros/setup.test.hs b/cabal-testsuite/PackageTests/CabalMacros/setup.test.hs
new file mode 100644
index 0000000000000000000000000000000000000000..16fdbe51277695e7e9c1158ab7d37f8706be599d
--- /dev/null
+++ b/cabal-testsuite/PackageTests/CabalMacros/setup.test.hs
@@ -0,0 +1,18 @@
+import Test.Cabal.Prelude
+import qualified Data.ByteString.Char8 as BS8
+
+main = setupAndCabalTest $ do
+    env <- getTestEnv
+    let mode = testRecordMode env
+
+    setup_build []
+    let autogenDir = testDistDir env </> "build" </> "autogen"
+
+    defaultRecordMode RecordAll $ recordHeader ["cabal_macros.h"]
+    contents <- liftIO $ BS8.readFile $ autogenDir </> "cabal_macros.h"
+    -- we are only interested in CURRENT_ lines
+    -- others change a lot based on available tools in the environment
+    let contents' = BS8.unlines
+                  $ filter (BS8.isInfixOf $ BS8.pack "CURRENT")
+                  $ BS8.lines contents
+    liftIO $ BS8.appendFile (testActualFile env) contents'