5 version.pl - Parse the NASM version file and produce appropriate macros
9 version.pl $format < $filename
11 echo 2.06rc10 | version.pl $format
13 version.pl $format $filename
15 Where $format is one of:
17 h mac sed make nsis id xid perl yaml json
21 The NASM version number is assumed to consist of:
23 E<lt>majorE<gt>.E<lt>minorE<gt>[.E<lt>subminorE<gt>][
24 plE<lt>patchlevelE<gt> |
28 ... where E<lt>tailE<gt> is not necessarily numeric, but if it is of the form
29 -E<lt>digitsE<gt> it is assumed to be a snapshot release.
48 # forward definition of subroutines
62 # jump table to subroutines / variables
85 Pod
::Usage
::pod2usage
(
86 "run perldoc $0 or pod2text $0 for more information"
93 use Scalar
::Util
'reftype';
95 my($cmd, $filename) = @ARGV;
98 not $cmd or $cmd =~ m
{
106 # in this case $filename is actually output format
107 # we want to know more about
108 $jump{help
}->($filename);
111 }elsif($cmd eq 'usage'){
115 my $jump = $jump{$cmd};
117 $jump{usage
}->(cmd
=>$cmd);
120 my $version = Load
($filename);
123 my $reftype = reftype
$jump;
125 if($reftype eq 'CODE'){
126 my $ret = $jump->($version);
127 print "$ret\n" if defined $ret;
130 # an un-used reference type
134 print $version->{$jump}, "\n";
144 # only really required for this first match
145 # could probably rewrite the match for earlier Perls
149 if($filename and $filename ne '-'){
150 open my $file, '<', $filename or die;
158 die unless length $line;
159 $version{_line
} = $line;
162 (?
<major
>\d
+)[.](?
<minor
>\d
+)
163 (?
:[.](?
<subminor
>\d
+))?
165 pl
(?
<patchlevel
>\d
+) |
169 [-](?
<snapshot
>\d
+) |
175 for my $key(qw
'major minor subminor patchlevel rc'){
176 my $value = $+{$key} || 0;
178 # removes any leading zeros by forcing to a number
179 $version{$key} = $value + 0;
181 for my $key(qw
'snapshot tail'){
183 $version{$key} = $+{$key};
191 # modify %version if this is a release candidate
193 $version{patchlevel
} = $version{rc
} + 90;
195 if($version{subminor
}){
196 $version{subminor
}--;
198 $version{subminor
} = 99;
203 $version{minor
} = 99;
211 # add 'id' and 'xid' to %version
213 ($version{major
} << 24) +
214 ($version{minor
} << 16) +
215 ($version{subminor
} << 8) +
216 $version{patchlevel
};
217 $version{xid
} = sprintf('0x%08x',$version{id
});
221 # add 'mangled' to %version
223 my $mangled = sprintf("%d.%02d",$version{major
},$version{minor
});
225 $version{subminor
} or
226 $version{patchlevel
} or
229 $mangled .= sprintf(".%02d",$version{subminor
});
232 $version{patchlevel
} or
235 $mangled .= sprintf(".%01d",$version{patchlevel
})
239 if($version{snapshot
}){
240 $mangled .= '.'.$version{snapshot
}
241 }elsif( $version{tail
}){
242 my $tail = $version{tail
};
247 $version{mangled
} = $mangled;
250 return %version if wantarray;
255 =head2 perl - returns a dump of internally used data
261 'mangled' => '2.05.99.100',
264 'xid' => '0x02056364',
272 no warnings qw
'once';
273 require Data
::Dumper
;
274 local $Data::Dumper
::Terse
= 1;
275 local $Data::Dumper
::Indent
= 1;
279 # remove any "hidden" keys
280 delete $ret{$_} if /^[_.]/;
282 return Data
::Dumper
::Dumper
(\
%ret);
285 =head2 yaml - returns the same thing as perl, but in YAML format
306 # remove any "hidden" keys
307 delete $ret{$_} if /^[_.]/;
312 =head2 json - returns the same thing as perl, but in JSON format
318 "mangled" : "2.05.99.100",
321 "xid" : "0x02056364",
336 # remove any "hidden" keys
337 delete $ret{$_} if /^[_.]/;
339 return $json->pretty->encode(\
%ret);
345 #ifndef NASM_VERSION_H
346 #define NASM_VERSION_H
347 #define NASM_MAJOR_VER $major
348 #define NASM_MINOR_VER $minor
349 #define NASM_SUBMINOR_VER {$subminor || 0}
350 #define NASM_PATCHLEVEL_VER {$patchlevel || 0}
351 #define NASM_SNAPSHOT $snapshot -- if snapshot
352 #define NASM_VERSION_ID $hex_id
353 #define NASM_VER "$ver"
354 #endif /* NASM_VERSION_H */
361 #NASM_SUBMINOR_VER -- this is zero if no subminor
362 #NASM_PATCHLEVEL_VER -- this is zero is no patchlevel
363 #NASM_SNAPSHOT -- if snapshot
364 #NASM_VERSION_ID -- version number encoded
365 #NASM_VER -- whole version number as a string
371 printf <<END, @$version{'major','minor','subminor','patchlevel'};
372 #ifndef NASM_VERSION_H
373 #define NASM_VERSION_H
374 #define NASM_MAJOR_VER %d
375 #define NASM_MINOR_VER %d
376 #define NASM_SUBMINOR_VER %d
377 #define NASM_PATCHLEVEL_VER %d
380 if ($version->{snapshot
}) {
381 printf "#define NASM_SNAPSHOT %d\n", $version->{snapshot
};
384 printf <<END, @$version{'xid','_line'};
385 #define NASM_VERSION_ID %s
386 #define NASM_VER "%s"
387 #endif /* NASM_VERSION_H */
396 __NASM_MAJOR__ $major
397 __NASM_MINOR__ $minor
398 __NASM_SUBMINOR__ $subminor
399 __NASM_PATCHLEVEL__ $patchlevel
400 __NASM_SNAPSHOT__ $snapshot -- if snapshot
401 __NASM_VERSION_ID__ $hex_id
408 printf <<'END', @$version{'major','minor','subminor','patchlevel'};
409 %%define __NASM_MAJOR__ %d
410 %%define __NASM_MINOR__ %d
411 %%define __NASM_SUBMINOR__ %d
412 %%define __NASM_PATCHLEVEL__ %d
415 if ($version->{snapshot
}) {
416 printf "%%define __NASM_SNAPSHOT__ %d\n", $version->{snapshot
};
419 printf <<'END', @$version{'id','_line'};
420 %%define __NASM_VERSION_ID__ 0%08Xh
421 %%define __NASM_VER__ "%s"
430 s/@@NASM_MAJOR@@/$major/g
431 s/@@NASM_MINOR@@/$minor/g
432 s/@@NASM_SUBMINOR@@/$sub_minor/g
433 s/@@NASM_PATCHLEVEL@@/$patchlevel/g
434 s/@@NASM_SNAPSHOT@@/$snapshot/g
435 s/@@NASM_VERSION_ID@@/$id/g
436 s/@@NASM_VERSION_XID@@/$hex_id/g
437 s/@@NASM_VER@@/$ver/g
438 s/@@NASM_MANGLED_VER@@/$mangled/g
444 my @rep = @
$version{qw{
455 no warnings
'uninitialized';
456 sprintf <<'END', @rep;
457 s/@@NASM_MAJOR@@/%d/g
458 s/@@NASM_MINOR@@/%d/g
459 s/@@NASM_SUBMINOR@@/%d/g
460 s/@@NASM_PATCHLEVEL@@/%d/g
461 s/@@NASM_SNAPSHOT@@/%d/g
462 s/@@NASM_VERSION_ID@@/%d/g
463 s/@@NASM_VERSION_XID@@/%s/g
465 s/@@NASM_MANGLED_VER@@/%s/g
474 NASM_MAJOR_VER=$major
475 NASM_MINOR_VER=$minor
476 NASM_SUBMINOR_VER=$subminor
477 NASM_PATCHLEVEL_VER=$patchlevel
483 return sprintf <<END, @$version{'_line','major','minor','subminor','patchlevel'};
488 NASM_PATCHLEVEL_VER=%d
495 !define VERSION "$version"
496 !define MAJOR_VER $major
497 !define MINOR_VER $minor
498 !define SUBMINOR_VER $subminor
499 !define PATCHLEVEL_VER $patchlevel
505 return sprintf <<'END', @$version{'_line','major','minor','subminor','patchlevel'};
509 !define SUBMINOR_VER %d
510 !define PATCHLEVEL_VER %d
519 sed
=> 'strings for sed command',
520 mac
=> 'strings for nasm macros',
521 h
=> 'strings for headers',
522 make
=> 'strings for makefiles',
523 perl
=> 'dump of program data',
524 nsis
=> 'what is nsis?',
525 json
=> 'dump of program data in json format',
526 yaml
=> 'dump of program data in yaml format'
529 if( $cmd and $help{$cmd} ){
530 print $help{$cmd},"\n";
532 print "$0 [help]? [ ".join(' | ',keys %help)." ]\n";