forked from RefPerSys/RefPerSys
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrps-generate-timestamp.sh
More file actions
executable file
·159 lines (115 loc) · 5.96 KB
/
rps-generate-timestamp.sh
File metadata and controls
executable file
·159 lines (115 loc) · 5.96 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-or-later
#
# © Copyright (C) 2020 - 2025, Basile Starynkevitch and the
# forum@refpersys.org mailing list contributors
#
# This file rps-generate-timestamp.sh is part of the Reflexive
# Persistent System (aka RefPerSys); it just emits a string with the
# full git commit id, appending + if the git status is not clean.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##
## This internal script generates some C file containing timestamp
## related constants for Linux related to the RefPerSys inference
## engine free software project on refpersys.org. It should be
## invoked by GNU make only.
##
if [ -z $GPP ]; then
GPP=$(which gpp)
if [ -z $GPP ]; then
printf "%s missing gpp\n" $0 2>&1
exit 1
fi
export GPP
fi
if [ -z $CXX ]; then
CXX=$(which g++)
if [ -z $CXX ]; then
printf "%s missing g++ GNU compiler\n" $0 2>&1
exit 1
fi
export CXX
fi
if [ -z $CARBURETTA ]; then
CARBURETTA=$(which carburetta)
if [ -z $CARBURETTA ]; then
printf "%s missing carburetta parser generator, see https://carburetta.com/ and github.com/kingletbv/carburetta\n" $0 2>&1
exit 1
fi
export CARBURETTA
fi
printf "/// invocation: %s %s in %s\n" $0 "$*" "$(realpath $(pwd))"
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LC_TIME=en_US.UTF-8
printf "// generated C file %s by %s -- DONT EDIT - see refpersys.org\n" $1 $0
printf "// to restore %s from a %%%%__timestamp.c%%%% file edit there lines with @REFPERSYS_HOME.\n" $1
printf "// environment is:\n"
printenv | /bin/sed 's:^://~ :'
printf "\n\n"
date +"const char rps_timestamp[]=\"%c\";%nconst unsigned long rps_timelong=%sL;"
printf "const char rps_topdirectory[]=\"%s\";\n" $(realpath $(pwd))
if git status|grep -q 'nothing to commit' ; then
endgitid='";'
else
endgitid='+";'
fi
(echo -n 'const char rps_gitid[]="';
git log --format=oneline -q -1 | cut '-d ' -f1 | tr -d '\n';
echo $endgitid)
printf 'const char rps_shortgitid[] = "%s";\n' "$(./rps-generate-gitid.sh -s)"
printf 'const char rps_gitbranch[] = "%s";\n' "$(git branch --show-current)"
(echo -n 'const char rps_lastgittag[]="'; (git describe --abbrev=0 --all || echo '*notag*') | tr -d '\n\r\f\"\\\\'; echo '";')
(echo -n 'const char rps_lastgitcommit[]="' ; \
git log --format=oneline --abbrev=12 --abbrev-commit -q \
| head -1 | tr -d '\n\r\f\"\\\\' ; \
echo '";')
git archive -o /tmp/refpersys-$$.tar.gz HEAD
trap "/bin/rm /tmp/refpersys-$$.tar.gz /tmp/refpersys-$$.toc" EXIT INT
cp -va /tmp/refpersys-$$.tar.gz $HOME/tmp/refpersys.tar.gz >& /dev/stderr
/bin/tar tf /tmp/refpersys-$$.tar.gz | /bin/grep -v 'attic' > /tmp/refpersys-$$.toc
printf "\n/// refpersys.toc:\n"
/bin/sed s:^:///:g /tmp/refpersys-$$.toc
printf "//// end refpersys.toc\n"
(echo -n 'const char rps_md5sum[]="' ; cat $(/bin/grep -v '/$' /tmp/refpersys-$$.toc ) | /usr/bin/md5sum | /usr/bin/tr -d '\n -' ; echo '";')
(echo 'const char*const rps_files[]= {'; /bin/egrep -v '/$\|attic/' /tmp/refpersys-$$.toc | /usr/bin/tr -s " \n" | /usr/bin/sed 's/^\(.*\)$/ "\1\",/'; echo ' (const char*)0} ;')
(echo 'const char*const rps_subdirectories[]= {' ; /bin/grep '/$' /tmp/refpersys-$$.toc | tr -s " \n" | sed 's/^\(.*\)$/ "\1\",/'; echo ' (const char*)0} ;')
printf "const char rps_gnumakefile[]=\"%s\";\n" $(realpath GNUmakefile)
printf "const char rps_gnu_make[]=\"%s\";\n" $(/bin/which gmake)
printf "const char rps_gnu_make_version[]=\"%s\";\n" "$(gmake --version | /bin/head -1)"
printf "const char rps_gnu_make_features[]=\"%s\";\n" "$(gmake -s --no-print-directory print-gmake-features)"
printf "const char rps_gnu_bison[]=\"%s\";\n" $(/bin/which bison)
printf "const char rps_gnu_bison_version[]=\"%s\";\n" "$(bison --version | /bin/head -1)"
printf "const char rps_carburetta[]=\"%s\"; //Carburetta parser generator, see github.com/kingletbv/carburetta\n" $(/bin/which $CARBURETTA)
printf "const char rps_carburetta_version[]=\"%s\";\n" "$($CARBURETTA --version | /bin/head -1)"
printf "const char rps_gui_script_executable[]=\"%s\";\n" $(realpath gui-script-refpersys.sh)
printf "const char rps_building_user_name[]=\"%s\";\n" "$(git config user.name)"
printf "const char rps_building_user_email[]=\"%s\";\n" $(git config user.email)
printf "const char rps_building_host[]=\"%s\";\n" $(/bin/uname -n)
printf "const char rps_building_operating_system[]=\"%s\";\n" $(/bin/uname -o)
printf "const char rps_building_opersysname[]=\"%s\";\n" $(/bin/uname -o | /bin/sed 's/[^A-Za-z0-9]/_/')
printf "const char rps_building_machine[]=\"%s\";\n" $(/bin/uname -m)
printf "const char rps_building_machname[]=\"%s\";\n" $(/bin/uname -m | /bin/sed 's/[^A-Za-z0-9]/_/')
printf "const char rps_plugin_builder[]=\"%s\";\n" $(realpath do-build-refpersys-plugin)
printf "const char rps_cxx_compiler_realpath[]=\"%s\";\n" $(realpath $CXX)
printf "const char rps_cxx_compiler_version[]=\"%s\";\n" "$($CXX --version | /bin/head -1)"
printf "const char rps_cxx_compiler_flags[]=\"%s\";\n" "$CXXFLAGS"
printf "const char rps_gpp_preprocessor_command[]=\"%s\";\n" $GPP
printf "const char rps_gpp_preprocessor_realpath[]=\"%s\";\n" $(realpath $GPP)
printf "const char rps_gpp_preprocessor_version[]=\"%s\";\n" "$($GPP --version | /bin/head -1)"
printf "/// see also GNUmakefile in %s for refpersys.org;\n" $PWD
printf "/// this is generated by %s in %s git %s\n" $0 $PWD $(./rps-generate-gitid.sh -s)
## end of file rps-generate-timestamp.sh