3 if [ "$1" = "--help" ] ||
[ "$1" = "-h" ] ||
[ "$1" = "" ]; then
4 echo "To report a short string about the current version:"
6 echo "To regenerate version_pm3.c if needed:"
7 echo " $0 [--force] [--undecided] path/to/version_pm3.c"
11 # Output a version_pm3.c file that includes information about the current build
13 # pure sh POSIX as now even on Windows we use WSL or ProxSpace with sh available
15 # Clear environment locale so that git will not use localized strings
20 if [ "$1" = "--short" ]; then
25 if [ "$1" = "--force" ]; then
30 if [ "$1" = "--undecided" ]; then
36 if ! $SHORT && [ "$VERSIONSRC" = "" ]; then
37 echo "Error: $0 is missing its destination filename"
41 if $SHORT && [ "$VERSIONSRC" != "" ]; then
42 echo "Error: can't output a short string and generate file at the same time"
46 # if you are making your own fork, change this line to reflect your fork-name
48 # GIT status 0 = dirty, 1 = clean , 2 = undecided
51 # Do we have access to git command?
54 if [ "$commandGIT" != "" ]; then
56 # now avoiding the "fatal: No names found, cannot describe anything." error by fallbacking to abbrev hash in such case
57 gitversion
=$
(git describe
--dirty --always)
58 gitbranch
=$
(git rev-parse
--abbrev-ref HEAD
)
60 if [ "$gitversion" != "${gitversion%-dirty}" ]; then
66 if [ "$gitbranch" != "" ] && [ "$gitversion" != "" ]; then
67 fullgitinfo
="${fullgitinfo}/${gitbranch}/${gitversion}"
68 ctime
="$(date '+%Y-%m-%d %H:%M:%S')"
70 fullgitinfo
="${fullgitinfo}/master/release (git)"
73 fullgitinfo
="${fullgitinfo}/master/release (no_git)"
74 dl_time
=$
(stat
--printf="%y" ..
/README.md
)
83 # Crop so it fits within 50 characters C string, so max 49 chars
85 fullgitinfoextra
="${fullgitinfo#??????????????????????????????????????????????}"
86 if [ "$fullgitinfoextra" != "$fullgitinfo" ]; then
87 fullgitinfo46
="${fullgitinfo%"${fullgitinfoextra}"}"
88 fullgitinfo
="${fullgitinfo46}..."
91 pm3path
=$
(dirname -- "$0")/..
92 cd "$pm3path" ||
return
93 # did we find the src?
94 [ -f armsrc
/appmain.c
] ||
return
95 if [ "${OSTYPE#darwin}" != "$OSTYPE" ]; then
97 ls armsrc
/*.
[ch
] common_arm
/*.
[ch
]|
grep -E -v "(disabled|version_pm3|fpga_version_info)"|
sort|
xargs shasum
-a 256 -t|shasum
-a 256|cut
-c -9
99 ls armsrc
/*.
[ch
] common_arm
/*.
[ch
]|
grep -E -v "(disabled|version_pm3|fpga_version_info)"|
sort|
xargs sha256sum
-t|sha256sum|cut
-c -9
102 if [ "$sha" = "" ]; then
107 if ! $FORCE && [ -f "$VERSIONSRC" ]; then
108 # version src file exists, check if it needs to be updated
109 # file parser quite fragile, be careful if you edit VERSIONSRC template below...
110 oldclean
=$
(sed '13s/.*\([0-9]\+\).*/\1/;13!d' "$VERSIONSRC")
111 oldfullgitinfo
=$
(sed '14s/.*"\([^"]*\)".*/\1/;14!d' "$VERSIONSRC")
112 oldsha
=$
(sed '16s/.*"\([^"]*\)".*/\1/;16!d' "$VERSIONSRC")
113 if [ "$oldclean" = "$clean" ] && [ "$oldfullgitinfo" = "$fullgitinfo" ] && [ "$oldsha" = "$sha" ]; then
118 # use a tmp file to avoid concurrent call to mkversion to parse a half-written file.
119 cat > "${VERSIONSRC}.tmp" <<EOF
121 /* Generated file, do not edit */
125 #define SECTVERSINFO __attribute__((section(".version_information")))
128 const struct version_information_t SECTVERSINFO g_version_information = {
129 VERSION_INFORMATION_MAGIC,
138 mv "${VERSIONSRC}.tmp" "${VERSIONSRC}"