Tomato 1.28
[tomato.git] / release / src / btools / uversion.pl
blob1e22b5d3013c3eb025861061f85fd99e089d0ca9
1 #!/usr/bin/perl
3 # uversion.pl
4 # Copyright (C) 2006 Jonathan Zarate
6 # - update the build number for Tomato
9 use POSIX qw(strftime);
11 sub error
13 print "\nuversion error: $@\n";
14 exit(1);
17 sub help
19 print "Usage: uversion --bump|--gen\n";
20 exit(1);
26 if ($#ARGV != 0) {
27 help();
30 $path = "router/shared";
31 $major = 0;
32 $minor = 0;
33 $build = 0;
35 open(F, "$path/tomato_version") || error("opening tomato_version: $!");
36 $_ = <F>;
37 if (!(($major, $minor, $build) = /^(\d+)\.(\d+)\.(\d+)$/)) {
38 error("Invalid version: '$_'");
40 close(F);
43 if ($ARGV[0] eq "--bump") {
44 ++$build;
45 open(F, ">$path/tomato_version.~") || error("creating temp file: $!");
46 printf F "%d.%02d.%04d", $major, $minor, $build;
47 close(F);
48 rename("$path/tomato_version.~", "$path/tomato_version") || error("renaming: $!");
49 exit(0);
52 if ($ARGV[0] ne "--gen") {
53 help();
56 $time = strftime("%a, %d %b %Y %H:%M:%S %z", localtime());
57 $minor = sprintf("%02d", $minor);
58 $build = sprintf("%04d", $build);
60 open(F, ">$path/tomato_version.h~") || error("creating temp file: $!");
61 print F <<"END";
62 #ifndef __TOMATO_VERSION_H__
63 #define __TOMATO_VERSION_H__
64 #define TOMATO_MAJOR "$major"
65 #define TOMATO_MINOR "$minor"
66 #define TOMATO_BUILD "$build"
67 #define TOMATO_BUILDTIME "$time"
68 #define TOMATO_VERSION "$major.$minor.$build"
69 #endif
70 END
71 close(F);
72 rename("$path/tomato_version.h~", "$path/tomato_version.h") || error("renaming: $!");
74 print "Version: $major.$minor.$build ($time)\n";
75 exit(0);