X-Git-Url: https://git.draconx.ca/gitweb/dxcommon.git/blobdiff_plain/22a05c201cd829bead27a94b779fe76190103da1..8c45dd9fec485578a09dbf541d4209dcf77acd5f:/scripts/fix-gnulib.pl diff --git a/scripts/fix-gnulib.pl b/scripts/fix-gnulib.pl index 640f1cd..9a1f273 100755 --- a/scripts/fix-gnulib.pl +++ b/scripts/fix-gnulib.pl @@ -63,7 +63,6 @@ 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 @@ -72,6 +71,13 @@ my @cleanfiles; # the value is always set to 1. my (%allvars, %sourcevars); +# Collected names of subdirectories that may need to be created at build time. +# The keys are directory names, the values are targets. +my %gl_dirstamps; + +# State to drop MKDIR_P lines that have been replaced by dirstamps. +my ($have_dirstamp) = (0); + sub drop { undef $_; next; @@ -123,7 +129,21 @@ sub mangle_target { @left = map(mangle_file($_), @left); @right = map(mangle_file($_), @right); - return join(" ", @left) . ": " . join(" ", @right) . "\n"; + my @dirstamps = get_dirstamps(@left); + + return join(" ", @left) . ": " . join(" ", @dirstamps, @right) . "\n"; +} + +sub get_dirstamps { + my %h; + + foreach (@_) { + next unless $_[0] =~ m|^(lib(/.*)?)/[^/]*$|; + + $h{$gl_dirstamps{$1} = "$1/\$(am__dirstamp)"} = 1; + } + + return keys %h; } while () { @@ -232,24 +252,11 @@ 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:]*):/) { - $check_mkdir = $1; $_ = mangle_target($_); + $have_dirstamp = /am__dirstamp/; } # MKDIR_P commands need to be fixed up; in principle Gnulib could also @@ -271,12 +278,28 @@ EOF # component. s/t-\$@/\$\@-t/g; - # Finally, $(srcdir), $(builddir) and %reldir% need to be fixed up. + # $(srcdir), $(builddir) and %reldir% need to be fixed up. s:\$\(srcdir\):\$\(top_srcdir\)/lib:g; s:\$\(builddir\):\$\(top_builddir\)/lib:g; s:%reldir%:lib:g; + + # If we installed a dirstamp prerequisite for this target, don't + # emit the mkdir line which creates the output directory. + if ($have_dirstamp && m|\$[({]MKDIR_P[})][ '"]*lib/|) { + drop unless s/^(\t\$[({](AM_V_GEN|gl_V_at)[})]).*/\1:/; + } + undef $have_dirstamp if /^\t/; } continue { s/(\n.)/\\\1/g; print; }; +# Define a bunch of fake programs which will ensure Automake produces the +# necessary dirstamp rules, as unfortunately we cannot know in advance which +# will be generated, and the usual Automake behaviour where generated rules +# are suppressed by rules in Makefile.am doesn't actaully work for these. +print <