Subject: Re: bug#78960: VPATH build fails
From: Pádraig Brady <[email-masked]>
To: Bruno Haible <[email-masked]>, [email-masked]
Date: Sat, 5 Jul 2025 13:08:31 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

On 05/07/2025 10:59, Bruno Haible via GNU coreutils Bug Reports wrote:
> Hi,
> 
> The coreutils CI build part that does a "make distcheck" today fails,
> whereas on 2025-06-30 it succeeded [1].
> 
> The problem can be reproduced as follows:
> 
> 1)
> $ ./bootstrap --no-git --gnulib-srcdir=$GNULIB_SRCDIR
> $ ./configure
> $ make
> $ make dist
> 
> 2)
> Unpack the tarball, cd into its directory.
> 
> 3)
> $ mkdir bb
> $ cd bb
> $ ../configure
> $ make V=1
> ...
> depbase=`echo src/pinky.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
> gcc  -I. -I.. -I./lib  -Ilib -I../lib -Isrc -I../src    -g -O2 -MT src/pinky.o -MD -MP -MF $depbase.Tpo -c -o src/pinky.o ../src/pinky.c &&\
> mv -f $depbase.Tpo $depbase.Po
> gcc   -g -O2 -Wl,--as-needed  -o src/pinky src/pinky.o src/libver.a lib/libcoreutils.a   lib/libcoreutils.a
> rm -f src/speedlist.h
> /arch/local/x86_64-linux/bin/mkdir -p src
> ( for opt in -dM -xdumpmacros -qshowmacros -PD; do \
>                  gcc  -I. -I.. -I./lib  -Ilib -I../lib -Isrc -I../src    -g -O2 -E $opt ../src/termios.c 2>&1 && break; \
>              done ) | /bin/bash ../src/speedgen src/speedlist.ht
> chmod a-w src/speedlist.ht
> mv src/speedlist.ht src/speedlist.h
> depbase=`echo src/stty.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
> gcc  -I. -I.. -I./lib  -Ilib -I../lib -Isrc -I../src    -g -O2 -MT src/stty.o -MD -MP -MF $depbase.Tpo -c -o src/stty.o src/stty.c &&\
> mv -f $depbase.Tpo $depbase.Po
> cc1: fatal error: src/stty.c: No such file or directory
> compilation terminated.
> make[2]: *** [Makefile:13092: src/stty.o] Error 1
> make[2]: Leaving directory '/COREUTILS/coreutils/coreutils-20250411/bb'
> make[1]: *** [Makefile:23441: all-recursive] Error 1
> make[1]: Leaving directory '/COREUTILS/coreutils/coreutils-20250411/bb'
> make: *** [Makefile:9356: all] Error 2
> 
> Comparing the compilation commands for pinky.c and stty.c, you can see
> that ../src/pinky.c and src/stty.c are referenced. But in a VPATH build,
> src/stty.c does not exist.
> 
> This is caused by commit 017fc50bb6797ac2d71e46fef8f559acb0f44c5d.
> If I locally revert this commit, "make V=1" succeeds.
> 
> Bruno
> 
> [1] https://github.com/coreutils/ci-check/actions

I did test a VPATH build from `make dist`,
but only a parallel build with `make -j4`, which does pass.

I pushed the following which passes both types of builds here.
Marking this as done.

cheers,
Padraig

diff --git a/src/local.mk b/src/local.mk
index 537032578..fb763c4db 100644
--- a/src/local.mk
+++ b/src/local.mk
@@ -708,7 +708,7 @@ src/version.h: Makefile
  # -PD: MSVC (usable with a wrapper such as cccl from the SWIG project)
  getmacopts = -dM -xdumpmacros -qshowmacros -PD

-CLEANFILES += src/speedlist.h
+BUILT_SOURCES += src/speedlist.h
  src/speedlist.h: src/termios.c lib/config.h src/speedgen
         $(AM_V_GEN)rm -f $@
         $(AM_V_at)${MKDIR_P} src
@@ -718,8 +718,6 @@ src/speedlist.h: src/termios.c lib/config.h src/speedgen
         $(AM_V_at)chmod a-w $@t
         $(AM_V_at)mv $@t $@

-src/stty.c: src/speedlist.h
-
  # Generates a list of macro invocations like:
  #   SINGLE_BINARY_PROGRAM(program_name_str, main_name)
  # once for each program list on $(single_binary_progs). Note that