dirver.pl 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/usr/bin/perl
  2. # --- BEGIN COPYRIGHT BLOCK ---
  3. # This Program is free software; you can redistribute it and/or modify it under
  4. # the terms of the GNU General Public License as published by the Free Software
  5. # Foundation; version 2 of the License.
  6. #
  7. # This Program is distributed in the hope that it will be useful, but WITHOUT
  8. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  10. #
  11. # You should have received a copy of the GNU General Public License along with
  12. # this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  13. # Place, Suite 330, Boston, MA 02111-1307 USA.
  14. #
  15. # In addition, as a special exception, Red Hat, Inc. gives You the additional
  16. # right to link the code of this Program with code not covered under the GNU
  17. # General Public License ("Non-GPL Code") and to distribute linked combinations
  18. # including the two, subject to the limitations in this paragraph. Non-GPL Code
  19. # permitted under this exception must only link to the code of this Program
  20. # through those well defined interfaces identified in the file named EXCEPTION
  21. # found in the source code files (the "Approved Interfaces"). The files of
  22. # Non-GPL Code may instantiate templates or use macros or inline functions from
  23. # the Approved Interfaces without causing the resulting work to be covered by
  24. # the GNU General Public License. Only Red Hat, Inc. may make changes or
  25. # additions to the list of Approved Interfaces. You must obey the GNU General
  26. # Public License in all respects for all of the Program code and other code used
  27. # in conjunction with the Program except the Non-GPL Code covered by this
  28. # exception. If you modify this file, you may extend this exception to your
  29. # version of the file, but you are not obligated to do so. If you do not wish to
  30. # provide this exception without modification, you must delete this exception
  31. # statement from your version and license this file solely under the GPL without
  32. # exception.
  33. #
  34. #
  35. # Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  36. # Copyright (C) 2005 Red Hat, Inc.
  37. # All rights reserved.
  38. # --- END COPYRIGHT BLOCK ---
  39. #-----------------------------------------------------------------
  40. # dirver.pl: Generates ascii format #define for FILEVERSION
  41. # resource identifier used by Windows executable binaries.
  42. #
  43. # Usage: dirver.pl -v <major.minor.patch> [-d mm/dd/yy] [-o outfile]
  44. # Example: dirver.pl -v 6.5.2 -d 1/19/2005 -o fileversion.h
  45. #
  46. # -v <major.minor.patch> Version number.
  47. # -d <mm/dd/yy> Date. (optional)
  48. # -o <outfile> Output header file. (optional)
  49. # -H Print this help message
  50. #-----------------------------------------------------------------
  51. use Getopt::Std;
  52. use FileHandle;
  53. autoflush STDERR 1;
  54. getopts('v:d:o:H');
  55. if ($opt_H) {exitHelp();}
  56. # Load arguments
  57. $version = $opt_v || exitHelp();
  58. $date = $opt_d;
  59. $outfile = $opt_o;
  60. # Separate version into components
  61. my @verComponents = split(/\./, $version);
  62. # Set version components to 0 if not defined
  63. if ($verComponents[1] == undef) { $verComponents[1] = "0"; }
  64. if ($verComponents[2] == undef) { $verComponents[2] = "0"; }
  65. # Calculate build version and build date
  66. my $buildVersion = calcVersion(@verComponents);
  67. my $buildDate = calcBuildDate($date);
  68. # Write #defines out to stdout or a file is requested
  69. if ($outfile) {
  70. open(OUTFILE,">$outfile") || die "Error: Can't create $outfile: $!";
  71. $outhdl = OUTFILE;
  72. } else {
  73. $outhdl = STDOUT;
  74. }
  75. print $outhdl "#define VI_PRODUCTVERSION $verComponents[0].$verComponents[1]\n";
  76. print $outhdl "#define PRODUCTTEXT \"$version\"\n";
  77. print $outhdl "#define VI_FILEVERSION $buildVersion, 0, 0, $buildDate\n";
  78. print $outhdl "#define VI_FileVersion \"$version Build $buildDate\\0\"\n";
  79. # Close file if not using STDOUT
  80. if ($outfile) {
  81. close(OUTFILE);
  82. }
  83. #---------- calcVersion subroutine ----------
  84. sub calcVersion {
  85. my @ver = shift;
  86. my $nVersion = 0;
  87. $nVersion = $ver[0];
  88. $nVersion <<= 5;
  89. $nVersion += $ver[1];
  90. $nVersion <<= 7;
  91. $nVersion += $ver[2];
  92. $nVersion &= 0xFFFF;
  93. return $nVersion;
  94. }
  95. #---------- calcBuildDate subroutine ----------
  96. sub calcBuildDate {
  97. my $date = shift;
  98. my @dateComponents = ();
  99. my $month, $date, $year;
  100. my $buildDate = "";
  101. # Use date if passed in, otherwise use system date
  102. if ($date) {
  103. # Separate date into month, day, and year
  104. @dateComponents = split(/\//, $date);
  105. # Use struct tm range for month
  106. $dateComponents[0]--;
  107. # Handle 2 digit years like (20)00
  108. if ($dateComponents[2] < 70) {
  109. $dateComponents[2] += 20;
  110. }
  111. $month = $dateComponents[0];
  112. $day = $dateComponents[1];
  113. $year = $dateComponents[2];
  114. } else {
  115. $month = (localtime)[4];
  116. $day = (localtime)[3];
  117. $year = (localtime)[5] - 80;
  118. }
  119. $buildDate = $year;
  120. $buildDate <<= 4;
  121. $buildDate += $month;
  122. $buildDate <<= 5;
  123. $buildDate += $day;
  124. $buildDate &= 0xFFFF;
  125. return $buildDate;
  126. }
  127. #---------- exitHelp subroutine ----------
  128. sub exitHelp {
  129. print(STDERR "$0: Generates ascii format #define for FILEVERSION
  130. \tresource identifier used by Windows executable binaries.
  131. \tUsage: $0 -v <major.minor.patch> [-d mm/dd/yy] [-o outfile]
  132. \tExample: $0 -v 6.5.2 -d 1/19/2005 -o fileversion.h
  133. \t-v <major.minor.patch> Version number.
  134. \t-d <mm/dd/yy> Date. \(optional\)
  135. \t-o <outfile> Output header file. \(optional\)
  136. \t-H Print this help message\n");
  137. exit(0);
  138. }