]>
Commit | Line | Data |
---|---|---|
8a6aec16 | 1 | #!/usr/bin/perl |
2 | # Output a version.c file that includes information about the current build | |
3 | # Normally a couple of lines of bash would be enough (see openpcd project, original firmware by Harald Welte and Milosch Meriac) | |
4 | # but this will, at least in theory, also work on Windows with our current compile environment. | |
5 | # -- Henryk Plötz <henryk@ploetzli.ch> 2009-09-28 | |
6 | ||
8a6aec16 | 7 | my $main_dir = shift; |
8 | ||
9 | # Clear environment locale so that svn will not use localized strings | |
10 | $ENV{'LC_ALL'} = "C"; | |
11 | $ENV{'LANG'} = "C"; | |
12 | ||
13 | my $svnversion = 0; | |
14 | my $present = 0; | |
15 | my $clean = 2; | |
16 | my @compiletime = gmtime(); | |
17 | ||
18 | # Strategy one: call svn info and extract last changed revision, call svn status and look for ^M | |
19 | if(open(SVNINFO, "svn info $main_dir|")) { | |
20 | while(<SVNINFO>) { | |
21 | if (/^Last Changed Rev: (.*)/) { | |
22 | $present = 1; | |
23 | $svnversion = $1; | |
24 | ## last; # Do not abort here, since SVN tends to complain about a Broken pipe | |
25 | } | |
26 | } | |
27 | close(SVNINFO); | |
49b35ff9 | 28 | |
8a6aec16 | 29 | if(open(SVNSTATUS, "svn status $main_dir|")) { |
30 | $clean = 1; | |
31 | while(<SVNSTATUS>) { | |
32 | if(/^M/) { | |
33 | $clean = 0; | |
34 | ## last; | |
35 | } | |
36 | } | |
37 | close(SVNINFO); | |
38 | } | |
49b35ff9 | 39 | |
8a6aec16 | 40 | } else { |
49b35ff9 | 41 | # Strategy two: look for .svn/entries. The third line should be "dir", the fourth line should contain |
4f3bd973 | 42 | # the currently checked out revision, the eleventh line should contain the last changed revision. |
8a6aec16 | 43 | # revision. |
44 | if(open(ENTRIES, "$main_dir/.svn/entries")) { | |
45 | my $i = 1; | |
46 | while(<ENTRIES>) { | |
47 | last if($i == 3 and !/^dir/); | |
4f3bd973 | 48 | if($i == 11 and /^([0-9]*)/) { |
8a6aec16 | 49 | $present = 1; |
50 | $svnversion = $1; | |
51 | } | |
52 | $i++; | |
53 | } | |
54 | } | |
55 | } | |
56 | ||
57 | $compiletime[4] += 1; | |
58 | $compiletime[5] += 1900; | |
59 | my $ctime = sprintf("%6\$04i-%5\$02i-%4\$02i %3\$02i:%2\$02i:%1\$02i", @compiletime); | |
50011f19 | 60 | $svnversion=~ s/(^\s+|\s+$)//g; |
8a6aec16 | 61 | |
62 | print <<EOF | |
49b35ff9 | 63 | #include "proxmark3.h" |
8a6aec16 | 64 | /* Generated file, do not edit */ |
b7913d8f | 65 | const struct version_information __attribute__((section(".version_information"))) version_information = { |
8a6aec16 | 66 | VERSION_INFORMATION_MAGIC, |
67 | 1, | |
68 | $present, | |
69 | $clean, | |
70 | "svn $svnversion", | |
71 | "$ctime", | |
72 | }; | |
73 | EOF |