1 |
#!/usr/bin/perl -w |
2 |
|
3 |
# ***** BEGIN LICENSE BLOCK ***** |
4 |
# Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
5 |
# |
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/ |
10 |
# |
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. |
15 |
# |
16 |
# The Original Code is the Win32 Version System. |
17 |
# |
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. |
21 |
# |
22 |
# Contributor(s): |
23 |
# |
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. |
35 |
# |
36 |
# ***** END LICENSE BLOCK ***** |
37 |
|
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; |
47 |
|
48 |
# Calculate the number of days since Jan. 1, 2000 from a buildid string |
49 |
sub daysFromBuildID |
50 |
{ |
51 |
my ($buildid,) = @_; |
52 |
|
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."); |
55 |
|
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; |
59 |
} |
60 |
|
61 |
#Creates version resource file |
62 |
|
63 |
#Paramaters are passed on the command line: |
64 |
|
65 |
#Example: -MODNAME nsToolkitCompsModule -DEBUG=1 |
66 |
|
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 |
81 |
|
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 |
85 |
|
86 |
#Get next .ver file entry |
87 |
sub getNextEntry |
88 |
{ |
89 |
while (<VERFILE>) |
90 |
{ |
91 |
my $mline = $_; |
92 |
($mline) = split(/#/,$mline); |
93 |
my ($entry, $value)=split(/=/,$mline,2); |
94 |
if (defined($entry)) |
95 |
{ |
96 |
if (defined($value)) |
97 |
{ |
98 |
$entry =~ s/^\s*(.*?)\s*$/$1/; |
99 |
$value =~ s/^\s*(.*?)\s*$/$1/; |
100 |
return ($entry,$value); |
101 |
} |
102 |
} |
103 |
} |
104 |
return undef; |
105 |
} |
106 |
|
107 |
my ($quiet,$objdir,$debug,$official,$milestone,$buildid,$module,$binary,$depth,$rcinclude,$bits,$srcdir,$fileversion,$productversion); |
108 |
|
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)) |
142 |
{ |
143 |
$module = $binary; |
144 |
($module) = split(/\./,$module); |
145 |
} |
146 |
|
147 |
my $fileos = "VOS__WINDOWS32"; |
148 |
if ($bits eq "16") { $fileos="VOS__WINDOWS16"; } |
149 |
|
150 |
my $bufferstr=" "; |
151 |
|
152 |
my $MILESTONE_FILE = "$topsrcdir/config/milestone.txt"; |
153 |
my $BUILDID_FILE = "$depth/config/buildid"; |
154 |
|
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 |
169 |
|
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")) |
184 |
{ |
185 |
|
186 |
my ($a,$b) = getNextEntry(); |
187 |
while (defined($a)) |
188 |
{ |
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(); |
202 |
} |
203 |
close(VERFILE) |
204 |
} |
205 |
else |
206 |
{ |
207 |
if (!$quiet || $quiet ne "1") { print "$bufferstr" . "WARNING: No module.ver file included ($module, $binary). Default values used\n"; } |
208 |
} |
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/; |
219 |
|
220 |
open(BUILDID, "<", $BUILDID_FILE) || die("Couldn't open buildid file: $BUILDID_FILE"); |
221 |
$buildid = <BUILDID>; |
222 |
$buildid =~ s/\s*$//; |
223 |
close BUILDID; |
224 |
|
225 |
my $daycount = daysFromBuildID($buildid); |
226 |
|
227 |
if ($milestone eq "") { |
228 |
$milestone = Moz::Milestone::getOfficialMilestone($MILESTONE_FILE); |
229 |
} |
230 |
|
231 |
$mfversion = $mpversion = $milestone; |
232 |
if ($appversion eq "") { |
233 |
$appversion = $milestone; |
234 |
} |
235 |
|
236 |
if ($debug eq "1") |
237 |
{ |
238 |
push @fileflags, "VS_FF_DEBUG"; |
239 |
$mpversion .= " Debug"; |
240 |
$mfversion .= " Debug"; |
241 |
} |
242 |
|
243 |
if ($official ne "1") { |
244 |
push @fileflags, "VS_FF_PRIVATEBUILD"; |
245 |
} |
246 |
|
247 |
if ($milestone =~ /[a-z]/) { |
248 |
push @fileflags, "VS_FF_PRERELEASE"; |
249 |
} |
250 |
|
251 |
my @mstone = split(/\./,$milestone); |
252 |
$mstone[1] =~s/\D.*$//; |
253 |
if (!$mstone[2]) { |
254 |
$mstone[2] = "0"; |
255 |
} |
256 |
else { |
257 |
$mstone[2] =~s/\D.*$//; |
258 |
} |
259 |
$fileversion = $productversion="$mstone[0],$mstone[1],$mstone[2],$daycount"; |
260 |
|
261 |
my @appver = split(/\./,$appversion); |
262 |
for ($j = 1; $j < 4; $j++) |
263 |
{ |
264 |
if (!$appver[$j]) { |
265 |
$appver[$j] = "0"; |
266 |
} |
267 |
else { |
268 |
$appver[$j] =~s/\D.*$//; |
269 |
} |
270 |
} |
271 |
my $winappversion = "$appver[0],$appver[1],$appver[2],$appver[3]"; |
272 |
|
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; |
277 |
|
278 |
|
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;} |
291 |
|
292 |
|
293 |
#Override section |
294 |
|
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 |
299 |
// |
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/ |
304 |
// |
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. |
309 |
// |
310 |
// The Original Code is the Win32 Version System. |
311 |
// |
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. |
315 |
// |
316 |
// Contributor(s): |
317 |
// |
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. |
329 |
// |
330 |
// ***** END LICENSE BLOCK ***** |
331 |
|
332 |
#include<winver.h> |
333 |
|
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 |
337 |
|
338 |
// Do not edit this file. Changes won't affect the build. |
339 |
|
340 |
}; |
341 |
|
342 |
my $versionlevel=0; |
343 |
my $insideversion=0; |
344 |
if (open(RCINCLUDE, "<$rcinclude")) |
345 |
{ |
346 |
print RCFILE "// From included resource $rcinclude\n"; |
347 |
# my $mstring=""; |
348 |
while (<RCINCLUDE>) |
349 |
{ |
350 |
$_ =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; |
351 |
print RCFILE $_; |
352 |
# my $instr=$_; |
353 |
# chomp($instr); |
354 |
# $mstring .= "$instr\;"; |
355 |
} |
356 |
close(RCINCLUDE); |
357 |
# $mstring =~ s/\/\*.*\*\///g; |
358 |
# my @mlines = split(/\;/,$mstring); |
359 |
# for(@mlines) |
360 |
# { |
361 |
# my ($nocomment)=split(/\/\//,$_); |
362 |
# if (defined($nocomment) && $nocomment ne "") |
363 |
# { |
364 |
# my ($firststring,$secondstring) = split(/\s+/,$nocomment); |
365 |
# if (!defined($firststring)) {$firststring="";} |
366 |
# if (!defined($secondstring)) {$secondstring="";} |
367 |
# if ($secondstring eq "VERSIONINFO") |
368 |
# { |
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"; |
373 |
#} |
374 |
# $versionlevel = 0; |
375 |
# $insideversion = 1; |
376 |
# } |
377 |
# if ($firststring eq "BEGIN") { $versionlevel++; } |
378 |
# if ($secondstring eq "END") |
379 |
# { |
380 |
# $versionlevel--; |
381 |
# if ($insideversion==1 && $versionlevel==0) {$versionlevel=0;} |
382 |
# } |
383 |
# my $includecheck = $firststring . $secondstring; |
384 |
# $includecheck =~ s/<|>/"/g; |
385 |
# $includecheck = lc($includecheck); |
386 |
# if ($includecheck ne "#include\"winver.h\"") |
387 |
# { |
388 |
# if ($insideversion == 0 && $versionlevel == 0) |
389 |
# { |
390 |
# print RCFILE "$nocomment\n"; |
391 |
# } |
392 |
# } |
393 |
# } |
394 |
# } |
395 |
|
396 |
} |
397 |
|
398 |
my $fileflags = join(' | ', @fileflags); |
399 |
|
400 |
print RCFILE qq{ |
401 |
|
402 |
|
403 |
///////////////////////////////////////////////////////////////////////////// |
404 |
// |
405 |
// Version |
406 |
// |
407 |
|
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" |
432 |
END |
433 |
END |
434 |
BLOCK "VarFileInfo" |
435 |
BEGIN |
436 |
VALUE "Translation", 0x0, 1200 |
437 |
END |
438 |
END |
439 |
|
440 |
}; |
441 |
close(RCFILE); |