]> git.zerfleddert.de Git - proxmark3-svn/blame - tools/mkversion.pl
merged trunk changes into branch
[proxmark3-svn] / tools / mkversion.pl
CommitLineData
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 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;
8a6aec16 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: (.*)/) {
8a6aec16 21 $svnversion = $1;
22 ## last; # Do not abort here, since SVN tends to complain about a Broken pipe
23 }
24 }
25 close(SVNINFO);
49b35ff9 26
8a6aec16 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 }
49b35ff9 37
8a6aec16 38} else {
49b35ff9 39 # Strategy two: look for .svn/entries. The third line should be "dir", the fourth line should contain
4f3bd973 40 # the currently checked out revision, the eleventh line should contain the last changed revision.
8a6aec16 41 # revision.
42 if(open(ENTRIES, "$main_dir/.svn/entries")) {
43 my $i = 1;
44 while(<ENTRIES>) {
45 last if($i == 3 and !/^dir/);
4f3bd973 46 if($i == 11 and /^([0-9]*)/) {
8a6aec16 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);
50011f19 57$svnversion=~ s/(^\s+|\s+$)//g;
8a6aec16 58
59print <<EOF
49b35ff9 60#include "proxmark3.h"
8a6aec16 61/* Generated file, do not edit */
b7913d8f 62const struct version_information __attribute__((section(".version_information"))) version_information = {
8a6aec16 63 VERSION_INFORMATION_MAGIC,
64 1,
69135e1c 65 1,
8a6aec16 66 $clean,
67 "svn $svnversion",
68 "$ctime",
69};
70EOF
Impressum, Datenschutz