]> git.zerfleddert.de Git - proxmark3-svn/blame_incremental - tools/mkversion.pl
Refactoring low frequency operations, now 'lf hid fskdemod' is more stable. Also...
[proxmark3-svn] / tools / mkversion.pl
... / ...
CommitLineData
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
7my $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
13my $svnversion = 0;
14my $clean = 2;
15my @compiletime = gmtime();
16
17# Strategy one: call svn info and extract last changed revision, call svn status and look for ^M
18if(open(SVNINFO, "svn info $main_dir|")) {
19 while(<SVNINFO>) {
20 if (/^Last Changed Rev: (.*)/) {
21 $svnversion = $1;
22 ## last; # Do not abort here, since SVN tends to complain about a Broken pipe
23 }
24 }
25 close(SVNINFO);
26
27 if(open(SVNSTATUS, "svn status $main_dir|")) {
28 $clean = 1;
29 while(<SVNSTATUS>) {
30 if(/^M/) {
31 $clean = 0;
32 ## last;
33 }
34 }
35 close(SVNINFO);
36 }
37
38} else {
39 # Strategy two: look for .svn/entries. The third line should be "dir", the fourth line should contain
40 # the currently checked out revision, the eleventh line should contain the last changed revision.
41 # revision.
42 if(open(ENTRIES, "$main_dir/.svn/entries")) {
43 my $i = 1;
44 while(<ENTRIES>) {
45 last if($i == 3 and !/^dir/);
46 if($i == 11 and /^([0-9]*)/) {
47 $svnversion = $1;
48 }
49 $i++;
50 }
51 }
52}
53
54$compiletime[4] += 1;
55$compiletime[5] += 1900;
56my $ctime = sprintf("%6\$04i-%5\$02i-%4\$02i %3\$02i:%2\$02i:%1\$02i", @compiletime);
57$svnversion=~ s/(^\s+|\s+$)//g;
58
59print <<EOF
60#include "proxmark3.h"
61/* Generated file, do not edit */
62const struct version_information __attribute__((section(".version_information"))) version_information = {
63 VERSION_INFORMATION_MAGIC,
64 1,
65 1,
66 $clean,
67 "svn $svnversion",
68 "$ctime",
69};
70EOF
Impressum, Datenschutz