]> git.draconx.ca Git - dxcommon.git/commitdiff
fix-gnulib: Ensure header rules create output directory.
authorNick Bowler <nbowler@draconx.ca>
Thu, 24 Mar 2022 01:31:06 +0000 (21:31 -0400)
committerNick Bowler <nbowler@draconx.ca>
Thu, 24 Mar 2022 01:31:06 +0000 (21:31 -0400)
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
tests/data/gnulib.mk
tests/scripts.at

index 69a7d864f29e939385a3f712d6fa1515318468e1..ce27521b007b86b3a22bb446c2bf24242836812d 100755 (executable)
@@ -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($_);
        }
 
index e44e6450e258867f646bad5d71803548f0a0b7db..992f6dfdbfe400bd2b48184d75aff28eeb5a8aad 100644 (file)
@@ -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 <alloca.h> 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 <stddef.h> 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
index 9c5f56a950eb4391aa8d3b390117a53c4956bc10..4a838077250eaa6c5a6c8be1e433cbc0acbc3837 100644 (file)
@@ -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" <<EOF
-/^## begin gnulib module $1/,/^## end   gnulib module $1/p
+  echo;
+  for arg
+  do
+    sed -n -f - "$srcdir/tests/data/gnulib.mk" <<EOF
+/^## begin gnulib module $arg/,/^## end   gnulib module $arg/p
 EOF
+  done
 }
 m4_divert_pop([PREPARE_TESTS])
 
@@ -647,6 +651,40 @@ EXTRA_LIBRARIES += libgnu.a
 
 AT_CLEANUP
 
+AT_SETUP([fix-gnulib.pl header directory creation])
+
+AT_DATA([extract.sed],
+[[/AM_V_GEN/b ok
+/gl_V_at/b ok
+s/:.*/:/
+h
+b
+:ok
+s/'//g
+x
+G
+p
+n
+s/[)].*/)/
+p
+]])
+
+test_gnulib_mk alloca-opt sys_types stddef >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