Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
4.2 KiB

  1. use strict;
  2. use IO::File;
  3. #
  4. # genbldno.pl
  5. #
  6. # Arguments: none
  7. #
  8. # Purpose: generate a file called __bldnum__ and binplace to the source tree.
  9. # the contents of this file will be a reference to the master build
  10. # build number as specified by %SDXROOT%\published\sdk\inc\ntverp.h
  11. # in the form "BUILDNUMBER=2257\n"
  12. #
  13. # Returns: 0 if success, non-zero otherwise
  14. #
  15. my( $BuildNumber, $QfeNumber );
  16. my( $BldnumFileName ) = $ENV{ "SDXROOT" } . "\\__bldnum__";
  17. my( $QfenumFileName ) = $ENV{ "SDXROOT" } . "\\__qfenum__";
  18. # use unless as GetBuildNumber returns zero on failure
  19. unless ( $BuildNumber = &GetBuildNumber ) {
  20. print( "Failed to generate build number, exiting ...\n" );
  21. exit( 1 );
  22. }
  23. # use if as GenerateBldnumFile returns zero for success
  24. if ( &GenerateNumFile( $BldnumFileName, $BuildNumber, "BUILDNUMBER" ) ) {
  25. print( "Failed to generate $BldnumFileName, exiting ...\n" );
  26. exit( 1 );
  27. }
  28. # use unless as GetQfeNumber returns zero on failure
  29. unless ( $QfeNumber = &GetQfeNumber ) {
  30. print( "Failed to generate qfe number, exiting ...\n" );
  31. exit( 1 );
  32. }
  33. # Generate the qfe number file from ntverp.h
  34. if ( &GenerateNumFile( $QfenumFileName, $QfeNumber, "QFEBUILDNUMBER" ) ) {
  35. print( "Failed to generate $QfenumFileName, exiting ...\n" );
  36. exit( 1 );
  37. }
  38. # if we're here, we returned successfully
  39. exit( 0 );
  40. #
  41. # GetBuildNumber
  42. #
  43. # Arguments: none
  44. #
  45. # Purpose: parse ntverp.h from published, return the build number
  46. #
  47. # Returns: the build number if successful, zero otherwise
  48. #
  49. sub GetBuildNumber
  50. {
  51. # find the file
  52. my( $VerFile ) = $ENV{ "SDXROOT" } . "\\published\\sdk\\inc\\ntverp.h";
  53. if ( ! -e $VerFile ) {
  54. print( "$VerFile does not exist ...\n" );
  55. return( 0 );
  56. }
  57. # parse the file
  58. if ( -e $VerFile ) {
  59. # open the file
  60. if ( defined( my $fh = new IO::File $VerFile, "r" ) ) {
  61. my( $ThisLine );
  62. # read through the file
  63. while ( $ThisLine = <$fh> ) {
  64. # see if this is the build number defining line
  65. if ( $ThisLine =~ /#define VER_PRODUCTBUILD\s*\/\* NT \*\/\s*(\d*)/ ) {
  66. # $1 is now the build number
  67. undef( $fh );
  68. return( $1 );
  69. }
  70. }
  71. undef( $fh );
  72. } else {
  73. print( "Failed to open $VerFile ...\n" );
  74. return( 0 );
  75. }
  76. }
  77. # if we're here, we didn't find a build number in the VerFile
  78. print( "Failed to find a build number in $VerFile ..." );
  79. return( 0 );
  80. }
  81. #
  82. # GetQfeNumber
  83. #
  84. # Arguments: none
  85. #
  86. # Purpose: parse ntverp.h from published, return the qfe number
  87. #
  88. # Returns: the qfe number if successful, zero otherwise
  89. #
  90. sub GetQfeNumber
  91. {
  92. # find the file
  93. my( $VerFile ) = $ENV{ "SDXROOT" } . "\\published\\sdk\\inc\\ntverp.h";
  94. if ( ! -e $VerFile ) {
  95. print( "$VerFile does not exist ...\n" );
  96. return( 0 );
  97. }
  98. # parse the file
  99. if ( -e $VerFile ) {
  100. # open the file
  101. if ( defined( my $fh = new IO::File $VerFile, "r" ) ) {
  102. my( $ThisLine );
  103. # read through the file
  104. while ( $ThisLine = <$fh> ) {
  105. # see if this is the qfe number defining line
  106. if ( $ThisLine =~ /#define VER_PRODUCTBUILD_QFE\s*(\d*)/ ) {
  107. # $1 is now the build number
  108. undef( $fh );
  109. return( $1 );
  110. }
  111. }
  112. undef( $fh );
  113. } else {
  114. print( "Failed to open $VerFile ...\n" );
  115. return( 0 );
  116. }
  117. }
  118. # if we're here, we didn't find a qfe number in the VerFile
  119. print( "Failed to find a qfe number in $VerFile ..." );
  120. return( 0 );
  121. }
  122. #
  123. # GenerateNumFile
  124. #
  125. # Arguments: $NumFileName, $Number, $NumberType
  126. #
  127. # Purpose: write the build number to the binplaced build number file, in
  128. # the following format: "$NumberType=2250"
  129. #
  130. # Returns: 0 if successful, non-zero otherwise
  131. #
  132. sub GenerateNumFile
  133. {
  134. # get passed args
  135. my( $NumFileName, $Number, $NumberType ) = @_;
  136. # open the file for write
  137. if ( defined( my $fh = new IO::File $NumFileName, "w" ) ) {
  138. print( $fh "$NumberType=$Number\n" );
  139. # success
  140. undef( $fh );
  141. return( 0 );
  142. }
  143. # if we're here, we didn't create the file
  144. print( "Failed to write $NumFileName ..." );
  145. return( 1 );
  146. }