1#!/usr/bin/perl -w 2 3use strict; 4 5sub update_man_page($); 6sub update_bin_tool($); 7sub update_txt_file($); 8sub update_spec_file($); 9sub get_file_info($); 10 11our $directory = $ARGV[0]; 12our $version = $ARGV[1]; 13our $release = $ARGV[2]; 14 15our @man_pages = ("man/gendesc.1", "man/genhtml.1", "man/geninfo.1", 16 "man/genpng.1", "man/lcov.1", "man/lcovrc.5"); 17our @bin_tools = ("bin/gendesc", "bin/genhtml", "bin/geninfo", 18 "bin/genpng", "bin/lcov"); 19our @txt_files = ("README"); 20our @spec_files = ("rpm/lcov.spec"); 21 22if (!defined($directory) || !defined($version) || !defined($release)) { 23 die("Usage: $0 <directory> <version string> <release string>\n"); 24} 25 26foreach (@man_pages) { 27 print("Updating man page $_\n"); 28 update_man_page($directory."/".$_); 29} 30foreach (@bin_tools) { 31 print("Updating bin tool $_\n"); 32 update_bin_tool($directory."/".$_); 33} 34foreach (@txt_files) { 35 print("Updating text file $_\n"); 36 update_txt_file($directory."/".$_); 37} 38foreach (@spec_files) { 39 print("Updating spec file $_\n"); 40 update_spec_file($directory."/".$_); 41} 42print("Done.\n"); 43 44sub get_file_info($) 45{ 46 my ($filename) = @_; 47 my ($sec, $min, $hour, $year, $month, $day); 48 my @stat; 49 50 @stat = stat($filename); 51 ($sec, $min, $hour, $day, $month, $year) = localtime($stat[9]); 52 $year += 1900; 53 $month += 1; 54 55 return (sprintf("%04d-%02d-%02d", $year, $month, $day), 56 sprintf("%04d%02d%02d%02d%02d.%02d", $year, $month, $day, 57 $hour, $min, $sec), 58 sprintf("%o", $stat[2] & 07777)); 59} 60 61sub update_man_page($) 62{ 63 my ($filename) = @_; 64 my @date = get_file_info($filename); 65 my $date_string = $date[0]; 66 local *IN; 67 local *OUT; 68 69 $date_string =~ s/-/\\-/g; 70 open(IN, "<$filename") || die ("Error: cannot open $filename\n"); 71 open(OUT, ">$filename.new") || 72 die("Error: cannot create $filename.new\n"); 73 while (<IN>) { 74 s/\"LCOV\s+\d+\.\d+\"/\"LCOV $version\"/g; 75 s/\d\d\d\d\\\-\d\d\\\-\d\d/$date_string/g; 76 print(OUT $_); 77 } 78 close(OUT); 79 close(IN); 80 chmod(oct($date[2]), "$filename.new"); 81 system("mv", "-f", "$filename.new", "$filename"); 82 system("touch", "$filename", "-t", $date[1]); 83} 84 85sub update_bin_tool($) 86{ 87 my ($filename) = @_; 88 my @date = get_file_info($filename); 89 local *IN; 90 local *OUT; 91 92 open(IN, "<$filename") || die ("Error: cannot open $filename\n"); 93 open(OUT, ">$filename.new") || 94 die("Error: cannot create $filename.new\n"); 95 while (<IN>) { 96 s/(our\s+\$lcov_version\s*=\s*["']).*(["'].*)$/$1LCOV version $version$2/g; 97 print(OUT $_); 98 } 99 close(OUT); 100 close(IN); 101 chmod(oct($date[2]), "$filename.new"); 102 system("mv", "-f", "$filename.new", "$filename"); 103 system("touch", "$filename", "-t", $date[1]); 104} 105 106sub update_txt_file($) 107{ 108 my ($filename) = @_; 109 my @date = get_file_info($filename); 110 local *IN; 111 local *OUT; 112 113 open(IN, "<$filename") || die ("Error: cannot open $filename\n"); 114 open(OUT, ">$filename.new") || 115 die("Error: cannot create $filename.new\n"); 116 while (<IN>) { 117 s/(Last\s+changes:\s+)\d\d\d\d-\d\d-\d\d/$1$date[0]/g; 118 print(OUT $_); 119 } 120 close(OUT); 121 close(IN); 122 chmod(oct($date[2]), "$filename.new"); 123 system("mv", "-f", "$filename.new", "$filename"); 124 system("touch", "$filename", "-t", $date[1]); 125} 126 127sub update_spec_file($) 128{ 129 my ($filename) = @_; 130 my @date = get_file_info($filename); 131 local *IN; 132 local *OUT; 133 134 open(IN, "<$filename") || die ("Error: cannot open $filename\n"); 135 open(OUT, ">$filename.new") || 136 die("Error: cannot create $filename.new\n"); 137 while (<IN>) { 138 s/^(Version:\s*)\d+\.\d+.*$/$1$version/; 139 s/^(Release:\s*).*$/$1$release/; 140 print(OUT $_); 141 } 142 close(OUT); 143 close(IN); 144 system("mv", "-f", "$filename.new", "$filename"); 145 system("touch", "$filename", "-t", $date[1]); 146} 147