Merge pull request #1331 from Guilhem7/master
[RRG-proxmark3.git] / tools / mkversion.sh
blob4569a7cf4056277de87522f1681eefaa7cc6dad6
1 #!/bin/sh
3 # Output a version_pm3.c file that includes information about the current build
4 # From mkversion.pl
5 # pure sh POSIX as now even on Windows we use WSL or ProxSpace with sh available
7 # Clear environment locale so that git will not use localized strings
8 export LC_ALL="C"
9 export LANG="C"
11 # if you are making your own fork, change this line to reflect your fork-name
12 fullgitinfo="RRG/Iceman"
13 # GIT status 0 = dirty, 1 = clean , 2 = undecided
14 clean=2
16 # Do we have acces to git command?
17 commandGIT=$(env git)
19 if [ "$commandGIT" != "" ]; then
21 # now avoiding the "fatal: No names found, cannot describe anything." error by fallbacking to abbrev hash in such case
22 gitversion=$(git describe --dirty --always)
23 gitbranch=$(git rev-parse --abbrev-ref HEAD)
24 if [ "$1" != "--undecided" ]; then
25 if [ "$gitversion" != "${gitversion%-dirty}" ]; then
26 clean=0
27 else
28 clean=1
31 if [ "$gitbranch" != "" ] && [ "$gitversion" != "" ]; then
32 fullgitinfo="${fullgitinfo}/${gitbranch}/${gitversion}"
33 ctime="$(date '+%Y-%m-%d %H:%M:%S')"
34 else
35 fullgitinfo="${fullgitinfo}/master/release (git)"
37 else
38 fullgitinfo="${fullgitinfo}/master/release (no_git)"
39 dl_time=$(stat --printf="%y" ../README.md)
40 # POSIX way...
41 ctime=${dl_time%.*}
44 # Crop so it fits within 50 characters C string, so max 49 chars
45 # POSIX way
46 fullgitinfoextra="${fullgitinfo#??????????????????????????????????????????????}"
47 if [ "$fullgitinfoextra" != "$fullgitinfo" ]; then
48 fullgitinfo46="${fullgitinfo%"${fullgitinfoextra}"}"
49 fullgitinfo="${fullgitinfo46}..."
51 cat <<EOF
52 #include "common.h"
53 /* Generated file, do not edit */
54 #ifndef ON_DEVICE
55 #define SECTVERSINFO
56 #else
57 #define SECTVERSINFO __attribute__((section(".version_information")))
58 #endif
60 const struct version_information SECTVERSINFO version_information = {
61 VERSION_INFORMATION_MAGIC,
64 $clean,
65 "$fullgitinfo",
66 "$ctime",
68 EOF