forked from phkehl/ubloxcfg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.h.pl
executable file
·72 lines (64 loc) · 1.47 KB
/
config.h.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
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/perl -w
use strict;
use warnings;
my $debug = 0;
print("// Automatically generated. Do not edit.\n");
print("#ifndef __CONFIG_GEN_H__\n");
print("#define __CONFIG_GEN_H__\n");
do
{
my $hash = getGithash();
my $date = getDate();
my $time = getTime();
my $year = substr($date, 0, 4);
while (my $line = <STDIN>)
{
$line =~ s{%HASH%}{$hash}g;
$line =~ s{%DATE%}{$date}g;
$line =~ s{%TIME%}{$time}g;
$line =~ s{%YEAR%}{$year}g;
print($line);
}
};
print("#endif\n");
sub getDate
{
my (undef, undef, undef, $mday, $mon, $year) = localtime();
return sprintf('%04i-%02i-%02i', $year + 1900, $mon + 1, $mday);
}
sub getTime
{
my ($sec, $min, $hour) = localtime();
return sprintf('%02i:%02i:%02i', $hour, $min, $sec);
}
sub getGithash
{
my ($hash, $dirty);
if ($^O =~ m/Win/i)
{
$hash = qx{git log --pretty=format:%H -n1};
$dirty = qx{git describe --always --dirty};
}
else
{
$hash = qx{LC_ALL=C git log --pretty=format:%H -n1 2>/dev/null};
$dirty = qx{LC_ALL=C git describe --always --dirty 2>/dev/null};
}
$hash =~ s{\r?\n}{};
$dirty =~ s{\r?\n}{};
print(STDERR "hash=[$hash]\ndirty=[$dirty]\n") if ($debug);
if ($hash && $dirty)
{
my $str = substr($hash, 0, 8);
if ($dirty =~ m{-dirty$})
{
$str .= 'M' ;
}
return $str;
}
else
{
return "00000000";
}
}
# eof