Version generation changes
[tomato.git] / release / src / btools / uversion.pl
blobcf6c3c3754d1a9c902e84de49017c0479ee002a3
1 #!/usr/bin/perl
3 # uversion.pl
4 # Copyright (C) 2006 Jonathan Zarate
6 # - update the build number for Tomato
7 # !!TB - Added version suffix
10 use POSIX qw(strftime);
12 sub error
14 print "\nuversion error: $@\n";
15 exit(1);
18 sub help
20 print "Usage: uversion --bump|--gen\n";
21 exit(1);
27 if ($#ARGV < 0) {
28 help();
31 $path = "router/shared";
32 $major = 0;
33 $minor = 0;
34 $build = 0;
35 $space = "";
36 $suffix = "";
38 open(F, "$path/tomato_version") || error("opening tomato_version: $!");
39 $_ = <F>;
40 if (!(($major, $minor, $build, $space, $suffix) = /^(\d+)\.(\d+)\.(\d+)(\s+)?(.+)?$/)) {
41 error("Invalid version: '$_'");
43 close(F);
45 if ($ARGV[0] eq "--bump") {
46 ++$build;
47 open(F, ">$path/tomato_version.~") || error("creating temp file: $!");
48 printf F "%d.%02d.%04d %s", $major, $minor, $build, $suffix;
49 close(F);
50 rename("$path/tomato_version.~", "$path/tomato_version") || error("renaming: $!");
51 exit(0);
54 if ($ARGV[0] ne "--gen") {
55 help();
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
63 if ($#ARGV > 0) {
64 if ($ARGV[1] ne "--def") {
65 $build = sprintf("%04d", $ARGV[1]);
69 # read the version suffix from the command line
70 if ($#ARGV > 1) {
71 $start = 2;
72 $stop = $#ARGV;
73 $suffix = "";
74 for ($i=$start; $i <= $stop; $i++) {
75 if ($suffix eq "") {
76 $suffix = $ARGV[$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: $!");
85 print F <<"END";
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"
93 #endif
94 END
95 close(F);
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;
100 close(F);
101 rename("$path/tomato_version.~", "$path/tomato_version") || error("renaming: $!");
103 print "Version: $major.$minor.$build $suffix ($time)\n";
104 exit(0);