]> git.draconx.ca Git - dxcommon.git/commitdiff
Mangle spliced makefile lines in Gnulib correctly.
authorNick Bowler <nbowler@draconx.ca>
Sat, 22 Oct 2011 17:37:27 +0000 (13:37 -0400)
committerNick Bowler <nbowler@draconx.ca>
Sun, 23 Oct 2011 00:20:58 +0000 (20:20 -0400)
Otherwise, target and variable mangling may only apply to the first
line.

scripts/fix-gnulib.pl

index 834fb7a2e6fe0f0b3f4a11c7eaa11d3fb800422c..ee7a0c94a70a88c6ca6e5f59ae5181da037e1ab9 100755 (executable)
@@ -17,6 +17,8 @@ my $input    = undef;
 my $m4output = undef;
 my $m4macro  = "DX_FIX_GNULIB";
 
+my $line     = 0;
+
 Getopt::Long::Configure("gnu_getopt", "no_auto_abbrev");
 GetOptions(
        "o|output=s"   => \$output,
@@ -56,7 +58,7 @@ sub mangle_file {
                # Fix up things that look like filenames.
                $word = "lib/$word";
        } else {
-               print STDERR "$0: warning: unrecognized source file: $word\n";
+               print STDERR "$0:$line: warning: unrecognized source file: $word\n";
        }
 
        return "$word";
@@ -65,7 +67,7 @@ sub mangle_file {
 sub mangle_variable {
        my $raw = shift;
 
-       $raw =~ /([^=]+=)[[:space:]]*(.*)/;
+       $raw =~ /([^=]+=)[[:space:]]*(.*)/s;
        my ($left, @right) = ($1, split(/[[:space:]]+/, $2));
 
        return join(" ", ($left, map(mangle_file($_), @right))) . "\n";
@@ -74,7 +76,7 @@ sub mangle_variable {
 sub mangle_target {
        my $raw = shift;
 
-       $raw =~ /([^:]+):[[:space:]]*(.*)/;
+       $raw =~ /([^:]+):[[:space:]]*(.*)/s;
        my @left  = split(/[[:space:]]+/, $1);
        my @right = split(/[[:space:]]+/, $2);
 
@@ -85,6 +87,14 @@ sub mangle_target {
 }
 
 while (<STDIN>) {
+       $line++;
+
+       # Combine line splices.
+       while (s/\\$//) {
+               $line++;
+               $_ = $_ . <STDIN>
+       }
+
        next if (/^#/);
 
        if (!$printed_header) {
@@ -147,7 +157,7 @@ EOF
 
        # Targets are similar to variables: the target and its dependencies
        # need to be mangled.
-       if (/:/) {
+       if (/^[^\t].*:/) {
                $_ = mangle_target($_);
        }
 
@@ -164,7 +174,7 @@ EOF
        # Finally, references to $(srcdir) and $(builddir) need to be fixed up.
        s:\$\(srcdir\):\$\(top_srcdir\)/lib:g;
        s:\$\(builddir\):\$\(top_builddir\)/lib:g;
-} continue { print };
+} continue { s/(\n.)/\\\1/g; print; };
 
 print <<'EOF';
 gnulib_lt_objects = $(libgnu_la_OBJECTS) $(gl_LTLIBOBJS)