-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtimestamp-emit.sh
executable file
·123 lines (96 loc) · 4.52 KB
/
timestamp-emit.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
# script timestamp-emit.sh
## BISMON - see github.com/bstarynk/bismon/
## Copyright © 2018 - 2021 CEA (Commissariat à l'énergie atomique et aux énergies alternatives)
## contributed by Basile Starynkevitch (working at CEA, LIST, France)
## <[email protected]> or <[email protected]>
# there should be at most one argument....
output_timestamp=$1
if [ -z "$output_timestamp" ]; then
output_timestamp=__timestamp.c
fi
if [ ! -d ".git" ]; then
printf "%s should be invoked from a .git versioned directory\n" $0 > /dev/stderr
exit 1
fi
if [ $# -gt 1 ]; then
printf "%s should be invoked with at most one argument, the timestamp file to be generated...\n" $0 > /dev/stderr
exit 1
fi
tempoutput="$output_timestamp-$$.tmp"
printf "// %sGENERATED¤ timestamp file %s, see http://github.com/bstarynk/bismon\n" "¤" $output_timestamp > $tempoutput
printf "// generated by %s on %s\n" "$0" "$(date +"%Y %b %d")" $(hostname) >> $tempoutput
date +'const char bismon_timestamp[]="%c";%n const unsigned long bismon_timelong=%sL;' >> $tempoutput
(echo -n 'const char bismon_lastgitcommit[]="' ; \
git log --format=oneline --abbrev=12 --abbrev-commit -q \
| head -1 | tr -d '\n\r\f\"\\\\' ; \
echo '";') >> $tempoutput
if git status|grep -q 'nothing to commit' ; then
endgitid='";'
else
endgitid='+";'
fi
(echo -n 'const char bismon_gitid[]="';
git log --format=oneline -q -1 | cut '-d ' -f1 | tr -d '\n';
echo $endgitid) >> $tempoutput
(printf 'const char bismon_shortgitid[]="%.16s%s\n' \
$(git log --format=oneline -q -1 | cut '-d ' -f1 | tr -d '\n') \
$endgitid) >> $tempoutput
(echo 'const char* const bismon_sources[] = {';
git ls-tree -r --name-only --full-name HEAD | ./emit-git-sources.gawk
printf ' (const char*)0 }; // end bismon_sources\n') >> $tempoutput
(printf 'const int bismon_source_number =\n (sizeof(bismon_sources)/sizeof(bismon_sources[0])) - 1;\n\n') >> $tempoutput
(echo -n 'const char bismon_lastgittag[]="'; (git describe --abbrev=0 --all || echo '*notag*') | tr -d '\n\r\f\"\\\\'; echo '";') >> $tempoutput
(echo -n 'const char bismon_checksum[]="'; cat $(git ls-tree -r --full-name HEAD | awk '/^100/{print $4}') | md5sum | cut -d' ' -f1 | tr -d '\n\r\f\"\\' ; echo '";') >> $tempoutput
(echo -n 'const char bismon_directory[]="'; /bin/pwd | tr -d '\n\\"' ; echo '";') >> $tempoutput
(echo -n 'const char bismon_gnumakefile[]="'; echo -n $(realpath GNUmakefile); echo '";') >> $tempoutput
if [ -n "$BISMON_MAKE" ] ; then
(echo -n 'const char* bismon_make ="'; echo -n $BISMON_MAKE; echo '";') >> $tempoutput
else
echo 'const char* bismon_make;' >> $tempoutput
fi
if [ -n "$BISMON_PACKAGES" ] ; then
(echo -n 'const char* bismon_packages = "'; echo -n $BISMON_PACKAGES; echo '";') >> $tempoutput
else
echo 'const char* bismon_packages;' >> $tempoutput
fi
### target cross-compilers
echo "//// target cross-compilers:" >> $tempoutput
if [ -n "$BISMONMK_TARGET_GCC" ]; then
(echo -n 'const char* bismon_target_gcc = "'; echo -n $BISMONMK_TARGET_GCC; echo '";') >> $tempoutput
else
echo 'const char* bismon_target_gcc;' >> $tempoutput
fi
if [ -n "$BISMONMK_TARGET_GXX" ]; then
(echo -n 'const char* bismon_target_gxx = "'; echo -n $BISMONMK_TARGET_GXX; echo '";') >> $tempoutput
else
echo 'const char* bismon_target_gxx;' >> $tempoutput
fi
### host compilers
echo "//// host compilers:" >> $tempoutput
if [ -n "$BISMONMK_HOST_CC" ]; then
(echo -n 'const char* bismon_host_cc = "'; echo -n $BISMONMK_HOST_CC; echo '";') >> $tempoutput
else
echo 'const char* bismon_host_cc;' >> $tempoutput
fi
if [ -n "$BISMONMK_HOST_CXX" ]; then
(echo -n 'const char* bismon_host_cxx = "'; echo -n $BISMONMK_HOST_CXX; echo '";') >> $tempoutput
else
echo 'const char* bismon_host_cxx;' >> $tempoutput
fi
### libonion is becoming obsolete, commit cfe63e48206d6f568 (june 22, 2022); see BISMON_LIBONION preprocessor flag
#° echo "//// libonion for Web service:" >> $tempoutput
#° if [ -n "$BISMONMK_ONION_INCLUDEDIR" ]; then
#° (echo -n 'const char* bismon_onion_includedir = "'; echo -n $BISMONMK_ONION_INCLUDEDIR; echo '";') >> $tempoutput
#° else
#° echo 'const char* bismon_onion_includedir;' >> $tempoutput
#° fi
#°
#°
#° if [ -n "$BISMONMK_ONION_LIBDIR" ]; then
#° (echo -n 'const char* bismon_onion_libdir = "'; echo -n $BISMONMK_ONION_LIBDIR; echo '";') >> $tempoutput
#° else
#° echo 'const char* bismon_onion_libdir;' >> $tempoutput
#° fi
mv $tempoutput $output_timestamp
### eof timestamp-emit.sh