summaryrefslogtreecommitdiff
path: root/graphics/sketch/makever.pl
blob: 430f0d42e93fbc76dab4149a3ecb8ddbaebe34c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use strict;
use POSIX qw(strftime);
    
sub run {
  local $/ = undef;
  local *F;

  # get raw data
  open(F, "version.dat") || die "can't open version.dat for input";
  my $x = <F>;
  close F;

  # put data pairs in a hash
  my %pairs = $x =~ /([a-z]+)\s*=\s*(\S+)\s*/g;
  die "syntax error in version.dat\n" unless
		defined $pairs{major} && 
    defined $pairs{minor} && 
    defined $pairs{build};

  # update the build number
  $pairs{build}++ unless $pairs{dist} or $ARGV[0] eq 'noinc';

  # get the current time/date
  my $t = time;
  $pairs{time} = $t;
  my $slt = scalar(localtime($t));
  my $nicelt = strftime("%A, %B %d, %Y", localtime($t));

  # print the header
  open(F, "> version.h") || die "can't open version.h for output";
  print F "// Produced by makever.pl.  Don't edit.\n";
  print F "#define VER_MAJOR $pairs{major}\n";
  print F "#define VER_MINOR $pairs{minor}\n";
  print F "#define VER_BUILD $pairs{build}\n";
  print F "#define VER_BUILD_TIME $t\n";
  print F "#ifndef STRINGIFY\n";
  print F "#define ___S(X) #X\n";
  print F "#define STRINGIFY(X) ___S(X)\n";
  print F "#endif\n";
  print F "#define VER_BUILD_TIME_STRING STRINGIFY($slt)\n";
  my $d = $pairs{dist} ? "d" : "";
  print F qq|#define VER_STRING STRINGIFY(VER_MAJOR) "." STRINGIFY(VER_MINOR) " (build " STRINGIFY(VER_BUILD) "$d, " VER_BUILD_TIME_STRING ")"\n|;
  close F;

  # print doc version information
  open(F, "> Doc/version.texi") || die "can't open version.texi";
  print F "\@comment Produced by makever.pl.  Don't edit.\n";
  print F "\@set VER_MAJOR $pairs{major}\n";
  print F "\@set VER_MINOR $pairs{minor}\n";
  print F "\@set VER_BUILD $pairs{build}\n";
  print F "\@set UPDATED $nicelt\n";
  print F "\@set VERSION \@value{VER_MAJOR}.\@value{VER_MINOR} (build \@value{VER_BUILD})\n";
  close F;

  if ( open(F, "index-tmp.htm") ) {
		my $html = <F>;
		close F;
		my $version = "$pairs{major}.$pairs{minor} (build $pairs{build}), $nicelt";
		$html =~ s/VERSION/$version/g;
		my $ver = "$pairs{major}.$pairs{minor}.$pairs{build}";
		$html =~ s/VER/$ver/g;
		open(F, "> index.htm") || die "can't open index.htm for output";
		print F $html;
		close F;
  }
  else {
    warn "not generating web page\n";
  }

  # update the version header
  open(F, "> version.dat") || die "can't open version.dat for output";
  print F join('', map { "$_ = $pairs{$_}\n" } keys %pairs);
  close F;
}

run;