version_win.pl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. #!/usr/bin/perl -w
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. #use diagnostics;
  6. require strict;
  7. my $dir = $0;
  8. $dir =~ s/[^\/]*$//;
  9. push(@INC, "$dir");
  10. require "Moz/Milestone.pm";
  11. use Getopt::Long;
  12. use Getopt::Std;
  13. use POSIX;
  14. # Calculate the number of days since Jan. 1, 2000 from a buildid string
  15. sub daysFromBuildID
  16. {
  17. my ($buildid,) = @_;
  18. my ($y, $m, $d, $h) = ($buildid =~ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/);
  19. $d || die("Unrecognized buildid string.");
  20. my $secondstodays = 60 * 60 * 24;
  21. return sprintf("%d",
  22. (POSIX::mktime(00, 00, 00, $d, $m - 1, $y - 1900) -
  23. POSIX::mktime(00, 00, 00, 01, 00, 100)) / $secondstodays);
  24. }
  25. #Creates version resource file
  26. #Paramaters are passed on the command line:
  27. #Example: -MODNAME nsToolkitCompsModule -DEBUG=1
  28. # DEBUG - Mozilla's global debug variable - tells if its debug version
  29. # OFFICIAL - tells Mozilla is building a milestone or nightly
  30. # MSTONE - tells which milestone is being built;
  31. # OBJDIR - Holds the object directory;
  32. # MODNAME - tells what the name of the module is like nsBMPModule
  33. # DEPTH - Holds the path to the root obj dir
  34. # TOPSRCDIR - Holds the path to the root mozilla dir
  35. # SRCDIR - Holds module.ver and source
  36. # BINARY - Holds the name of the binary file
  37. # DISPNAME - Holds the display name of the built application
  38. # APPVERSION - Holds the version string of the built application
  39. # RCINCLUDE - Holds the name of the RC File to include or ""
  40. # QUIET - Turns off output
  41. #Description and Comment come from module.ver
  42. #Bug 23560
  43. #http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/rc_7x2d.asp
  44. #Get next .ver file entry
  45. sub getNextEntry
  46. {
  47. while (<VERFILE>)
  48. {
  49. my $mline = $_;
  50. ($mline) = split(/#/,$mline);
  51. my ($entry, $value)=split(/=/,$mline,2);
  52. if (defined($entry))
  53. {
  54. if (defined($value))
  55. {
  56. $entry =~ s/^\s*(.*?)\s*$/$1/;
  57. $value =~ s/^\s*(.*?)\s*$/$1/;
  58. return ($entry,$value);
  59. }
  60. }
  61. }
  62. return undef;
  63. }
  64. my ($quiet,$objdir,$debug,$official,$milestone,$buildid,$module,$binary,$depth,$rcinclude,$srcdir,$fileversion,$productversion);
  65. GetOptions( "QUIET" => \$quiet,
  66. "DEBUG=s" => \$debug,
  67. "OFFICIAL=s" => \$official,
  68. "MSTONE=s" => \$milestone,
  69. "MODNAME=s" => \$module,
  70. "BINARY=s" => \$binary,
  71. "DISPNAME=s" => \$displayname,
  72. "APPVERSION=s" => \$appversion,
  73. "SRCDIR=s" => \$srcdir,
  74. "TOPSRCDIR=s" => \$topsrcdir,
  75. "DEPTH=s" => \$depth,
  76. "RCINCLUDE=s" => \$rcinclude,
  77. "OBJDIR=s" => \$objdir);
  78. if (!defined($debug)) {$debug="";}
  79. if (!defined($official)) {$official="";}
  80. if (!defined($milestone)) {$milestone="";}
  81. if (!defined($module)) {$module="";}
  82. if (!defined($binary)) {$binary="";}
  83. if (!defined($displayname)) {$displayname="UXP";}
  84. if (!defined($appversion)) {$appversion=$milestone;}
  85. if (!defined($depth)) {$depth=".";}
  86. if (!defined($rcinclude)) {$rcinclude="";}
  87. if (!defined($objdir)) {$objdir=".";}
  88. if (!defined($srcdir)) {$srcdir=".";}
  89. if (!defined($topsrcdir)) {$topsrcdir=".";}
  90. my $mfversion = "Personal";
  91. my $mpversion = "Personal";
  92. my @fileflags = ("0");
  93. my $comment="";
  94. my $description="";
  95. if (!defined($module))
  96. {
  97. $module = $binary;
  98. ($module) = split(/\./,$module);
  99. }
  100. my $bufferstr=" ";
  101. my $MILESTONE_FILE = "$topsrcdir/config/milestone.txt";
  102. my $BUILDID_FILE = "$depth/buildid.h";
  103. #Read module.ver file
  104. #Version file overrides for WIN32:
  105. #WIN32_MODULE_COMMENT
  106. #WIN32_MODULE_DESCRIPTION
  107. #WIN32_MODULE_FILEVERSION
  108. #WIN32_MODULE_COMPANYNAME
  109. #WIN32_MODULE_FILEVERSION_STRING
  110. #WIN32_MODULE_NAME
  111. #WIN32_MODULE_COPYRIGHT
  112. #WIN32_MODULE_TRADEMARKS
  113. #WIN32_MODULE_ORIGINAL_FILENAME
  114. #WIN32_MODULE_PRODUCTNAME
  115. #WIN32_MODULE_PRODUCTVERSION
  116. #WIN32_MODULE_PRODUCTVERSION_STRING
  117. #Override values obtained from the .ver file
  118. my $override_comment;
  119. my $override_description;
  120. my $override_fileversion;
  121. my $override_company;
  122. my $override_mfversion;
  123. my $override_module;
  124. my $override_copyright;
  125. my $override_trademarks;
  126. my $override_filename;
  127. my $override_productname;
  128. my $override_productversion;
  129. my $override_mpversion;
  130. if (open(VERFILE, "<$srcdir/module.ver"))
  131. {
  132. my ($a,$b) = getNextEntry();
  133. while (defined($a))
  134. {
  135. if ($a eq "WIN32_MODULE_COMMENT") { $override_comment = $b; }
  136. if ($a eq "WIN32_MODULE_DESCRIPTION") { $override_description = $b; }
  137. if ($a eq "WIN32_MODULE_FILEVERSION") { $override_fileversion = $b; }
  138. if ($a eq "WIN32_MODULE_COMPANYNAME") { $override_company = $b; }
  139. if ($a eq "WIN32_MODULE_FILEVERSION_STRING") { $override_mfversion = $b; }
  140. if ($a eq "WIN32_MODULE_NAME") { $override_module = $b; }
  141. if ($a eq "WIN32_MODULE_COPYRIGHT") { $override_copyright = $b; }
  142. if ($a eq "WIN32_MODULE_TRADEMARKS") { $override_trademarks = $b; }
  143. if ($a eq "WIN32_MODULE_ORIGINAL_FILENAME") { $override_filename = $b; }
  144. if ($a eq "WIN32_MODULE_PRODUCTNAME") { $override_productname = $b; }
  145. if ($a eq "WIN32_MODULE_PRODUCTVERSION") { $override_productversion = $b; }
  146. if ($a eq "WIN32_MODULE_PRODUCTVERSION_STRING") { $override_mpversion = $b; }
  147. ($a,$b) = getNextEntry();
  148. }
  149. close(VERFILE)
  150. }
  151. else
  152. {
  153. if (!$quiet || $quiet ne "1") { print "$bufferstr" . "WARNING: No module.ver file included ($module, $binary). Default values used\n"; }
  154. }
  155. #Get rid of trailing and leading whitespace
  156. $debug =~ s/^\s*(.*)\s*$/$1/;
  157. $comment =~ s/^\s*(.*)\s*$/$1/;
  158. $official =~ s/^\s*(.*)\s*$/$1/;
  159. $milestone =~ s/^\s*(.*)\s*$/$1/;
  160. $description =~ s/^\s*(.*)\s*$/$1/;
  161. $module =~ s/^\s*(.*)\s*$/$1/;
  162. $depth =~ s/^\s*(.*)\s*$/$1/;
  163. $binary =~ s/^\s*(.*)\s*$/$1/;
  164. $displayname =~ s/^\s*(.*)\s*$/$1/;
  165. open(BUILDID, "<", $BUILDID_FILE) || die("Couldn't open buildid file: $BUILDID_FILE");
  166. $buildid = <BUILDID>;
  167. $buildid =~ s/^#define MOZ_BUILDID\s+(\S+)\s*$/$1/;
  168. close BUILDID;
  169. my $daycount = daysFromBuildID($buildid);
  170. if ($milestone eq "") {
  171. $milestone = Moz::Milestone::getOfficialMilestone($MILESTONE_FILE);
  172. }
  173. $mfversion = $mpversion = $milestone;
  174. if ($appversion eq "") {
  175. $appversion = $milestone;
  176. }
  177. if ($debug eq "1")
  178. {
  179. push @fileflags, "VS_FF_DEBUG";
  180. $mpversion .= " Debug";
  181. $mfversion .= " Debug";
  182. }
  183. if ($official ne "1") {
  184. push @fileflags, "VS_FF_PRIVATEBUILD";
  185. }
  186. if ($milestone =~ /[a-z]/) {
  187. push @fileflags, "VS_FF_PRERELEASE";
  188. }
  189. my @mstone = split(/\./,$milestone);
  190. $mstone[1] =~s/\D.*$//;
  191. if (!$mstone[2]) {
  192. $mstone[2] = "0";
  193. }
  194. else {
  195. $mstone[2] =~s/\D.*$//;
  196. }
  197. $fileversion = $productversion="$mstone[0],$mstone[1],$mstone[2],$daycount";
  198. my @appver = split(/\./,$appversion);
  199. for ($j = 1; $j < 4; $j++)
  200. {
  201. if (!$appver[$j]) {
  202. $appver[$j] = "0";
  203. }
  204. else {
  205. $appver[$j] =~s/\D.*$//;
  206. }
  207. }
  208. my $winappversion = "$appver[0],$appver[1],$appver[2],$appver[3]";
  209. my $copyright = "License: MPL 2.0";
  210. my $company = "Moonchild Productions";
  211. my $trademarks = "Moonchild";
  212. my $productname = "UXP";
  213. if (defined($override_comment)){$override_comment =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $comment=$override_comment;}
  214. if (defined($override_description)){$override_description =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $description=$override_description;}
  215. if (defined($override_fileversion)){$override_fileversion =~ s/\@MOZ_APP_WINVERSION\@/$winappversion/g; $fileversion=$override_fileversion;}
  216. if (defined($override_mfversion)){$override_mfversion =~ s/\@MOZ_APP_VERSION\@/$appversion/g; $mfversion=$override_mfversion;}
  217. if (defined($override_company)){$company=$override_company;}
  218. if (defined($override_module)){$override_module =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $module=$override_module;}
  219. if (defined($override_copyright)){$override_copyright =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $copyright=$override_copyright;}
  220. if (defined($override_trademarks)){$override_trademarks =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $trademarks=$override_trademarks;}
  221. if (defined($override_filename)){$binary=$override_filename;}
  222. if (defined($override_productname)){$override_productname =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $productname=$override_productname;}
  223. if (defined($override_productversion)){$override_productversion =~ s/\@MOZ_APP_WINVERSION\@/$winappversion/g; $productversion=$override_productversion;}
  224. if (defined($override_mpversion)){$override_mpversion =~ s/\@MOZ_APP_VERSION\@/$appversion/g; $mpversion=$override_mpversion;}
  225. #Override section
  226. open(RCFILE, ">$objdir/module.rc") || die("Can't edit module.rc - It must be locked.\n");
  227. print RCFILE qq{
  228. // This Source Code Form is subject to the terms of the Mozilla Public
  229. // License, v. 2.0. If a copy of the MPL was not distributed with this
  230. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  231. #include<winver.h>
  232. // Note: if you contain versioning information in an included
  233. // RC script, it will be discarded
  234. // Use module.ver to explicitly set these values
  235. // Do not edit this file. Changes won't affect the build.
  236. };
  237. my $versionlevel=0;
  238. my $insideversion=0;
  239. if (open(RCINCLUDE, "<$rcinclude"))
  240. {
  241. print RCFILE "// From included resource $rcinclude\n";
  242. # my $mstring="";
  243. while (<RCINCLUDE>)
  244. {
  245. $_ =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g;
  246. print RCFILE $_;
  247. # my $instr=$_;
  248. # chomp($instr);
  249. # $mstring .= "$instr\;";
  250. }
  251. close(RCINCLUDE);
  252. # $mstring =~ s/\/\*.*\*\///g;
  253. # my @mlines = split(/\;/,$mstring);
  254. # for(@mlines)
  255. # {
  256. # my ($nocomment)=split(/\/\//,$_);
  257. # if (defined($nocomment) && $nocomment ne "")
  258. # {
  259. # my ($firststring,$secondstring) = split(/\s+/,$nocomment);
  260. # if (!defined($firststring)) {$firststring="";}
  261. # if (!defined($secondstring)) {$secondstring="";}
  262. # if ($secondstring eq "VERSIONINFO")
  263. # {
  264. #if (!$quiet || $quiet ne "1") {
  265. # print "$bufferstr" . "WARNING: Included RC file ($rcinclude, $module, $binary)\n";
  266. # print "$bufferstr" . "WARNING: contains versioning information that will be discarded\n";
  267. # print "$bufferstr" . "WARNING: Remove it and use relevant overrides (in module.ver)\n";
  268. #}
  269. # $versionlevel = 0;
  270. # $insideversion = 1;
  271. # }
  272. # if ($firststring eq "BEGIN") { $versionlevel++; }
  273. # if ($secondstring eq "END")
  274. # {
  275. # $versionlevel--;
  276. # if ($insideversion==1 && $versionlevel==0) {$versionlevel=0;}
  277. # }
  278. # my $includecheck = $firststring . $secondstring;
  279. # $includecheck =~ s/<|>/"/g;
  280. # $includecheck = lc($includecheck);
  281. # if ($includecheck ne "#include\"winver.h\"")
  282. # {
  283. # if ($insideversion == 0 && $versionlevel == 0)
  284. # {
  285. # print RCFILE "$nocomment\n";
  286. # }
  287. # }
  288. # }
  289. # }
  290. }
  291. my $fileflags = join(' | ', @fileflags);
  292. print RCFILE qq{
  293. /////////////////////////////////////////////////////////////////////////////
  294. //
  295. // Version
  296. //
  297. 1 VERSIONINFO
  298. FILEVERSION $fileversion
  299. PRODUCTVERSION $productversion
  300. FILEFLAGSMASK 0x3fL
  301. FILEFLAGS $fileflags
  302. FILEOS VOS__WINDOWS32
  303. FILETYPE VFT_DLL
  304. FILESUBTYPE 0x0L
  305. BEGIN
  306. BLOCK "StringFileInfo"
  307. BEGIN
  308. BLOCK "000004b0"
  309. BEGIN
  310. VALUE "Comments", "$comment"
  311. VALUE "LegalCopyright", "$copyright"
  312. VALUE "CompanyName", "$company"
  313. VALUE "FileDescription", "$description"
  314. VALUE "FileVersion", "$mfversion"
  315. VALUE "ProductVersion", "$mpversion"
  316. VALUE "InternalName", "$module"
  317. VALUE "LegalTrademarks", "$trademarks"
  318. VALUE "OriginalFilename", "$binary"
  319. VALUE "ProductName", "$productname"
  320. VALUE "BuildID", "$buildid"
  321. END
  322. END
  323. BLOCK "VarFileInfo"
  324. BEGIN
  325. VALUE "Translation", 0x0, 1200
  326. END
  327. END
  328. };
  329. close(RCFILE);