bug 494645 - new "-r" option to the dis function disassemble recursively. r=mrbkap
[mozilla-central.git] / config / version_win.pl
blob9d57b4397c3da9cd391d7c23464ad8f8b051c352
1 #!/usr/bin/perl -w
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
14 # License.
16 # The Original Code is the Win32 Version System.
18 # The Initial Developer of the Original Code is Brian Bober <netdemonz@yahoo.com>
19 # Portions created by the Initial Developer are Copyright (C) 2001
20 # the Initial Developer. All Rights Reserved.
22 # Contributor(s):
24 # Alternatively, the contents of this file may be used under the terms of
25 # either the GNU General Public License Version 2 or later (the "GPL"), or
26 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 # in which case the provisions of the GPL or the LGPL are applicable instead
28 # of those above. If you wish to allow use of your version of this file only
29 # under the terms of either the GPL or the LGPL, and not to allow others to
30 # use your version of this file under the terms of the MPL, indicate your
31 # decision by deleting the provisions above and replace them with the notice
32 # and other provisions required by the GPL or the LGPL. If you do not delete
33 # the provisions above, a recipient may use your version of this file under
34 # the terms of any one of the MPL, the GPL or the LGPL.
36 # ***** END LICENSE BLOCK *****
38 #use diagnostics;
39 require strict;
40 my $dir = $0;
41 $dir =~ s/[^\/]*$//;
42 push(@INC, "$dir");
43 require "Moz/Milestone.pm";
44 use Getopt::Long;
45 use Getopt::Std;
46 use POSIX;
48 # Calculate the number of days since Jan. 1, 2000 from a buildid string
49 sub daysFromBuildID
51 my ($buildid,) = @_;
53 my ($y, $m, $d, $h) = ($buildid =~ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/);
54 $d || die("Unrecognized buildid string.");
56 my $secondstodays = 60 * 60 * 24;
57 return (POSIX::mktime(00, 00, 00, $d, $m - 1, $y - 1900) -
58 POSIX::mktime(00, 00, 00, 01, 00, 100)) / $secondstodays;
61 #Creates version resource file
63 #Paramaters are passed on the command line:
65 #Example: -MODNAME nsToolkitCompsModule -DEBUG=1
67 # DEBUG - Mozilla's global debug variable - tells if its debug version
68 # OFFICIAL - tells Mozilla is building a milestone or nightly
69 # MSTONE - tells which milestone is being built;
70 # OBJDIR - Holds the object directory;
71 # MODNAME - tells what the name of the module is like nsBMPModule
72 # DEPTH - Holds the path to the root obj dir
73 # TOPSRCDIR - Holds the path to the root mozilla dir
74 # SRCDIR - Holds module.ver and source
75 # BINARY - Holds the name of the binary file
76 # DISPNAME - Holds the display name of the built application
77 # APPVERSION - Holds the version string of the built application
78 # BITS - 16 or 32 bit
79 # RCINCLUDE - Holds the name of the RC File to include or ""
80 # QUIET - Turns off output
82 #Description and Comment come from module.ver
83 #Bug 23560
84 #http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/rc_7x2d.asp
86 #Get next .ver file entry
87 sub getNextEntry
89 while (<VERFILE>)
91 my $mline = $_;
92 ($mline) = split(/#/,$mline);
93 my ($entry, $value)=split(/=/,$mline,2);
94 if (defined($entry))
96 if (defined($value))
98 $entry =~ s/^\s*(.*?)\s*$/$1/;
99 $value =~ s/^\s*(.*?)\s*$/$1/;
100 return ($entry,$value);
104 return undef;
107 my ($quiet,$objdir,$debug,$official,$milestone,$buildid,$module,$binary,$depth,$rcinclude,$bits,$srcdir,$fileversion,$productversion);
109 GetOptions( "QUIET" => \$quiet,
110 "DEBUG=s" => \$debug,
111 "OFFICIAL=s" => \$official,
112 "MSTONE=s" => \$milestone,
113 "MODNAME=s" => \$module,
114 "BINARY=s" => \$binary,
115 "DISPNAME=s" => \$displayname,
116 "APPVERSION=s" => \$appversion,
117 "SRCDIR=s" => \$srcdir,
118 "TOPSRCDIR=s" => \$topsrcdir,
119 "DEPTH=s" => \$depth,
120 "RCINCLUDE=s" => \$rcinclude,
121 "OBJDIR=s" => \$objdir,
122 "BITS=s" => \$bits);
123 if (!defined($debug)) {$debug="";}
124 if (!defined($official)) {$official="";}
125 if (!defined($milestone)) {$milestone="";}
126 if (!defined($module)) {$module="";}
127 if (!defined($binary)) {$binary="";}
128 if (!defined($displayname)) {$displayname="Mozilla";}
129 if (!defined($appversion)) {$appversion=$milestone;}
130 if (!defined($depth)) {$depth=".";}
131 if (!defined($rcinclude)) {$rcinclude="";}
132 if (!defined($objdir)) {$objdir=".";}
133 if (!defined($srcdir)) {$srcdir=".";}
134 if (!defined($topsrcdir)) {$topsrcdir=".";}
135 if (!defined($bits)) {$bits="";}
136 my $mfversion = "Personal";
137 my $mpversion = "Personal";
138 my @fileflags = ("0");
139 my $comment="";
140 my $description="";
141 if (!defined($module))
143 $module = $binary;
144 ($module) = split(/\./,$module);
147 my $fileos = "VOS__WINDOWS32";
148 if ($bits eq "16") { $fileos="VOS__WINDOWS16"; }
150 my $bufferstr=" ";
152 my $MILESTONE_FILE = "$topsrcdir/config/milestone.txt";
153 my $BUILDID_FILE = "$depth/config/buildid";
155 #Read module.ver file
156 #Version file overrides for WIN32:
157 #WIN32_MODULE_COMMENT
158 #WIN32_MODULE_DESCRIPTION
159 #WIN32_MODULE_FILEVERSION
160 #WIN32_MODULE_COMPANYNAME
161 #WIN32_MODULE_FILEVERSION_STRING
162 #WIN32_MODULE_NAME
163 #WIN32_MODULE_COPYRIGHT
164 #WIN32_MODULE_TRADEMARKS
165 #WIN32_MODULE_ORIGINAL_FILENAME
166 #WIN32_MODULE_PRODUCTNAME
167 #WIN32_MODULE_PRODUCTVERSION
168 #WIN32_MODULE_PRODUCTVERSION_STRING
170 #Override values obtained from the .ver file
171 my $override_comment;
172 my $override_description;
173 my $override_fileversion;
174 my $override_company;
175 my $override_mfversion;
176 my $override_module;
177 my $override_copyright;
178 my $override_trademarks;
179 my $override_filename;
180 my $override_productname;
181 my $override_productversion;
182 my $override_mpversion;
183 if (open(VERFILE, "<$srcdir/module.ver"))
186 my ($a,$b) = getNextEntry();
187 while (defined($a))
189 if ($a eq "WIN32_MODULE_COMMENT") { $override_comment = $b; }
190 if ($a eq "WIN32_MODULE_DESCRIPTION") { $override_description = $b; }
191 if ($a eq "WIN32_MODULE_FILEVERSION") { $override_fileversion = $b; }
192 if ($a eq "WIN32_MODULE_COMPANYNAME") { $override_company = $b; }
193 if ($a eq "WIN32_MODULE_FILEVERSION_STRING") { $override_mfversion = $b; }
194 if ($a eq "WIN32_MODULE_NAME") { $override_module = $b; }
195 if ($a eq "WIN32_MODULE_COPYRIGHT") { $override_copyright = $b; }
196 if ($a eq "WIN32_MODULE_TRADEMARKS") { $override_trademarks = $b; }
197 if ($a eq "WIN32_MODULE_ORIGINAL_FILENAME") { $override_filename = $b; }
198 if ($a eq "WIN32_MODULE_PRODUCTNAME") { $override_productname = $b; }
199 if ($a eq "WIN32_MODULE_PRODUCTVERSION") { $override_productversion = $b; }
200 if ($a eq "WIN32_MODULE_PRODUCTVERSION_STRING") { $override_mpversion = $b; }
201 ($a,$b) = getNextEntry();
203 close(VERFILE)
205 else
207 if (!$quiet || $quiet ne "1") { print "$bufferstr" . "WARNING: No module.ver file included ($module, $binary). Default values used\n"; }
209 #Get rid of trailing and leading whitespace
210 $debug =~ s/^\s*(.*)\s*$/$1/;
211 $comment =~ s/^\s*(.*)\s*$/$1/;
212 $official =~ s/^\s*(.*)\s*$/$1/;
213 $milestone =~ s/^\s*(.*)\s*$/$1/;
214 $description =~ s/^\s*(.*)\s*$/$1/;
215 $module =~ s/^\s*(.*)\s*$/$1/;
216 $depth =~ s/^\s*(.*)\s*$/$1/;
217 $binary =~ s/^\s*(.*)\s*$/$1/;
218 $displayname =~ s/^\s*(.*)\s*$/$1/;
220 open(BUILDID, "<", $BUILDID_FILE) || die("Couldn't open buildid file: $BUILDID_FILE");
221 $buildid = <BUILDID>;
222 $buildid =~ s/\s*$//;
223 close BUILDID;
225 my $daycount = daysFromBuildID($buildid);
227 if ($milestone eq "") {
228 $milestone = Moz::Milestone::getOfficialMilestone($MILESTONE_FILE);
231 $mfversion = $mpversion = $milestone;
232 if ($appversion eq "") {
233 $appversion = $milestone;
236 if ($debug eq "1")
238 push @fileflags, "VS_FF_DEBUG";
239 $mpversion .= " Debug";
240 $mfversion .= " Debug";
243 if ($official ne "1") {
244 push @fileflags, "VS_FF_PRIVATEBUILD";
247 if ($milestone =~ /[a-z]/) {
248 push @fileflags, "VS_FF_PRERELEASE";
251 my @mstone = split(/\./,$milestone);
252 $mstone[1] =~s/\D.*$//;
253 if (!$mstone[2]) {
254 $mstone[2] = "0";
256 else {
257 $mstone[2] =~s/\D.*$//;
259 $fileversion = $productversion="$mstone[0],$mstone[1],$mstone[2],$daycount";
261 my @appver = split(/\./,$appversion);
262 for ($j = 1; $j < 4; $j++)
264 if (!$appver[$j]) {
265 $appver[$j] = "0";
267 else {
268 $appver[$j] =~s/\D.*$//;
271 my $winappversion = "$appver[0],$appver[1],$appver[2],$appver[3]";
273 my $copyright = "License: MPL 1.1/GPL 2.0/LGPL 2.1";
274 my $company = "Mozilla Foundation";
275 my $trademarks = "Mozilla";
276 my $productname = $displayname;
279 if (defined($override_comment)){$override_comment =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $comment=$override_comment;}
280 if (defined($override_description)){$override_description =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $description=$override_description;}
281 if (defined($override_fileversion)){$override_fileversion =~ s/\@MOZ_APP_WINVERSION\@/$winappversion/g; $fileversion=$override_fileversion;}
282 if (defined($override_mfversion)){$override_mfversion =~ s/\@MOZ_APP_VERSION\@/$appversion/g; $mfversion=$override_mfversion;}
283 if (defined($override_company)){$company=$override_company;}
284 if (defined($override_module)){$override_module =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $module=$override_module;}
285 if (defined($override_copyright)){$override_copyright =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $copyright=$override_copyright;}
286 if (defined($override_trademarks)){$override_trademarks =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $trademarks=$override_trademarks;}
287 if (defined($override_filename)){$binary=$override_filename;}
288 if (defined($override_productname)){$override_productname =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $productname=$override_productname;}
289 if (defined($override_productversion)){$override_productversion =~ s/\@MOZ_APP_WINVERSION\@/$winappversion/g; $productversion=$override_productversion;}
290 if (defined($override_mpversion)){$override_mpversion =~ s/\@MOZ_APP_VERSION\@/$appversion/g; $mpversion=$override_mpversion;}
293 #Override section
295 open(RCFILE, ">$objdir/module.rc") || die("Can't edit module.rc - It must be locked.\n");
296 print RCFILE qq{
297 // ***** BEGIN LICENSE BLOCK *****
298 // Version: MPL 1.1/GPL 2.0/LGPL 2.1
300 // The contents of this file are subject to the Mozilla Public License Version
301 // 1.1 (the "License"); you may not use this file except in compliance with
302 // the License. You may obtain a copy of the License at
303 // http://www.mozilla.org/MPL/
305 // Software distributed under the License is distributed on an "AS IS" basis,
306 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
307 // for the specific language governing rights and limitations under the
308 // License.
310 // The Original Code is the Win32 Version System.
312 // The Initial Developer of the Original Code is Brian Bober <netdemonz\@yahoo.com>
313 // Portions created by the Initial Developer are Copyright (C) 2001
314 // the Initial Developer. All Rights Reserved.
316 // Contributor(s):
318 // Alternatively, the contents of this file may be used under the terms of
319 // either the GNU General Public License Version 2 or later (the "GPL"), or
320 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
321 // in which case the provisions of the GPL or the LGPL are applicable instead
322 // of those above. If you wish to allow use of your version of this file only
323 // under the terms of either the GPL or the LGPL, and not to allow others to
324 // use your version of this file under the terms of the MPL, indicate your
325 // decision by deleting the provisions above and replace them with the notice
326 // and other provisions required by the GPL or the LGPL. If you do not delete
327 // the provisions above, a recipient may use your version of this file under
328 // the terms of any one of the MPL, the GPL or the LGPL.
330 // ***** END LICENSE BLOCK *****
332 #include<winver.h>
334 // Note: if you contain versioning information in an included
335 // RC script, it will be discarded
336 // Use module.ver to explicitly set these values
338 // Do not edit this file. Changes won't affect the build.
342 my $versionlevel=0;
343 my $insideversion=0;
344 if (open(RCINCLUDE, "<$rcinclude"))
346 print RCFILE "// From included resource $rcinclude\n";
347 # my $mstring="";
348 while (<RCINCLUDE>)
350 $_ =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g;
351 print RCFILE $_;
352 # my $instr=$_;
353 # chomp($instr);
354 # $mstring .= "$instr\;";
356 close(RCINCLUDE);
357 # $mstring =~ s/\/\*.*\*\///g;
358 # my @mlines = split(/\;/,$mstring);
359 # for(@mlines)
361 # my ($nocomment)=split(/\/\//,$_);
362 # if (defined($nocomment) && $nocomment ne "")
364 # my ($firststring,$secondstring) = split(/\s+/,$nocomment);
365 # if (!defined($firststring)) {$firststring="";}
366 # if (!defined($secondstring)) {$secondstring="";}
367 # if ($secondstring eq "VERSIONINFO")
369 #if (!$quiet || $quiet ne "1") {
370 # print "$bufferstr" . "WARNING: Included RC file ($rcinclude, $module, $binary)\n";
371 # print "$bufferstr" . "WARNING: contains versioning information that will be discarded\n";
372 # print "$bufferstr" . "WARNING: Remove it and use relevant overrides (in module.ver)\n";
374 # $versionlevel = 0;
375 # $insideversion = 1;
377 # if ($firststring eq "BEGIN") { $versionlevel++; }
378 # if ($secondstring eq "END")
379 # {
380 # $versionlevel--;
381 # if ($insideversion==1 && $versionlevel==0) {$versionlevel=0;}
383 # my $includecheck = $firststring . $secondstring;
384 # $includecheck =~ s/<|>/"/g;
385 # $includecheck = lc($includecheck);
386 # if ($includecheck ne "#include\"winver.h\"")
388 # if ($insideversion == 0 && $versionlevel == 0)
390 # print RCFILE "$nocomment\n";
398 my $fileflags = join(' | ', @fileflags);
400 print RCFILE qq{
403 /////////////////////////////////////////////////////////////////////////////
405 // Version
408 1 VERSIONINFO
409 FILEVERSION $fileversion
410 PRODUCTVERSION $productversion
411 FILEFLAGSMASK 0x3fL
412 FILEFLAGS $fileflags
413 FILEOS $fileos
414 FILETYPE VFT_DLL
415 FILESUBTYPE 0x0L
416 BEGIN
417 BLOCK "StringFileInfo"
418 BEGIN
419 BLOCK "000004b0"
420 BEGIN
421 VALUE "Comments", "$comment"
422 VALUE "LegalCopyright", "$copyright"
423 VALUE "CompanyName", "$company"
424 VALUE "FileDescription", "$description"
425 VALUE "FileVersion", "$mfversion"
426 VALUE "ProductVersion", "$mpversion"
427 VALUE "InternalName", "$module"
428 VALUE "LegalTrademarks", "$trademarks"
429 VALUE "OriginalFilename", "$binary"
430 VALUE "ProductName", "$productname"
431 VALUE "BuildID", "$buildid"
434 BLOCK "VarFileInfo"
435 BEGIN
436 VALUE "Translation", 0x0, 1200
441 close(RCFILE);