#!/usr/bin/perl # # $Id: commflags,v 1.4 2000/09/17 05:04:26 vogelke Exp $ # # find common compiler flags in make output. $k = 0; while (<>) { chomp; s/\s+/ /g; s/-pipe -c/-c -pipe/g; # keep -c out of middle of line. $orig[$k] = "$_"; $k++; } $max = $k; $n = 0; $prev = ''; # get just the options. while ($n < $max) { $_ = $orig[$n]; @fl = grep (/^-/, split()); $flist = join (' ', @fl); $a{$flist} = 1; $n++; } # keep only option patterns long enough to be worth it. $k = 1; foreach $p (sort keys %a) { next unless length ($p) > 60; $p =~ s/-c //g; $p =~ s/-o //g; $p =~ s/ -c//g; $p =~ s/ -o//g; $pat[$k] = "$p"; $k++; } # set up the flag variables that might be used. $k = 1; while ($pat[$k]) { $disp[$k] = '$flag' . $k . " = $pat[$k]"; $rep[$k] = '$flag' . $k; $used[$k] = 0; # kill backslashes, or they screw up the replacement. $pat[$k] =~ s/\\/./g; $k++; } # go through the original file, look for matches. $n = 0; while ($n < $max) { $_ = $orig[$n]; $k = 1; $match = 0; while ($pat[$k]) { if (/$pat[$k]/) { $match = 1; $used[$k]++; last; } $k++; } $n++; } # print only the flag strings that were used. $k = 1; while ($pat[$k]) { print "$disp[$k]\n" if $used[$k]; $k++; } print "\n"; # now, go through original file for the last time, doing subs. $n = 0; while ($n < $max) { $_ = $orig[$n]; $k = 1; $match = 0; while ($pat[$k]) { if (/$pat[$k]/) { s/$pat[$k]/$rep[$k]/g; print "$_\n"; $match = 1; $used[$k]++; last; } $k++; } print "$_\n" unless $match; $n++; } exit (0);