-
Notifications
You must be signed in to change notification settings - Fork 10
/
auto_version.pl
executable file
·59 lines (54 loc) · 1.23 KB
/
auto_version.pl
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
#!/usr/bin/perl -w
use strict;
use POSIX qw(strftime);
my $max_minor = 199;
my $max_build = 1999;
my $date = strftime "%d.%m.%Y", localtime;
my @def_files = ( "include/app_defaults.h" );
# Incrementing Source files with C defined Version Code
foreach my $f (@def_files) {
my @new;
open(F, "<$f") or die $!;
my @content = <F>;
my $major_set = 0;
my $minor_set = 0;
foreach my $line (@content) {
if ($line =~ m/\#define\ VER_BUILD\t\t(\d+)/) {
my $build = $1;
$build++;
if ($build > $max_build) {
$build = 0;
$minor_set = 1;
}
$line =~ s/(\#define\ VER_BUILD\t\t)\d+(.*)$/$1$build$2/;
}
elsif ($line =~ m/\#define.?VER_MINOR\t\t(\d+)/) {
if ($minor_set > 0) {
$minor_set = 0;
my $minor = $1;
$minor++;
if ($minor > $max_minor) {
$minor = 0;
$major_set = 1;
}
$line =~ s/(\#define.?VER_MINOR\t\t)\d+(.*)$/$1$minor$2/;
}
}
elsif ($line =~ m/\#define.?VER_MAJOR.?(\d+).*$/) {
if ($major_set > 0) {
$major_set = 0;
my $major = $1;
$major++;
$line =~ s/(\#define.?VER_MAJOR.?)\d+(.*)$/$1$major$2/;
}
}
push(@new, $line);
}
close(F);
open(F, ">$f") or die $!;
foreach my $line (@new) {
print F $line;
}
close(F);
}
printf "Version Codes updated!\n";