4 # Copyright (C) 2006 Jonathan Zarate
6 # - update the build number for Tomato
7 # !!TB - Added version suffix
10 use POSIX
qw(strftime);
14 print "\nuversion error: $@\n";
20 print "Usage: uversion --bump|--gen\n";
31 $path = "router/shared";
38 open(F
, "$path/tomato_version") || error
("opening tomato_version: $!");
40 if (!(($major, $minor, $build, $space, $suffix) = /^(\d+)\.(\d+)\.(\d+)(\s+)?(.+)?$/)) {
41 error
("Invalid version: '$_'");
45 if ($ARGV[0] eq "--bump") {
47 open(F
, ">$path/tomato_version.~") || error
("creating temp file: $!");
48 printf F
"%d.%02d.%04d %s", $major, $minor, $build, $suffix;
50 rename("$path/tomato_version.~", "$path/tomato_version") || error
("renaming: $!");
54 if ($ARGV[0] ne "--gen") {
58 $time = strftime
("%a, %d %b %Y %H:%M:%S %z", localtime());
59 $minor = sprintf("%02d", $minor);
60 $build = sprintf("%04d", $build);
62 # read the build number from the command line
64 if ($ARGV[1] ne "--def") {
65 $build = sprintf("%04d", $ARGV[1]);
69 # read the version suffix from the command line
74 for ($i=$start; $i <= $stop; $i++) {
78 elsif ($ARGV[$i] ne "") {
79 $suffix = sprintf("%s %s", $suffix, $ARGV[$i]);
84 open(F
, ">$path/tomato_version.h~") || error
("creating temp file: $!");
86 #ifndef __TOMATO_VERSION_H__
87 #define __TOMATO_VERSION_H__
88 #define TOMATO_MAJOR "$major"
89 #define TOMATO_MINOR "$minor"
90 #define TOMATO_BUILD "$build"
91 #define TOMATO_BUILDTIME "$time"
92 #define TOMATO_VERSION "$major.$minor.$build $suffix"
96 rename("$path/tomato_version.h~", "$path/tomato_version.h") || error
("renaming: $!");
98 open(F
, ">$path/tomato_version.~") || error
("creating temp file: $!");
99 printf F
"%d.%02d.%04d %s", $major, $minor, $build, $suffix;
101 rename("$path/tomato_version.~", "$path/tomato_version") || error
("renaming: $!");
103 print "Version: $major.$minor.$build $suffix ($time)\n";