michael@0: #!/usr/bin/perl -w michael@0: michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: #use diagnostics; michael@0: require strict; michael@0: my $dir = $0; michael@0: $dir =~ s/[^\/]*$//; michael@0: push(@INC, "$dir"); michael@0: require "Moz/Milestone.pm"; michael@0: use Getopt::Long; michael@0: use Getopt::Std; michael@0: use POSIX; michael@0: michael@0: # Calculate the number of days since Jan. 1, 2000 from a buildid string michael@0: sub daysFromBuildID michael@0: { michael@0: my ($buildid,) = @_; michael@0: michael@0: my ($y, $m, $d, $h) = ($buildid =~ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/); michael@0: $d || die("Unrecognized buildid string."); michael@0: michael@0: my $secondstodays = 60 * 60 * 24; michael@0: return sprintf("%d", michael@0: (POSIX::mktime(00, 00, 00, $d, $m - 1, $y - 1900) - michael@0: POSIX::mktime(00, 00, 00, 01, 00, 100)) / $secondstodays); michael@0: } michael@0: michael@0: #Creates version resource file michael@0: michael@0: #Paramaters are passed on the command line: michael@0: michael@0: #Example: -MODNAME nsToolkitCompsModule -DEBUG=1 michael@0: michael@0: # DEBUG - Mozilla's global debug variable - tells if its debug version michael@0: # OFFICIAL - tells Mozilla is building a milestone or nightly michael@0: # MSTONE - tells which milestone is being built; michael@0: # OBJDIR - Holds the object directory; michael@0: # MODNAME - tells what the name of the module is like nsBMPModule michael@0: # DEPTH - Holds the path to the root obj dir michael@0: # TOPSRCDIR - Holds the path to the root mozilla dir michael@0: # SRCDIR - Holds module.ver and source michael@0: # BINARY - Holds the name of the binary file michael@0: # DISPNAME - Holds the display name of the built application michael@0: # APPVERSION - Holds the version string of the built application michael@0: # RCINCLUDE - Holds the name of the RC File to include or "" michael@0: # QUIET - Turns off output michael@0: michael@0: #Description and Comment come from module.ver michael@0: #Bug 23560 michael@0: #http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/rc_7x2d.asp michael@0: michael@0: #Get next .ver file entry michael@0: sub getNextEntry michael@0: { michael@0: while () michael@0: { michael@0: my $mline = $_; michael@0: ($mline) = split(/#/,$mline); michael@0: my ($entry, $value)=split(/=/,$mline,2); michael@0: if (defined($entry)) michael@0: { michael@0: if (defined($value)) michael@0: { michael@0: $entry =~ s/^\s*(.*?)\s*$/$1/; michael@0: $value =~ s/^\s*(.*?)\s*$/$1/; michael@0: return ($entry,$value); michael@0: } michael@0: } michael@0: } michael@0: return undef; michael@0: } michael@0: michael@0: my ($quiet,$objdir,$debug,$official,$milestone,$buildid,$module,$binary,$depth,$rcinclude,$srcdir,$fileversion,$productversion); michael@0: michael@0: GetOptions( "QUIET" => \$quiet, michael@0: "DEBUG=s" => \$debug, michael@0: "OFFICIAL=s" => \$official, michael@0: "MSTONE=s" => \$milestone, michael@0: "MODNAME=s" => \$module, michael@0: "BINARY=s" => \$binary, michael@0: "DISPNAME=s" => \$displayname, michael@0: "APPVERSION=s" => \$appversion, michael@0: "SRCDIR=s" => \$srcdir, michael@0: "TOPSRCDIR=s" => \$topsrcdir, michael@0: "DEPTH=s" => \$depth, michael@0: "RCINCLUDE=s" => \$rcinclude, michael@0: "OBJDIR=s" => \$objdir); michael@0: if (!defined($debug)) {$debug="";} michael@0: if (!defined($official)) {$official="";} michael@0: if (!defined($milestone)) {$milestone="";} michael@0: if (!defined($module)) {$module="";} michael@0: if (!defined($binary)) {$binary="";} michael@0: if (!defined($displayname)) {$displayname="Mozilla";} michael@0: if (!defined($appversion)) {$appversion=$milestone;} michael@0: if (!defined($depth)) {$depth=".";} michael@0: if (!defined($rcinclude)) {$rcinclude="";} michael@0: if (!defined($objdir)) {$objdir=".";} michael@0: if (!defined($srcdir)) {$srcdir=".";} michael@0: if (!defined($topsrcdir)) {$topsrcdir=".";} michael@0: my $mfversion = "Personal"; michael@0: my $mpversion = "Personal"; michael@0: my @fileflags = ("0"); michael@0: my $comment=""; michael@0: my $description=""; michael@0: if (!defined($module)) michael@0: { michael@0: $module = $binary; michael@0: ($module) = split(/\./,$module); michael@0: } michael@0: michael@0: my $bufferstr=" "; michael@0: michael@0: my $MILESTONE_FILE = "$topsrcdir/config/milestone.txt"; michael@0: my $BUILDID_FILE = "$depth/config/buildid"; michael@0: michael@0: #Read module.ver file michael@0: #Version file overrides for WIN32: michael@0: #WIN32_MODULE_COMMENT michael@0: #WIN32_MODULE_DESCRIPTION michael@0: #WIN32_MODULE_FILEVERSION michael@0: #WIN32_MODULE_COMPANYNAME michael@0: #WIN32_MODULE_FILEVERSION_STRING michael@0: #WIN32_MODULE_NAME michael@0: #WIN32_MODULE_COPYRIGHT michael@0: #WIN32_MODULE_TRADEMARKS michael@0: #WIN32_MODULE_ORIGINAL_FILENAME michael@0: #WIN32_MODULE_PRODUCTNAME michael@0: #WIN32_MODULE_PRODUCTVERSION michael@0: #WIN32_MODULE_PRODUCTVERSION_STRING michael@0: michael@0: #Override values obtained from the .ver file michael@0: my $override_comment; michael@0: my $override_description; michael@0: my $override_fileversion; michael@0: my $override_company; michael@0: my $override_mfversion; michael@0: my $override_module; michael@0: my $override_copyright; michael@0: my $override_trademarks; michael@0: my $override_filename; michael@0: my $override_productname; michael@0: my $override_productversion; michael@0: my $override_mpversion; michael@0: if (open(VERFILE, "<$srcdir/module.ver")) michael@0: { michael@0: michael@0: my ($a,$b) = getNextEntry(); michael@0: while (defined($a)) michael@0: { michael@0: if ($a eq "WIN32_MODULE_COMMENT") { $override_comment = $b; } michael@0: if ($a eq "WIN32_MODULE_DESCRIPTION") { $override_description = $b; } michael@0: if ($a eq "WIN32_MODULE_FILEVERSION") { $override_fileversion = $b; } michael@0: if ($a eq "WIN32_MODULE_COMPANYNAME") { $override_company = $b; } michael@0: if ($a eq "WIN32_MODULE_FILEVERSION_STRING") { $override_mfversion = $b; } michael@0: if ($a eq "WIN32_MODULE_NAME") { $override_module = $b; } michael@0: if ($a eq "WIN32_MODULE_COPYRIGHT") { $override_copyright = $b; } michael@0: if ($a eq "WIN32_MODULE_TRADEMARKS") { $override_trademarks = $b; } michael@0: if ($a eq "WIN32_MODULE_ORIGINAL_FILENAME") { $override_filename = $b; } michael@0: if ($a eq "WIN32_MODULE_PRODUCTNAME") { $override_productname = $b; } michael@0: if ($a eq "WIN32_MODULE_PRODUCTVERSION") { $override_productversion = $b; } michael@0: if ($a eq "WIN32_MODULE_PRODUCTVERSION_STRING") { $override_mpversion = $b; } michael@0: ($a,$b) = getNextEntry(); michael@0: } michael@0: close(VERFILE) michael@0: } michael@0: else michael@0: { michael@0: if (!$quiet || $quiet ne "1") { print "$bufferstr" . "WARNING: No module.ver file included ($module, $binary). Default values used\n"; } michael@0: } michael@0: #Get rid of trailing and leading whitespace michael@0: $debug =~ s/^\s*(.*)\s*$/$1/; michael@0: $comment =~ s/^\s*(.*)\s*$/$1/; michael@0: $official =~ s/^\s*(.*)\s*$/$1/; michael@0: $milestone =~ s/^\s*(.*)\s*$/$1/; michael@0: $description =~ s/^\s*(.*)\s*$/$1/; michael@0: $module =~ s/^\s*(.*)\s*$/$1/; michael@0: $depth =~ s/^\s*(.*)\s*$/$1/; michael@0: $binary =~ s/^\s*(.*)\s*$/$1/; michael@0: $displayname =~ s/^\s*(.*)\s*$/$1/; michael@0: michael@0: open(BUILDID, "<", $BUILDID_FILE) || die("Couldn't open buildid file: $BUILDID_FILE"); michael@0: $buildid = ; michael@0: $buildid =~ s/\s*$//; michael@0: close BUILDID; michael@0: michael@0: my $daycount = daysFromBuildID($buildid); michael@0: michael@0: if ($milestone eq "") { michael@0: $milestone = Moz::Milestone::getOfficialMilestone($MILESTONE_FILE); michael@0: } michael@0: michael@0: $mfversion = $mpversion = $milestone; michael@0: if ($appversion eq "") { michael@0: $appversion = $milestone; michael@0: } michael@0: michael@0: if ($debug eq "1") michael@0: { michael@0: push @fileflags, "VS_FF_DEBUG"; michael@0: $mpversion .= " Debug"; michael@0: $mfversion .= " Debug"; michael@0: } michael@0: michael@0: if ($official ne "1") { michael@0: push @fileflags, "VS_FF_PRIVATEBUILD"; michael@0: } michael@0: michael@0: if ($milestone =~ /[a-z]/) { michael@0: push @fileflags, "VS_FF_PRERELEASE"; michael@0: } michael@0: michael@0: my @mstone = split(/\./,$milestone); michael@0: $mstone[1] =~s/\D.*$//; michael@0: if (!$mstone[2]) { michael@0: $mstone[2] = "0"; michael@0: } michael@0: else { michael@0: $mstone[2] =~s/\D.*$//; michael@0: } michael@0: $fileversion = $productversion="$mstone[0],$mstone[1],$mstone[2],$daycount"; michael@0: michael@0: my @appver = split(/\./,$appversion); michael@0: for ($j = 1; $j < 4; $j++) michael@0: { michael@0: if (!$appver[$j]) { michael@0: $appver[$j] = "0"; michael@0: } michael@0: else { michael@0: $appver[$j] =~s/\D.*$//; michael@0: } michael@0: } michael@0: my $winappversion = "$appver[0],$appver[1],$appver[2],$appver[3]"; michael@0: michael@0: my $copyright = "License: MPL 2"; michael@0: my $company = "Mozilla Foundation"; michael@0: my $trademarks = "Mozilla"; michael@0: my $productname = $displayname; michael@0: michael@0: michael@0: if (defined($override_comment)){$override_comment =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $comment=$override_comment;} michael@0: if (defined($override_description)){$override_description =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $description=$override_description;} michael@0: if (defined($override_fileversion)){$override_fileversion =~ s/\@MOZ_APP_WINVERSION\@/$winappversion/g; $fileversion=$override_fileversion;} michael@0: if (defined($override_mfversion)){$override_mfversion =~ s/\@MOZ_APP_VERSION\@/$appversion/g; $mfversion=$override_mfversion;} michael@0: if (defined($override_company)){$company=$override_company;} michael@0: if (defined($override_module)){$override_module =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $module=$override_module;} michael@0: if (defined($override_copyright)){$override_copyright =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $copyright=$override_copyright;} michael@0: if (defined($override_trademarks)){$override_trademarks =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $trademarks=$override_trademarks;} michael@0: if (defined($override_filename)){$binary=$override_filename;} michael@0: if (defined($override_productname)){$override_productname =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $productname=$override_productname;} michael@0: if (defined($override_productversion)){$override_productversion =~ s/\@MOZ_APP_WINVERSION\@/$winappversion/g; $productversion=$override_productversion;} michael@0: if (defined($override_mpversion)){$override_mpversion =~ s/\@MOZ_APP_VERSION\@/$appversion/g; $mpversion=$override_mpversion;} michael@0: michael@0: michael@0: #Override section michael@0: michael@0: open(RCFILE, ">$objdir/module.rc") || die("Can't edit module.rc - It must be locked.\n"); michael@0: print RCFILE qq{ michael@0: // This Source Code Form is subject to the terms of the Mozilla Public michael@0: // License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: // file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: #include michael@0: michael@0: // Note: if you contain versioning information in an included michael@0: // RC script, it will be discarded michael@0: // Use module.ver to explicitly set these values michael@0: michael@0: // Do not edit this file. Changes won't affect the build. michael@0: michael@0: }; michael@0: michael@0: my $versionlevel=0; michael@0: my $insideversion=0; michael@0: if (open(RCINCLUDE, "<$rcinclude")) michael@0: { michael@0: print RCFILE "// From included resource $rcinclude\n"; michael@0: # my $mstring=""; michael@0: while () michael@0: { michael@0: $_ =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; michael@0: print RCFILE $_; michael@0: # my $instr=$_; michael@0: # chomp($instr); michael@0: # $mstring .= "$instr\;"; michael@0: } michael@0: close(RCINCLUDE); michael@0: # $mstring =~ s/\/\*.*\*\///g; michael@0: # my @mlines = split(/\;/,$mstring); michael@0: # for(@mlines) michael@0: # { michael@0: # my ($nocomment)=split(/\/\//,$_); michael@0: # if (defined($nocomment) && $nocomment ne "") michael@0: # { michael@0: # my ($firststring,$secondstring) = split(/\s+/,$nocomment); michael@0: # if (!defined($firststring)) {$firststring="";} michael@0: # if (!defined($secondstring)) {$secondstring="";} michael@0: # if ($secondstring eq "VERSIONINFO") michael@0: # { michael@0: #if (!$quiet || $quiet ne "1") { michael@0: # print "$bufferstr" . "WARNING: Included RC file ($rcinclude, $module, $binary)\n"; michael@0: # print "$bufferstr" . "WARNING: contains versioning information that will be discarded\n"; michael@0: # print "$bufferstr" . "WARNING: Remove it and use relevant overrides (in module.ver)\n"; michael@0: #} michael@0: # $versionlevel = 0; michael@0: # $insideversion = 1; michael@0: # } michael@0: # if ($firststring eq "BEGIN") { $versionlevel++; } michael@0: # if ($secondstring eq "END") michael@0: # { michael@0: # $versionlevel--; michael@0: # if ($insideversion==1 && $versionlevel==0) {$versionlevel=0;} michael@0: # } michael@0: # my $includecheck = $firststring . $secondstring; michael@0: # $includecheck =~ s/<|>/"/g; michael@0: # $includecheck = lc($includecheck); michael@0: # if ($includecheck ne "#include\"winver.h\"") michael@0: # { michael@0: # if ($insideversion == 0 && $versionlevel == 0) michael@0: # { michael@0: # print RCFILE "$nocomment\n"; michael@0: # } michael@0: # } michael@0: # } michael@0: # } michael@0: michael@0: } michael@0: michael@0: my $fileflags = join(' | ', @fileflags); michael@0: michael@0: print RCFILE qq{ michael@0: michael@0: michael@0: ///////////////////////////////////////////////////////////////////////////// michael@0: // michael@0: // Version michael@0: // michael@0: michael@0: 1 VERSIONINFO michael@0: FILEVERSION $fileversion michael@0: PRODUCTVERSION $productversion michael@0: FILEFLAGSMASK 0x3fL michael@0: FILEFLAGS $fileflags michael@0: FILEOS VOS__WINDOWS32 michael@0: FILETYPE VFT_DLL michael@0: FILESUBTYPE 0x0L michael@0: BEGIN michael@0: BLOCK "StringFileInfo" michael@0: BEGIN michael@0: BLOCK "000004b0" michael@0: BEGIN michael@0: VALUE "Comments", "$comment" michael@0: VALUE "LegalCopyright", "$copyright" michael@0: VALUE "CompanyName", "$company" michael@0: VALUE "FileDescription", "$description" michael@0: VALUE "FileVersion", "$mfversion" michael@0: VALUE "ProductVersion", "$mpversion" michael@0: VALUE "InternalName", "$module" michael@0: VALUE "LegalTrademarks", "$trademarks" michael@0: VALUE "OriginalFilename", "$binary" michael@0: VALUE "ProductName", "$productname" michael@0: VALUE "BuildID", "$buildid" michael@0: END michael@0: END michael@0: BLOCK "VarFileInfo" michael@0: BEGIN michael@0: VALUE "Translation", 0x0, 1200 michael@0: END michael@0: END michael@0: michael@0: }; michael@0: close(RCFILE);