Subject: configure doesn't update Makefile

From: Pip Cet <[email-masked]>
Date: Sat, 18 Jan 2025 19:35:54 +0000

This is a minor issue; I have a workaround, and it's only an issue if a
directory that's used in an Emacs build disappears.

I'm running into a strange bug sometimes when switching between the
scratch/elisp-benchmarks and master trees.

The symptom is that "make" sometimes fails after switching from
elisp-benchmarks (where benchmarks/Makefile.in exists and is mentioned
in Makefile) to master (where it doesn't):

make: *** No rule to make target 'benchmarks/Makefile.in', needed by 'Makefile'.  Stop.

The error message makes sense: the Makefile refers to
benchmarks/Makefile.in, which doesn't exist after the branch switch, so
I need to regenerate the Makefile.

These commands fail to fix things:

make Makefile
make bootstrap
./configure && make
sh ./autogen.sh && make

But this one fixes things:

sh ./autogen.sh && ./configure && make

It took me a while to figure out that last one, because it looks almost
exactly like a plain "sh ./autogen.sh && make": in both cases,
autogen.sh is run, then configure, but in the second case, configure
only creates ./config.status, which isn't run.

I'm confused by this recipe in Makefile.in:

config.status: ${srcdir}/configure
	if [ -x ./config.status ]; then		\
	    $(CFG) ./config.status --recheck;	\
	else					\
	    $(CFG) $(srcdir)/configure $(CONFIGURE_FLAGS); \
	fi

If config.status exists, it is rerun, and regenerates the Makefile; but
if it doesn't, configure is run but config.status isn't.  That's okay if
the point is to generate config.status, but from the rule above:

MAKEFILE_NAME = Makefile
$(MAKEFILE_NAME): config.status $(srcdir)/configure \
	 $(srcdir)/lib/gnulib.mk.in \
         $(srcdir)/Makefile.in $(SUBDIR_MAKEFILES_IN) $(CONFIG_STATUS_FILES_IN)
	MAKE='$(MAKE)' ./config.status

the point might be to regenerate and run it.  Changing this:

diff --git a/Makefile.in b/Makefile.in
index 342bec11d81..238d3c5a83b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -575,6 +575,7 @@ $(MAKEFILE_NAME):
 	 $(srcdir)/lib/gnulib.mk.in \
          $(srcdir)/Makefile.in $(SUBDIR_MAKEFILES_IN) $(CONFIG_STATUS_FILES_IN)
 	MAKE='$(MAKE)' ./config.status
+	$(CFG) ./config.status
 
 # Don't erase these files if make is interrupted while refreshing them.
 .PRECIOUS: Makefile config.status
@@ -588,6 +589,7 @@ config.status:
 	else					\
 	    $(CFG) $(srcdir)/configure $(CONFIGURE_FLAGS); \
 	fi
+	$(CFG) ./config.status
 
 $(srcdir)/configure: $(srcdir)/configure.ac $(srcdir)/m4/*.m4
 	cd $(srcdir) && ./autogen.sh autoconf

fixes things, but it's redundant and I'm not sure why either change on
its own isn't sufficient.