]> cvs.zerfleddert.de Git - proxmark3-svn/blob - tools/mkversion.pl
1c4dfcd965a1294e2a71d67b20cf9c0d2d9a7ec8
[proxmark3-svn] / tools / mkversion.pl
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
7 use strict;
8
9 my $main_dir = shift;
10
11 # Clear environment locale so that svn will not use localized strings
12 $ENV{'LC_ALL'} = "C";
13 $ENV{'LANG'} = "C";
14
15 my $svnversion = 0;
16 my $present = 0;
17 my $clean = 2;
18 my @compiletime = gmtime();
19
20 # Strategy one: call svn info and extract last changed revision, call svn status and look for ^M
21 if(open(SVNINFO, "svn info $main_dir|")) {
22 while(<SVNINFO>) {
23 if (/^Last Changed Rev: (.*)/) {
24 $present = 1;
25 $svnversion = $1;
26 ## last; # Do not abort here, since SVN tends to complain about a Broken pipe
27 }
28 }
29 close(SVNINFO);
30
31 if(open(SVNSTATUS, "svn status $main_dir|")) {
32 $clean = 1;
33 while(<SVNSTATUS>) {
34 if(/^M/) {
35 $clean = 0;
36 ## last;
37 }
38 }
39 close(SVNINFO);
40 }
41
42 } else {
43 # Strategy two: look for .svn/entries. The third line should be "dir", the fourth line should contain the current
44 # revision.
45 if(open(ENTRIES, "$main_dir/.svn/entries")) {
46 my $i = 1;
47 while(<ENTRIES>) {
48 last if($i == 3 and !/^dir/);
49 if($i == 4 and /^([0-9]*)/) {
50 $present = 1;
51 $svnversion = $1;
52 }
53 $i++;
54 }
55 }
56 }
57
58 $compiletime[4] += 1;
59 $compiletime[5] += 1900;
60 my $ctime = sprintf("%6\$04i-%5\$02i-%4\$02i %3\$02i:%2\$02i:%1\$02i", @compiletime);
61
62 print <<EOF
63 #include <proxmark3.h>
64 /* Generated file, do not edit */
65 struct version_information __attribute__((section(".version_information"))) version_information = {
66 VERSION_INFORMATION_MAGIC,
67 1,
68 $present,
69 $clean,
70 "svn $svnversion",
71 "$ctime",
72 };
73 EOF
Impressum, Datenschutz