• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/perl
2#
3# Read the "version" file and produce some macro declarations
4#
5
6use Fcntl;
7
8sub defx($$$) {
9    my($def, $name, $val) = @_;
10
11    $def =~ s/\</${name}/g;
12    $def =~ s/\@/${val}/g;
13
14    return $def."\n";
15}
16
17($vfile, $vout, $def) = @ARGV;
18sysopen(VERSION, $vfile, O_RDONLY) or die "$0: Cannot open $vfile\n";
19$vfile = <VERSION>;
20chomp $vfile;
21close(VERSION);
22
23unless ( $vfile =~ /^(([0-9]+)\.([0-9]+))\s+([0-9]+)$/ ) {
24    die "$0: Cannot parse version format\n";
25}
26$version = $1;
27$vma = $2+0;
28$vmi = $3+0;
29$year = $4;
30
31sysopen(VI, $vout, O_WRONLY|O_CREAT|O_TRUNC)
32    or die "$0: Cannot create $vout: $!\n";
33print VI defx($def, 'VERSION',       $version);
34print VI defx($def, 'VERSION_STR',   '"'.$version.'"');
35print VI defx($def, 'VERSION_MAJOR', $vma);
36print VI defx($def, 'VERSION_MINOR', $vmi);
37print VI defx($def, 'YEAR',          $year);
38print VI defx($def, 'YEAR_STR',      '"'.$year.'"');
39close(VI);
40