1 |
760 |
ahitrov |
#!/usr/bin/env perl |
2 |
497 |
ahitrov |
|
3 |
|
|
use strict; |
4 |
|
|
|
5 |
|
|
my $start_dir = $ARGV[0] || die "Root dir needed\n"; |
6 |
|
|
$start_dir =~ s/\/$//; |
7 |
|
|
die "Wrong path\n" unless -e $start_dir; |
8 |
|
|
|
9 |
|
|
print "Start patching Makefiles from [$start_dir]...\n"; |
10 |
|
|
|
11 |
|
|
my @dirs = ( $start_dir ); |
12 |
|
|
my @FILES; |
13 |
|
|
|
14 |
|
|
while ( @dirs ) { |
15 |
|
|
my $dir = shift @dirs; |
16 |
|
|
opendir(DIR, $dir); |
17 |
|
|
my @files = grep { /[^\.]+/ && ( -d $dir.'/'.$_ || $_ eq 'Makefile' ) } readdir(DIR); |
18 |
|
|
closedir DIR; |
19 |
|
|
|
20 |
|
|
foreach my $file ( @files ) { |
21 |
|
|
if ( $file eq 'Makefile' ) { |
22 |
|
|
push @FILES, $dir.'/'.$file; |
23 |
|
|
} else { |
24 |
|
|
push @dirs, $dir.'/'.$file; |
25 |
|
|
} |
26 |
|
|
} |
27 |
|
|
} |
28 |
|
|
|
29 |
|
|
foreach my $file ( @FILES ) { |
30 |
|
|
print $file."\n"; |
31 |
|
|
my $dir = $file; |
32 |
|
|
$dir =~ s/\/\w+$//; |
33 |
|
|
open FILE, $file; |
34 |
|
|
my $buffer = ''; |
35 |
|
|
while ( <FILE> ) { |
36 |
|
|
my $str = $_; |
37 |
|
|
if ( $str =~ /^OPTIMIZE\s*=\s+(.*?)\n/ ) { |
38 |
|
|
$str = "OPTIMIZE = $1 -fgnu89-inline\n"; |
39 |
|
|
} |
40 |
|
|
$buffer .= $str; |
41 |
|
|
} |
42 |
|
|
close FILE; |
43 |
|
|
my $out = $dir.'/Makefile.patch'; |
44 |
|
|
open OUT, "> $out"; |
45 |
|
|
print OUT $buffer; |
46 |
|
|
close OUT; |
47 |
|
|
rename $file, $file.'.orig'; |
48 |
|
|
rename $out, $file; |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
print "Files patched\n"; |