/
gen_timestamp.sh
executable file
·47 lines (40 loc) · 1.53 KB
/
gen_timestamp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
set -e
function write_timestamp {
CurrYear=`date -u +%Y`
CurrMonth=`date -u +%m`
CurrDay=`date -u +%d`
CurrHour=`date -u +%H`
CurrMinute=`date -u +%M`
echo \#define BUILD_TIMESTAMP \"${CurrYear}-${CurrMonth}-${CurrDay} ${CurrHour}:${CurrMinute} UT\" >> src/common/build_timestamp.h
echo \#define GITREVSTR\(s\) stringify_\(s\) >> src/common/build_timestamp.h
echo \#define stringify_\(s\) \#s >> src/common/build_timestamp.h
echo const char \* get_revision\(void\)\; >> src/common/build_timestamp.h
echo const char \* get_build_timestamp\(void\)\; >> src/common/build_timestamp.h
echo extern const char VERSION_STRING\[\]\; >> src/common/build_timestamp.h
echo \#endif >> src/common/build_timestamp.h
echo src/common/build_timestamp.h file created at ${CurrYear}-${CurrMonth}-${CurrDay} ${CurrHour}:${CurrMinute} UT
}
function write_git_error {
echo #warning GIT failed. Repository not found. Firmware revision will not be generated. >> src/common/build_timestamp.h
echo #define GITREV N/A >> src/common/build_timestamp.h
}
function write_header {
echo \#ifndef BUILD_TIMESTAMP > src/common/build_timestamp.h
git status &> /dev/null
if [ $? -ne 0 ]; then
echo Failed to execute git status
return 1
fi
GITREV="$(git rev-parse --short=8 HEAD)"
echo "#define GITREV \"${GITREV}\"" >> src/common/build_timestamp.h
return 0
}
write_header
if [ $? -eq 0 ]; then
write_timestamp
else
echo Failed to execute git status
write_git_error
write_timestamp
fi