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
# 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;
@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 (<STDIN>) {
# 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
# 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 <<EOF foreach (keys %gl_dirstamps);
+EXTRA_PROGRAMS += $_/gl-dirstamp
+${\(y|/|_|r)}_gl_dirstamp_SOURCES =
+EOF
+
print <<'EOF' if ($use_libtool);
gnulib_lt_objects = $(libgnu_la_OBJECTS) $(gl_LTLIBOBJS)
gnulib_objects = $(gnulib_lt_objects)