From 7dfcab2f4bcb7206174ea48857df1883d05e97a2 Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Fri, 22 Sep 2023 14:43:14 -0400
Subject: [PATCH] Get rid of all mention of `mk/config.h`

The RTS configure script is now solely responsible for managing its
headers; the top level configure script does not help.
---
 .gitignore                          |  4 ++--
 compiler/GHC/Builtin/primops.txt.pp |  2 +-
 configure.ac                        | 11 +++++++----
 distrib/cross-port                  |  4 ++--
 docs/coding-style.html              |  2 +-
 hadrian/src/Rules/SourceDist.hs     |  3 ++-
 rts/configure.ac                    |  4 ++--
 7 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/.gitignore b/.gitignore
index 39bf855af36..1ff4a8c3636 100644
--- a/.gitignore
+++ b/.gitignore
@@ -184,8 +184,8 @@ _darcs/
 /linter.log
 /mk/are-validating.mk
 /mk/build.mk
-/mk/config.h
-/mk/config.h.in
+/mk/unused.h
+/mk/unused.h.in
 /mk/config.mk
 /mk/config.mk.old
 /mk/system-cxx-std-lib-1.0.conf
diff --git a/compiler/GHC/Builtin/primops.txt.pp b/compiler/GHC/Builtin/primops.txt.pp
index fd8ebd3d7e7..fd3518ab82b 100644
--- a/compiler/GHC/Builtin/primops.txt.pp
+++ b/compiler/GHC/Builtin/primops.txt.pp
@@ -229,7 +229,7 @@ section "The word size story."
          must contain at least 30 bits. GHC always implements
          'Int' using the primitive type 'Int#', whose size equals
          the @MachDeps.h@ constant @WORD\_SIZE\_IN\_BITS@.
-         This is normally set based on the @config.h@ parameter
+         This is normally set based on the RTS @ghcautoconf.h@ parameter
          @SIZEOF\_HSWORD@, i.e., 32 bits on 32-bit machines, 64
          bits on 64-bit machines.
 
diff --git a/configure.ac b/configure.ac
index b593fbe32e7..31c3c259d76 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,8 +32,8 @@ AC_CONFIG_MACRO_DIRS([m4])
 # checkout), then we ship a file 'VERSION' containing the full version
 # when the source distribution was created.
 
-if test ! -f mk/config.h.in; then
-   echo "mk/config.h.in doesn't exist: perhaps you haven't run 'python3 boot'?"
+if test ! -f rts/ghcautoconf.h.autoconf.in; then
+   echo "rts/ghcautoconf.h.autoconf.in doesn't exist: perhaps you haven't run 'python3 boot'?"
    exit 1
 fi
 
@@ -84,8 +84,11 @@ AC_PREREQ([2.69])
 # Prepare to generate the following header files
 #
 
-# This one is autogenerated by autoheader.
-AC_CONFIG_HEADER(mk/config.h)
+dnl so the next header, which is manually maintained, doesn't get
+dnl overwritten by an autogenerated header. Once we have no more
+dnl `AC_CONFIG_HEADER` calls (issue #23966) we can delete all mention
+dnl of `mk/unused.h`.
+AC_CONFIG_HEADER(mk/unused.h)
 # This one is manually maintained.
 AC_CONFIG_HEADER(compiler/ghc-llvm-version.h)
 
diff --git a/distrib/cross-port b/distrib/cross-port
index 29dd804e825..ad18daa4751 100644
--- a/distrib/cross-port
+++ b/distrib/cross-port
@@ -28,7 +28,7 @@ if [ ! -f b1-stamp ]; then
 
    # For cross-compilation, at this stage you may want to set up a source
    # tree on the target machine, run the configure script there, and bring
-   # the resulting mk/config.h file back into this tree before building
+   # the resulting rts/ghcautoconf.h.autoconf file back into this tree before building
    # the libraries.
 
    touch mk/build.mk
@@ -38,7 +38,7 @@ if [ ! -f b1-stamp ]; then
 
    # We could optimise slightly by not building hslibs here.  Also, building
    # the RTS is not necessary (and might not be desirable if we're using
-   # a config.h from the target system).
+   # a ghcautoconf.h from the target system).
    make stage1
 
   cd ..
diff --git a/docs/coding-style.html b/docs/coding-style.html
index 29112bf60f9..71712804df3 100644
--- a/docs/coding-style.html
+++ b/docs/coding-style.html
@@ -108,7 +108,7 @@ POSIX-compliant to explicitly say so by having <code>#include
 
 <p><li> Some architectures have memory alignment constraints.  Others
 don't have any constraints but go faster if you align things.  These
-macros (from <tt>config.h</tt>) tell you which alignment to use
+macros (from <tt>ghcautoconf.h</tt>) tell you which alignment to use
 
 <pre>
   /* minimum alignment of unsigned int */
diff --git a/hadrian/src/Rules/SourceDist.hs b/hadrian/src/Rules/SourceDist.hs
index cd90032814f..f11a0e7ae31 100644
--- a/hadrian/src/Rules/SourceDist.hs
+++ b/hadrian/src/Rules/SourceDist.hs
@@ -156,7 +156,8 @@ prepareTree dest = do
       , pkgPath terminfo -/- "configure"
       , "configure"
       , "aclocal.m4"
-      , "mk" -/- "config.h.in" ]
+      , "mk" -/- "unused.h.in"
+      ]
 
     copyAlexHappyFiles =
       forM_ alexHappyFiles $ \(stg, pkg, inp, out) -> do
diff --git a/rts/configure.ac b/rts/configure.ac
index 94ae2d30d9a..4a016b15a48 100644
--- a/rts/configure.ac
+++ b/rts/configure.ac
@@ -390,9 +390,9 @@ touch include/ghcautoconf.h
 
 echo "#if !defined(__GHCAUTOCONF_H__)" >> include/ghcautoconf.h
 echo "#define __GHCAUTOCONF_H__" >> include/ghcautoconf.h
-# Copy the contents of $srcdir/../mk/config.h, turning '#define PACKAGE_FOO
+# Copy the contents of ghcautoconf.h.autoconf, turning '#define PACKAGE_FOO
 # "blah"' into '/* #undef PACKAGE_FOO */' to avoid clashes.
-cat $srcdir/../mk/config.h ghcautoconf.h.autoconf | sed \
+cat ghcautoconf.h.autoconf | sed \
    -e 's,^\([	 ]*\)#[	 ]*define[	 ][	 ]*\(PACKAGE_[A-Z]*\)[	 ][ 	]*".*".*$,\1/* #undef \2 */,' \
    -e '/__GLASGOW_HASKELL/d' \
    -e '/REMOVE ME/d' \
-- 
GitLab