buildnum.pl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/perl
  2. # --- BEGIN COPYRIGHT BLOCK ---
  3. # Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  4. # Copyright (C) 2005 Red Hat, Inc.
  5. # All rights reserved.
  6. #
  7. # License: GPL (version 3 or any later version).
  8. # See LICENSE for details.
  9. # --- END COPYRIGHT BLOCK ---
  10. #--------------------------------------------
  11. # buildnum.pl
  12. #
  13. # Generates a dated build number and writes
  14. # out a buildnum.dat file in a user specified
  15. # subdirectory.
  16. #
  17. # Usage: buildnum.pl -p <platform dir>
  18. #--------------------------------------------
  19. use Getopt::Std;
  20. use FileHandle;
  21. autoflush STDERR 1;
  22. getopts('p:H');
  23. if ($opt_H) {exitHelp();}
  24. # Load arguments
  25. $platdir = $opt_p;
  26. # Get current time
  27. @now = gmtime;
  28. # Format buildnum as YYYY.DDD.HHMM
  29. $year = $now[5] + 1900;
  30. $doy = $now[7] + 1;
  31. if ($doy < 100) { $doy = 0 . $doy; }
  32. $tod = $now[2] . $now[1];
  33. $buildnum = "$year.$doy.$tod";
  34. if ($platdir) {
  35. # Write buildnum.dat
  36. $buildnum_file = "./$platdir/buildnum.dat";
  37. open(BUILDNUM,">$buildnum_file") || die "Error: Can't create $buildnum_file: $!\n";
  38. print BUILDNUM "\\\"$buildnum\\\"";
  39. close(BUILDNUM);
  40. } else {
  41. print "\\\"$buildnum\\\"";
  42. }
  43. #---------- exitHelp subroutine ----------
  44. sub exitHelp {
  45. print(STDERR "$0: Generates a dated build number.
  46. \tUsage: $0 -p <platform>
  47. \t-p <platform> Platform subdirectory.
  48. \t-H Print this help message\n");
  49. exit(0);
  50. }