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 <major>.<minor>[.<subminor>][pl<patchlevel> | rc<number>]]<tail>
25 ... where <tail> is not necessarily numeric, but if it is of the form
26 -<digits> it is assumed to be a snapshot release.
45 return $version if $version;
48 # only really required for this first match
49 # could probably rewrite the match for earlier Perls
53 if($filename and $filename ne '-'){
54 open my $file, '<', $filename or die;
62 die unless length $line;
63 $version{_line
} = $line;
66 (?
<major
>\d
+)[.](?
<minor
>\d
+)
67 (?
:[.](?
<subminor
>\d
+))?
69 pl
(?
<patchlevel
>\d
+) |
79 for my $key(qw
'major minor subminor patchlevel rc'){
80 my $value = $+{$key} || 0;
82 # removes any leading zeros by forcing to a number
83 $version{$key} = $value + 0;
85 for my $key(qw
'snapshot tail'){
87 $version{$key} = $+{$key};
95 # modify %version if this is a release candidate
97 $version{patchlevel
} = $version{rc
} + 90;
99 if($version{subminor
}){
100 $version{subminor
}--;
102 $version{subminor
} = 99;
107 $version{minor
} = 99;
115 # add 'id' and 'xid' to %version
117 ($version{major
} << 24) +
118 ($version{minor
} << 16) +
119 ($version{subminor
} << 8) +
120 $version{patchlevel
};
121 $version{xid
} = sprintf('0x%08x',$version{id
});
125 # add 'mangled' to %version
127 my $mangled = sprintf("%d.%02d",$version{major
},$version{minor
});
129 $version{subminor
} or
130 $version{patchlevel
} or
133 $mangled .= sprintf(".%02d",$version{subminor
});
136 $version{patchlevel
} or
139 $mangled .= sprintf(".%01d",$version{patchlevel
})
143 if($version{snapshot
}){
144 $mangled .= '.'.$version{snapshot
}
145 }elsif( $version{tail
}){
146 my $tail = $version{tail
};
151 $version{mangled
} = $mangled;
154 $version = \
%version;
155 return %version if wantarray;
161 # forward definition of subroutines
173 # jump table to subroutines / variables
195 Pod
::Usage
::pod2usage
();
205 printf "0x%08x\n",$id
207 =item perl - returns a dump of internally used data
213 'mangled' => '2.05.99.100',
216 'xid' => '0x02056364',
224 no warnings qw
'once';
225 require Data
::Dumper
;
226 local $Data::Dumper
::Terse
= 1;
227 local $Data::Dumper
::Indent
= 1;
231 # remove any "hidden" keys
232 delete $ret{$_} if /^[_.]/;
234 return Data
::Dumper
::Dumper
(\
%ret);
237 =item yaml - returns the same thing as dump, but in YAML format
258 # remove any "hidden" keys
259 delete $ret{$_} if /^[_.]/;
264 =item json - returns the same thing as dump, but in JSON format
270 "mangled" : "2.05.99.100",
273 "xid" : "0x02056364",
288 # remove any "hidden" keys
289 delete $ret{$_} if /^[_.]/;
291 return $json->pretty->encode(\
%ret);
297 use Scalar
::Util
'reftype';
299 my($cmd, $filename) = @ARGV;
302 not $cmd or $cmd =~ /^ -h | (?:--)?help $/xi
304 # in this case $filename is actually output format
305 # we want to know more about
306 $jump{help
}->($filename);
309 }elsif($cmd eq 'usage'){
313 my $jump = $jump{$cmd};
315 $jump{usage
}->(cmd
=>$cmd);
318 my $version = Load
($filename);
321 my $reftype = reftype
$jump;
323 if($reftype eq 'CODE'){
324 my $ret = $jump->($version);
325 print "$ret\n" if defined $ret;
328 # an un-used reference type
332 print $version->{$jump}, "\n";
337 # subroutine definitions
344 NASM_SUBMINOR_VER -- this is zero if no subminor
345 NASM_PATCHLEVEL_VER -- this is zero is no patchlevel
346 NASM_SNAPSHOT -- if snapshot
347 NASM_VERSION_ID -- version number encoded
348 NASM_VER -- whole version number as a string
354 printf <<END, @$version{'major','minor','subminor','patchlevel'};
355 #ifndef NASM_VERSION_H
356 #define NASM_VERSION_H
357 #define NASM_MAJOR_VER %d
358 #define NASM_MINOR_VER %d
359 #define NASM_SUBMINOR_VER %d
360 #define NASM_PATCHLEVEL_VER %d
363 if ($version->{snapshot
}) {
364 printf "#define NASM_SNAPSHOT %d\n", $version->{snapshot
};
367 printf <<END, @$version{'xid','_line'};
368 #define NASM_VERSION_ID %s
369 #define NASM_VER "%s"
370 #endif /* NASM_VERSION_H */
391 printf <<'END', @$version{'major','minor','subminor','patchlevel'};
392 %%define __NASM_MAJOR__ %d
393 %%define __NASM_MINOR__ %d
394 %%define __NASM_SUBMINOR__ %d
395 %%define __NASM_PATCHLEVEL__ %d
398 if ($version->{snapshot
}) {
399 printf "%%define __NASM_SNAPSHOT__ %d\n", $version->{snapshot
};
402 printf <<'END', @$version{'id','_line'};
403 %%define __NASM_VERSION_ID__ 0%08Xh
404 %%define __NASM_VER__ "%s"
413 s/@@NASM_MAJOR@@/$major/g
414 s/@@NASM_MINOR@@/$minor/g
415 s/@@NASM_SUBMINOR@@/$sub_minor/g
416 s/@@NASM_PATCHLEVEL@@/$patchlevel/g
417 s/@@NASM_SNAPSHOT@@/$snapshot/g
418 s/@@NASM_VERSION_ID@@/$id/g
419 s/@@NASM_VERSION_XID@@/$xid/g
420 s/@@NASM_VER@@/$ver/g
421 s/@@NASM_MANGLED_VER@@/$mangled/g
427 my @rep = @
$version{qw{
438 no warnings
'uninitialized';
439 sprintf <<'END', @rep;
440 s/@@NASM_MAJOR@@/%d/g
441 s/@@NASM_MINOR@@/%d/g
442 s/@@NASM_SUBMINOR@@/%d/g
443 s/@@NASM_PATCHLEVEL@@/%d/g
444 s/@@NASM_SNAPSHOT@@/%d/g
445 s/@@NASM_VERSION_ID@@/%d/g
446 s/@@NASM_VERSION_XID@@/%s/g
448 s/@@NASM_MANGLED_VER@@/%s/g
457 NASM_MAJOR_VER=$major
458 NASM_MINOR_VER=$minor
459 NASM_SUBMINOR_VER=$subminor
460 NASM_PATCHLEVEL_VER=$patchlevel
466 return sprintf <<END, @$version{'_line','major','minor','subminor','patchlevel'};
471 NASM_PATCHLEVEL_VER=%d
478 !define VERSION "$version"
479 !define MAJOR_VER $major
480 !define MINOR_VER $minor
481 !define SUBMINOR_VER $subminor
482 !define PATCHLEVEL_VER $patchlevel
488 return sprintf <<'END', @$version{'_line','major','minor','subminor','patchlevel'};
492 !define SUBMINOR_VER %d
493 !define PATCHLEVEL_VER %d
503 sed
=> 'strings for sed command',
504 mac
=> 'strings for nasm macros',
505 h
=> 'strings for headers',
506 make
=> 'strings for makefiles',
507 perl
=> 'dump of program data',
508 nsis
=> 'what is nsis?',
509 json
=> 'dump of program data in json format',
510 yaml
=> 'dump of program data in yaml format'
513 if( $cmd and $help{$cmd} ){
514 print $help{$cmd},"\n";
516 print "$0 [help]? [ ".join(' | ',keys %help)." ]\n";