version.pl 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #!/usr/bin/perl
  2. ## --------------------------------------------------------------------------
  3. ##
  4. ## Copyright 1996-2016 The NASM Authors - All Rights Reserved
  5. ## See the file AUTHORS included with the NASM distribution for
  6. ## the specific copyright holders.
  7. ##
  8. ## Redistribution and use in source and binary forms, with or without
  9. ## modification, are permitted provided that the following
  10. ## conditions are met:
  11. ##
  12. ## * Redistributions of source code must retain the above copyright
  13. ## notice, this list of conditions and the following disclaimer.
  14. ## * Redistributions in binary form must reproduce the above
  15. ## copyright notice, this list of conditions and the following
  16. ## disclaimer in the documentation and/or other materials provided
  17. ## with the distribution.
  18. ##
  19. ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  20. ## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  21. ## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. ## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27. ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  30. ## OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  31. ## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ##
  33. ## --------------------------------------------------------------------------
  34. #
  35. # version.pl
  36. #
  37. # Parse the NASM version file and produce appropriate macros
  38. #
  39. # The NASM version number is assumed to consist of:
  40. #
  41. # <major>.<minor>[.<subminor>][pl<patchlevel>]]<tail>
  42. #
  43. # ... where <tail> is not necessarily numeric, but if it is of the form
  44. # -<digits> it is assumed to be a snapshot release.
  45. #
  46. # This defines the following macros:
  47. #
  48. # version.h:
  49. # NASM_MAJOR_VER
  50. # NASM_MINOR_VER
  51. # NASM_SUBMINOR_VER -- this is zero if no subminor
  52. # NASM_PATCHLEVEL_VER -- this is zero is no patchlevel
  53. # NASM_SNAPSHOT -- if snapshot
  54. # NASM_VERSION_ID -- version number encoded
  55. # NASM_VER -- whole version number as a string
  56. #
  57. # version.mac:
  58. # __NASM_MAJOR__
  59. # __NASM_MINOR__
  60. # __NASM_SUBMINOR__
  61. # __NASM_PATCHLEVEL__
  62. # __NASM_SNAPSHOT__
  63. # __NASM_VERSION_ID__
  64. # __NASM_VER__
  65. #
  66. ($what) = @ARGV;
  67. $line = <STDIN>;
  68. chomp $line;
  69. undef $man, $min, $smin, $plvl, $tail;
  70. $is_rc = 0;
  71. if ( $line =~ /^([0-9]+)\.([0-9]+)(.*)$/ ) {
  72. $maj = $1;
  73. $min = $2;
  74. $tail = $3;
  75. if ( $tail =~ /^\.([0-9]+)(.*)$/ ) {
  76. $smin = $1;
  77. $tail = $2;
  78. }
  79. if ( $tail =~ /^(pl|\.)([0-9]+)(.*)$/ ) {
  80. $plvl = $2;
  81. $tail = $3;
  82. } elsif ( $tail =~ /^rc([0-9]+)(.*)$/ ) {
  83. $is_rc = 1;
  84. $plvl = $1;
  85. $tail = $2;
  86. }
  87. } else {
  88. die "$0: Invalid input format\n";
  89. }
  90. if ($tail =~ /^\-([0-9]+)$/) {
  91. $snapshot = $1;
  92. } else {
  93. undef $snapshot;
  94. }
  95. $nmaj = $maj+0; $nmin = $min+0;
  96. $nsmin = $smin+0; $nplvl = $plvl+0;
  97. if ($is_rc) {
  98. $nplvl += 90;
  99. if ($nsmin > 0) {
  100. $nsmin--;
  101. } else {
  102. $nsmin = 99;
  103. if ($nmin > 0) {
  104. $nmin--;
  105. } else {
  106. $nmin = 99;
  107. $nmaj--;
  108. }
  109. }
  110. }
  111. $nasm_id = ($nmaj << 24)+($nmin << 16)+($nsmin << 8)+$nplvl;
  112. $mangled_ver = sprintf("%d.%02d", $nmaj, $nmin);
  113. if ($nsmin || $nplvl || defined($snapshot)) {
  114. $mangled_ver .= sprintf(".%02d", $nsmin);
  115. if ($nplvl || defined($snapshot)) {
  116. $mangled_ver .= '.'.$nplvl;
  117. }
  118. }
  119. ($mtail = $tail) =~ tr/-/./;
  120. $mangled_ver .= $mtail;
  121. if ( $what eq 'h' ) {
  122. print "#ifndef NASM_VERSION_H\n";
  123. print "#define NASM_VERSION_H\n";
  124. printf "#define NASM_MAJOR_VER %d\n", $nmaj;
  125. printf "#define NASM_MINOR_VER %d\n", $nmin;
  126. printf "#define NASM_SUBMINOR_VER %d\n", $nsmin;
  127. printf "#define NASM_PATCHLEVEL_VER %d\n", $nplvl;
  128. if (defined($snapshot)) {
  129. printf "#define NASM_SNAPSHOT %d\n", $snapshot;
  130. }
  131. printf "#define NASM_VERSION_ID 0x%08x\n", $nasm_id;
  132. printf "#define NASM_VER \"%s\"\n", $line;
  133. print "#endif /* NASM_VERSION_H */\n";
  134. } elsif ( $what eq 'mac' ) {
  135. print "STD: version\n";
  136. printf "%%define __NASM_MAJOR__ %d\n", $nmaj;
  137. printf "%%define __NASM_MINOR__ %d\n", $nmin;
  138. printf "%%define __NASM_SUBMINOR__ %d\n", $nsmin;
  139. printf "%%define __NASM_PATCHLEVEL__ %d\n", $nplvl;
  140. if (defined($snapshot)) {
  141. printf "%%define __NASM_SNAPSHOT__ %d\n", $snapshot;
  142. }
  143. printf "%%define __NASM_VERSION_ID__ 0%08Xh\n", $nasm_id;
  144. printf "%%define __NASM_VER__ \"%s\"\n", $line;
  145. } elsif ( $what eq 'sed' ) {
  146. printf "s/\@\@NASM_MAJOR\@\@/%d/g\n", $nmaj;
  147. printf "s/\@\@NASM_MINOR\@\@/%d/g\n", $nmin;
  148. printf "s/\@\@NASM_SUBMINOR\@\@/%d/g\n", $nsmin;
  149. printf "s/\@\@NASM_PATCHLEVEL\@\@/%d/g\n", $nplvl;
  150. printf "s/\@\@NASM_SNAPSHOT\@\@/%d/g\n", $snapshot; # Possibly empty
  151. printf "s/\@\@NASM_VERSION_ID\@\@/%d/g\n", $nasm_id;
  152. printf "s/\@\@NASM_VERSION_XID\@\@/0x%08x/g\n", $nasm_id;
  153. printf "s/\@\@NASM_VER\@\@/%s/g\n", $line;
  154. printf "s/\@\@NASM_MANGLED_VER\@\@/%s/g\n", $mangled_ver;
  155. } elsif ( $what eq 'make' ) {
  156. printf "NASM_VER=%s\n", $line;
  157. printf "NASM_MAJOR_VER=%d\n", $nmaj;
  158. printf "NASM_MINOR_VER=%d\n", $nmin;
  159. printf "NASM_SUBMINOR_VER=%d\n", $nsmin;
  160. printf "NASM_PATCHLEVEL_VER=%d\n", $nplvl;
  161. } elsif ( $what eq 'nsis' ) {
  162. printf "!define VERSION \"%s\"\n", $line;
  163. printf "!define MAJOR_VER %d\n", $nmin;
  164. printf "!define MINOR_VER %d\n", $nmin;
  165. printf "!define SUBMINOR_VER %d\n", $nsmin;
  166. printf "!define PATCHLEVEL_VER %d\n", $nplvl;
  167. } elsif ( $what eq 'id' ) {
  168. print $nasm_id, "\n"; # Print ID in decimal
  169. } elsif ( $what eq 'xid' ) {
  170. printf "0x%08x\n", $nasm_id; # Print ID in hexadecimal
  171. } elsif ( $what eq 'docsrc' ) {
  172. printf "\\M{version}{%s}\n", $line;
  173. printf "\\M{subtitle}{version %s}\n", $line;
  174. } else {
  175. die "$0: Unknown output: $what\n";
  176. }
  177. exit 0;