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 # if FORCED_DATE present and properly formatted:
69 case "$FORCED_DATE" in
70 [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]" "[0-9][0-9]:[0-9][0-9]:[0-9][0-9])
74 ctime
="$(date '+%Y-%m-%d %H:%M:%S')"
78 fullgitinfo
="${fullgitinfo}/master/release (git)"
81 fullgitinfo
="${fullgitinfo}/master/release (no_git)"
82 dl_time
=$
(stat
--printf="%y" README.md
)
91 # Crop so it fits within 50 characters C string, so max 49 chars
93 fullgitinfoextra
="${fullgitinfo#??????????????????????????????????????????????}"
94 if [ "$fullgitinfoextra" != "$fullgitinfo" ]; then
95 fullgitinfo46
="${fullgitinfo%"${fullgitinfoextra}"}"
96 fullgitinfo
="${fullgitinfo46}..."
99 pm3path
=$
(dirname -- "$0")/..
100 cd "$pm3path" ||
return
101 # did we find the src?
102 [ -f armsrc
/appmain.c
] ||
return
103 if [ "${OSTYPE#darwin}" != "$OSTYPE" ]; then
105 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
107 ls armsrc
/*.
[ch
] common_arm
/*.
[ch
]|
grep -E -v "(disabled|version_pm3|fpga_version_info)"|
sort|
xargs sha256sum
-t|sha256sum|cut
-c -9
110 if [ "$sha" = "" ]; then
115 if ! $FORCE && [ -f "$VERSIONSRC" ]; then
116 # version src file exists, check if it needs to be updated
117 # file parser quite fragile, be careful if you edit VERSIONSRC template below...
118 oldclean
=$
(sed '13s/.*\([0-9]\+\).*/\1/;13!d' "$VERSIONSRC")
119 oldfullgitinfo
=$
(sed '14s/.*"\([^"]*\)".*/\1/;14!d' "$VERSIONSRC")
120 oldsha
=$
(sed '16s/.*"\([^"]*\)".*/\1/;16!d' "$VERSIONSRC")
121 if [ "$oldclean" = "$clean" ] && [ "$oldfullgitinfo" = "$fullgitinfo" ] && [ "$oldsha" = "$sha" ]; then
126 # use a tmp file to avoid concurrent call to mkversion to parse a half-written file.
127 cat > "${VERSIONSRC}.tmp" <<EOF
129 /* Generated file, do not edit */
133 #define SECTVERSINFO __attribute__((section(".version_information")))
136 const struct version_information_t SECTVERSINFO g_version_information = {
137 VERSION_INFORMATION_MAGIC,
146 mv "${VERSIONSRC}.tmp" "${VERSIONSRC}"