Leaked source code of windows server 2003
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.

114 lines
2.8 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%\public\sdk\inc\ntverp.h
  11. # in the form "BUILDNUMBER=2257\n"
  12. #
  13. # Returns: 0 if success, non-zero otherwise
  14. #
  15. my( $BuildNumber );
  16. my( $BldnumFileName ) = $ENV{ "SDXROOT" } . "\\__bldnum__";
  17. # use unless as GetBuildNumber returns zero on failure
  18. unless ( $BuildNumber = &GetBuildNumber ) {
  19. print( "Failed to generate build number, exiting ...\n" );
  20. exit( 1 );
  21. }
  22. # use if as GenerateBldnumFile returns zero for success
  23. if ( &GenerateBldnumFile( $BldnumFileName, $BuildNumber ) ) {
  24. print( "Failed to generate $BldnumFileName, exiting ...\n" );
  25. exit( 1 );
  26. }
  27. # if we're here, we returned successfully
  28. exit( 0 );
  29. #
  30. # GetBuildNumber
  31. #
  32. # Arguments: none
  33. #
  34. # Purpose: parse ntverp.h from public, return the build number
  35. #
  36. # Returns: the build number if successful, zero otherwise
  37. #
  38. sub GetBuildNumber
  39. {
  40. # find the file
  41. my( $VerFile ) = $ENV{ "SDXROOT" } . "\\public\\sdk\\inc\\ntverp.h";
  42. if ( ! -e $VerFile ) {
  43. print( "$VerFile does not exist ...\n" );
  44. return( 0 );
  45. }
  46. # parse the file
  47. if ( -e $VerFile ) {
  48. # open the file
  49. if ( defined( my $fh = new IO::File $VerFile, "r" ) ) {
  50. my( $ThisLine );
  51. # read through the file
  52. while ( $ThisLine = <$fh> ) {
  53. # see if this is the build number defining line
  54. if ( $ThisLine =~ /#define VER_PRODUCTBUILD\s*\/\* NT \*\/\s*(\d*)/ ) {
  55. # $1 is now the build number
  56. undef( $fh );
  57. return( $1 );
  58. }
  59. }
  60. undef( $fh );
  61. } else {
  62. print( "Failed to open $VerFile ...\n" );
  63. return( 0 );
  64. }
  65. }
  66. # if we're here, we didn't find a build number in the VerFile
  67. print( "Failed to find a build number in $VerFile ..." );
  68. return( 0 );
  69. }
  70. #
  71. # GenerateBldnumFile
  72. #
  73. # Arguments: $BldnumFileName, $BuildNumber
  74. #
  75. # Purpose: write the build number to the binplaced build number file, in
  76. # the following format: "BUILDNUM=2250"
  77. #
  78. # Returns: 0 if successful, non-zero otherwise
  79. #
  80. sub GenerateBldnumFile
  81. {
  82. # get passed args
  83. my( $BldnumFileName, $BuildNumber ) = @_;
  84. # open the file for write
  85. if ( defined( my $fh = new IO::File $BldnumFileName, "w" ) ) {
  86. print( $fh "BUILDNUMBER=$BuildNumber\n" );
  87. # success
  88. undef( $fh );
  89. return( 0 );
  90. }
  91. # if we're here, we didn't create the file
  92. print( "Failed to write $BldnumFileName ..." );
  93. return( 1 );
  94. }