Bug 574454 - Cleanup nsNativeThemeWin's GetMinimumWidgetSize a bit. r=roc.
[mozilla-central.git] / config / version_win.pl
blob2e5b8804bf7b7d6e07b5d033c948758415c586b0
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 sprintf("%d",
58 (POSIX::mktime(00, 00, 00, $d, $m - 1, $y - 1900) -
59 POSIX::mktime(00, 00, 00, 01, 00, 100)) / $secondstodays);
62 #Creates version resource file
64 #Paramaters are passed on the command line:
66 #Example: -MODNAME nsToolkitCompsModule -DEBUG=1
68 # DEBUG - Mozilla's global debug variable - tells if its debug version
69 # OFFICIAL - tells Mozilla is building a milestone or nightly
70 # MSTONE - tells which milestone is being built;
71 # OBJDIR - Holds the object directory;
72 # MODNAME - tells what the name of the module is like nsBMPModule
73 # DEPTH - Holds the path to the root obj dir
74 # TOPSRCDIR - Holds the path to the root mozilla dir
75 # SRCDIR - Holds module.ver and source
76 # BINARY - Holds the name of the binary file
77 # DISPNAME - Holds the display name of the built application
78 # APPVERSION - Holds the version string of the built application
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,$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 if (!defined($debug)) {$debug="";}
123 if (!defined($official)) {$official="";}
124 if (!defined($milestone)) {$milestone="";}
125 if (!defined($module)) {$module="";}
126 if (!defined($binary)) {$binary="";}
127 if (!defined($displayname)) {$displayname="Mozilla";}
128 if (!defined($appversion)) {$appversion=$milestone;}
129 if (!defined($depth)) {$depth=".";}
130 if (!defined($rcinclude)) {$rcinclude="";}
131 if (!defined($objdir)) {$objdir=".";}
132 if (!defined($srcdir)) {$srcdir=".";}
133 if (!defined($topsrcdir)) {$topsrcdir=".";}
134 my $mfversion = "Personal";
135 my $mpversion = "Personal";
136 my @fileflags = ("0");
137 my $comment="";
138 my $description="";
139 if (!defined($module))
141 $module = $binary;
142 ($module) = split(/\./,$module);
145 my $bufferstr=" ";
147 my $MILESTONE_FILE = "$topsrcdir/config/milestone.txt";
148 my $BUILDID_FILE = "$depth/config/buildid";
150 #Read module.ver file
151 #Version file overrides for WIN32:
152 #WIN32_MODULE_COMMENT
153 #WIN32_MODULE_DESCRIPTION
154 #WIN32_MODULE_FILEVERSION
155 #WIN32_MODULE_COMPANYNAME
156 #WIN32_MODULE_FILEVERSION_STRING
157 #WIN32_MODULE_NAME
158 #WIN32_MODULE_COPYRIGHT
159 #WIN32_MODULE_TRADEMARKS
160 #WIN32_MODULE_ORIGINAL_FILENAME
161 #WIN32_MODULE_PRODUCTNAME
162 #WIN32_MODULE_PRODUCTVERSION
163 #WIN32_MODULE_PRODUCTVERSION_STRING
165 #Override values obtained from the .ver file
166 my $override_comment;
167 my $override_description;
168 my $override_fileversion;
169 my $override_company;
170 my $override_mfversion;
171 my $override_module;
172 my $override_copyright;
173 my $override_trademarks;
174 my $override_filename;
175 my $override_productname;
176 my $override_productversion;
177 my $override_mpversion;
178 if (open(VERFILE, "<$srcdir/module.ver"))
181 my ($a,$b) = getNextEntry();
182 while (defined($a))
184 if ($a eq "WIN32_MODULE_COMMENT") { $override_comment = $b; }
185 if ($a eq "WIN32_MODULE_DESCRIPTION") { $override_description = $b; }
186 if ($a eq "WIN32_MODULE_FILEVERSION") { $override_fileversion = $b; }
187 if ($a eq "WIN32_MODULE_COMPANYNAME") { $override_company = $b; }
188 if ($a eq "WIN32_MODULE_FILEVERSION_STRING") { $override_mfversion = $b; }
189 if ($a eq "WIN32_MODULE_NAME") { $override_module = $b; }
190 if ($a eq "WIN32_MODULE_COPYRIGHT") { $override_copyright = $b; }
191 if ($a eq "WIN32_MODULE_TRADEMARKS") { $override_trademarks = $b; }
192 if ($a eq "WIN32_MODULE_ORIGINAL_FILENAME") { $override_filename = $b; }
193 if ($a eq "WIN32_MODULE_PRODUCTNAME") { $override_productname = $b; }
194 if ($a eq "WIN32_MODULE_PRODUCTVERSION") { $override_productversion = $b; }
195 if ($a eq "WIN32_MODULE_PRODUCTVERSION_STRING") { $override_mpversion = $b; }
196 ($a,$b) = getNextEntry();
198 close(VERFILE)
200 else
202 if (!$quiet || $quiet ne "1") { print "$bufferstr" . "WARNING: No module.ver file included ($module, $binary). Default values used\n"; }
204 #Get rid of trailing and leading whitespace
205 $debug =~ s/^\s*(.*)\s*$/$1/;
206 $comment =~ s/^\s*(.*)\s*$/$1/;
207 $official =~ s/^\s*(.*)\s*$/$1/;
208 $milestone =~ s/^\s*(.*)\s*$/$1/;
209 $description =~ s/^\s*(.*)\s*$/$1/;
210 $module =~ s/^\s*(.*)\s*$/$1/;
211 $depth =~ s/^\s*(.*)\s*$/$1/;
212 $binary =~ s/^\s*(.*)\s*$/$1/;
213 $displayname =~ s/^\s*(.*)\s*$/$1/;
215 open(BUILDID, "<", $BUILDID_FILE) || die("Couldn't open buildid file: $BUILDID_FILE");
216 $buildid = <BUILDID>;
217 $buildid =~ s/\s*$//;
218 close BUILDID;
220 my $daycount = daysFromBuildID($buildid);
222 if ($milestone eq "") {
223 $milestone = Moz::Milestone::getOfficialMilestone($MILESTONE_FILE);
226 $mfversion = $mpversion = $milestone;
227 if ($appversion eq "") {
228 $appversion = $milestone;
231 if ($debug eq "1")
233 push @fileflags, "VS_FF_DEBUG";
234 $mpversion .= " Debug";
235 $mfversion .= " Debug";
238 if ($official ne "1") {
239 push @fileflags, "VS_FF_PRIVATEBUILD";
242 if ($milestone =~ /[a-z]/) {
243 push @fileflags, "VS_FF_PRERELEASE";
246 my @mstone = split(/\./,$milestone);
247 $mstone[1] =~s/\D.*$//;
248 if (!$mstone[2]) {
249 $mstone[2] = "0";
251 else {
252 $mstone[2] =~s/\D.*$//;
254 $fileversion = $productversion="$mstone[0],$mstone[1],$mstone[2],$daycount";
256 my @appver = split(/\./,$appversion);
257 for ($j = 1; $j < 4; $j++)
259 if (!$appver[$j]) {
260 $appver[$j] = "0";
262 else {
263 $appver[$j] =~s/\D.*$//;
266 my $winappversion = "$appver[0],$appver[1],$appver[2],$appver[3]";
268 my $copyright = "License: MPL 1.1/GPL 2.0/LGPL 2.1";
269 my $company = "Mozilla Foundation";
270 my $trademarks = "Mozilla";
271 my $productname = $displayname;
274 if (defined($override_comment)){$override_comment =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $comment=$override_comment;}
275 if (defined($override_description)){$override_description =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $description=$override_description;}
276 if (defined($override_fileversion)){$override_fileversion =~ s/\@MOZ_APP_WINVERSION\@/$winappversion/g; $fileversion=$override_fileversion;}
277 if (defined($override_mfversion)){$override_mfversion =~ s/\@MOZ_APP_VERSION\@/$appversion/g; $mfversion=$override_mfversion;}
278 if (defined($override_company)){$company=$override_company;}
279 if (defined($override_module)){$override_module =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $module=$override_module;}
280 if (defined($override_copyright)){$override_copyright =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $copyright=$override_copyright;}
281 if (defined($override_trademarks)){$override_trademarks =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $trademarks=$override_trademarks;}
282 if (defined($override_filename)){$binary=$override_filename;}
283 if (defined($override_productname)){$override_productname =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $productname=$override_productname;}
284 if (defined($override_productversion)){$override_productversion =~ s/\@MOZ_APP_WINVERSION\@/$winappversion/g; $productversion=$override_productversion;}
285 if (defined($override_mpversion)){$override_mpversion =~ s/\@MOZ_APP_VERSION\@/$appversion/g; $mpversion=$override_mpversion;}
288 #Override section
290 open(RCFILE, ">$objdir/module.rc") || die("Can't edit module.rc - It must be locked.\n");
291 print RCFILE qq{
292 // ***** BEGIN LICENSE BLOCK *****
293 // Version: MPL 1.1/GPL 2.0/LGPL 2.1
295 // The contents of this file are subject to the Mozilla Public License Version
296 // 1.1 (the "License"); you may not use this file except in compliance with
297 // the License. You may obtain a copy of the License at
298 // http://www.mozilla.org/MPL/
300 // Software distributed under the License is distributed on an "AS IS" basis,
301 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
302 // for the specific language governing rights and limitations under the
303 // License.
305 // The Original Code is the Win32 Version System.
307 // The Initial Developer of the Original Code is Brian Bober <netdemonz\@yahoo.com>
308 // Portions created by the Initial Developer are Copyright (C) 2001
309 // the Initial Developer. All Rights Reserved.
311 // Contributor(s):
313 // Alternatively, the contents of this file may be used under the terms of
314 // either the GNU General Public License Version 2 or later (the "GPL"), or
315 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
316 // in which case the provisions of the GPL or the LGPL are applicable instead
317 // of those above. If you wish to allow use of your version of this file only
318 // under the terms of either the GPL or the LGPL, and not to allow others to
319 // use your version of this file under the terms of the MPL, indicate your
320 // decision by deleting the provisions above and replace them with the notice
321 // and other provisions required by the GPL or the LGPL. If you do not delete
322 // the provisions above, a recipient may use your version of this file under
323 // the terms of any one of the MPL, the GPL or the LGPL.
325 // ***** END LICENSE BLOCK *****
327 #include<winver.h>
329 // Note: if you contain versioning information in an included
330 // RC script, it will be discarded
331 // Use module.ver to explicitly set these values
333 // Do not edit this file. Changes won't affect the build.
337 my $versionlevel=0;
338 my $insideversion=0;
339 if (open(RCINCLUDE, "<$rcinclude"))
341 print RCFILE "// From included resource $rcinclude\n";
342 # my $mstring="";
343 while (<RCINCLUDE>)
345 $_ =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g;
346 print RCFILE $_;
347 # my $instr=$_;
348 # chomp($instr);
349 # $mstring .= "$instr\;";
351 close(RCINCLUDE);
352 # $mstring =~ s/\/\*.*\*\///g;
353 # my @mlines = split(/\;/,$mstring);
354 # for(@mlines)
356 # my ($nocomment)=split(/\/\//,$_);
357 # if (defined($nocomment) && $nocomment ne "")
359 # my ($firststring,$secondstring) = split(/\s+/,$nocomment);
360 # if (!defined($firststring)) {$firststring="";}
361 # if (!defined($secondstring)) {$secondstring="";}
362 # if ($secondstring eq "VERSIONINFO")
364 #if (!$quiet || $quiet ne "1") {
365 # print "$bufferstr" . "WARNING: Included RC file ($rcinclude, $module, $binary)\n";
366 # print "$bufferstr" . "WARNING: contains versioning information that will be discarded\n";
367 # print "$bufferstr" . "WARNING: Remove it and use relevant overrides (in module.ver)\n";
369 # $versionlevel = 0;
370 # $insideversion = 1;
372 # if ($firststring eq "BEGIN") { $versionlevel++; }
373 # if ($secondstring eq "END")
374 # {
375 # $versionlevel--;
376 # if ($insideversion==1 && $versionlevel==0) {$versionlevel=0;}
378 # my $includecheck = $firststring . $secondstring;
379 # $includecheck =~ s/<|>/"/g;
380 # $includecheck = lc($includecheck);
381 # if ($includecheck ne "#include\"winver.h\"")
383 # if ($insideversion == 0 && $versionlevel == 0)
385 # print RCFILE "$nocomment\n";
393 my $fileflags = join(' | ', @fileflags);
395 print RCFILE qq{
398 /////////////////////////////////////////////////////////////////////////////
400 // Version
403 1 VERSIONINFO
404 FILEVERSION $fileversion
405 PRODUCTVERSION $productversion
406 FILEFLAGSMASK 0x3fL
407 FILEFLAGS $fileflags
408 FILEOS VOS__WINDOWS32
409 FILETYPE VFT_DLL
410 FILESUBTYPE 0x0L
411 BEGIN
412 BLOCK "StringFileInfo"
413 BEGIN
414 BLOCK "000004b0"
415 BEGIN
416 VALUE "Comments", "$comment"
417 VALUE "LegalCopyright", "$copyright"
418 VALUE "CompanyName", "$company"
419 VALUE "FileDescription", "$description"
420 VALUE "FileVersion", "$mfversion"
421 VALUE "ProductVersion", "$mpversion"
422 VALUE "InternalName", "$module"
423 VALUE "LegalTrademarks", "$trademarks"
424 VALUE "OriginalFilename", "$binary"
425 VALUE "ProductName", "$productname"
426 VALUE "BuildID", "$buildid"
429 BLOCK "VarFileInfo"
430 BEGIN
431 VALUE "Translation", 0x0, 1200
436 close(RCFILE);