From cb0e97d3d40a6b186bdf8639fceb27dc66927bb5 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 23 Mar 2022 21:31:06 -0400 Subject: [PATCH] fix-gnulib: Ensure header rules create output directory. Normally there is no problem, but when performing a VPATH builds with --disable-dependency-tracking the "lib" directory does not get created by configure and some of the rules that create header files will fail. It seems recent versions of Gnulib have a potential solution for this particular problem but is easy enough to patch it up here too. --- scripts/fix-gnulib.pl | 17 +++++++++++++- tests/data/gnulib.mk | 52 +++++++++++++++++++++++++++++++++++++++++++ tests/scripts.at | 42 ++++++++++++++++++++++++++++++++-- 3 files changed, 108 insertions(+), 3 deletions(-) diff --git a/scripts/fix-gnulib.pl b/scripts/fix-gnulib.pl index 69a7d86..ce27521 100755 --- a/scripts/fix-gnulib.pl +++ b/scripts/fix-gnulib.pl @@ -63,6 +63,7 @@ open STDOUT, ">", $output or die "$output: $!\n" if (defined $output); open STDIN, "<", $input or die "$input: $!\n" if (defined $input); my $printed_header = 0; +my $check_mkdir; my @cleanfiles; # Hashes to record make variables used in the automake source. The allvars @@ -231,9 +232,23 @@ EOF # ordinary variable so we can deal with them later. s/BUILT_SOURCES/gnulib_core_headers/; + # Rules for "toplevel" header files do not include commands to create + # the target directory; let's add that. + if (defined $check_mkdir) { + if (/gl_V_at/ || /AM_V_GEN/ and not /MKDIR_P/) { + my $dir = "lib/$check_mkdir"; + $dir =~ s|/[^/]*||; + + print "\t\$(AM_V_GEN)\$(MKDIR_P) $dir\n"; + s/AM_V_GEN|gl_V_at/AM_V_at/; + } + undef $check_mkdir + } + # Targets are similar to variables: the target and its dependencies # need to be mangled. - if (/^[^\t].*:/) { + if (/^([^\t:]*):/) { + $check_mkdir = $1; $_ = mangle_target($_); } diff --git a/tests/data/gnulib.mk b/tests/data/gnulib.mk index e44e645..992f6df 100644 --- a/tests/data/gnulib.mk +++ b/tests/data/gnulib.mk @@ -60,3 +60,55 @@ MOSTLYCLEANFILES += sys/types.h sys/types.h-t EXTRA_DIST += sys_types.in.h ## end gnulib module sys_types + +## begin gnulib module alloca-opt (2021-03-07) + +BUILT_SOURCES += $(ALLOCA_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +if GL_GENERATE_ALLOCA_H +alloca.h: alloca.in.h $(top_builddir)/config.status + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''HAVE_ALLOCA_H''@|$(HAVE_ALLOCA_H)|g' < $(srcdir)/alloca.in.h; \ + } > $@-t && \ + mv -f $@-t $@ +else +alloca.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += alloca.h alloca.h-t + +EXTRA_DIST += alloca.in.h + +## end gnulib module alloca-opt + +## begin gnulib module stddef (2022-02-23) + +BUILT_SOURCES += $(STDDEF_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +if GL_GENERATE_STDDEF_H +stddef.h: stddef.in.h $(top_builddir)/config.status + $(gl_V_at)$(SED_HEADER_STDOUT) \ + -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_STDDEF_H''@|$(NEXT_STDDEF_H)|g' \ + -e 's|@''HAVE_MAX_ALIGN_T''@|$(HAVE_MAX_ALIGN_T)|g' \ + -e 's|@''HAVE_WCHAR_T''@|$(HAVE_WCHAR_T)|g' \ + -e 's|@''REPLACE_NULL''@|$(REPLACE_NULL)|g' \ + $(srcdir)/stddef.in.h > $@-t + $(AM_V_at)mv $@-t $@ +else +stddef.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += stddef.h stddef.h-t + +EXTRA_DIST += stddef.in.h + +## end gnulib module stddef diff --git a/tests/scripts.at b/tests/scripts.at index 9c5f56a..4a83807 100644 --- a/tests/scripts.at +++ b/tests/scripts.at @@ -589,9 +589,13 @@ test_fix_gnulib () { $PERL -f "$srcdir/scripts/fix-gnulib.pl" "$@" } test_gnulib_mk () { - echo; sed -n -f - "$srcdir/tests/data/gnulib.mk" <test.mk.in +AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit +sed -n -f extract.sed test.mk], [0], +[[lib/alloca.h: + $(AM_V_GEN)$(MKDIR_P) lib + $(AM_V_at) +lib/sys/types.h: + $(AM_V_GEN)$(MKDIR_P) lib/sys + $(AM_V_at) +lib/stddef.h: + $(AM_V_GEN)$(MKDIR_P) lib + $(AM_V_at) +]]) + +AT_CLEANUP + dnl TEST_FIND_AUTOMAKE_VER([to-check], [test-action]) dnl dnl For each whitespace-separated version token in to-check, check if we can -- 2.43.2