Debian Codegraph @

ckubuildlog

raw
1 #!./wermit +
2 # CKUBUILDLOG C-Kermit script for UNIX-based operating systems
3 # Frank da Cruz, [email protected], Bronx
4 # and Peter Eichhorn, Munich
5 # 5 June 2023
6 # Most recent update:
7 # Sun Sep 24 10:00:17 2023
8 #
9 .version = 2.15 # Version
10 .verdate = 2023/09/24 # Date of version
11
12 # (v2.10 fixes reporting of OpenSSL version)
13 # (v2.11 fixes reporting of Kerberos version)
14 # (V2.12 tries harder to find compiler name and version)
15 # (V2.13 put "No warnings" in last field if there were no warnings)
16 # (V2.14 Don't "copy /append" on Macintosh - it clobbers the original file)
17 # (V2.15 Undoes previous change and fixes a syntax error in:
18 # .tmpcc := \fcommand(strings wermit | egrep -i "(cc |gcc|clang)")
19 # (final paren was missing) and adds support for SunOS and Solaris
20 #
21 set debug message off # Use -v on command line to turn on
22
23 # This script is distributed with C-Kermit source-code and is to be used
24 # on Unix-based platforms (e.g. Linux, BSD, macOS) after compilation and
25 # linking to produce a table entry for C-Kermit build log.
26 #
27 # Example of use (cd'd to C-Kermit source code directory, which must
28 # include C-Kermit sources and 'wermit' executable.
29 #
30 # make linux 2>log
31 # (compilation and linking occurs, producing a 'wermit' executable...)
32 # ./ckubuildlog
33 #
34 # This produces an xxx.txt file in the same directory, where xxx is the
35 # makefile target ("linux" in this example).
36 #
37 # You don't have to install the script, it comes with C-Kermit 10.0.
38 #
39 # Usage: ckubuildlog [ parameters ]
40 # For parameters see: https://www.kermitproject.org/ckbuildlog.html
41 #
42 # Examples (in the C-Kermit build directory):
43 # ./ckubuildlog (let the script try to figure the OS name a version)
44 # ./ckubuildlog "NetBSD 9.3" (provide hostname and version to the script)
45 #
46 # Creates a C-Kermit 10.0 Beta test builds-table entry to be sent
47 # to me for inclusion in https://kermitproject.org/ck10devbuilds.html.
48 #
49 # For compiler warnings to be included, C-Kermit must be built like this:
50 #
51 # cd ckermit (cd to your C-Kermit source code directory)
52 # rm -f log (remove any previous log)
53 # make targetname 2>log (log warnings and errors to file named 'log')
54 #
55 # (note: if you use a name other than 'log' you have to specify it
56 # on the ckubuildlog command line, e.g. 'ckubuildlog logfile=build7.log')
57 #
58 # C-Kermit build examples:
59 #
60 # make linux 2>log (default Linux build)
61 # make linux+ssl 2>log (Linux with OpenSSL)
62 # make linux+krb5 2>log (Linux with MIT Kerberos 5)
63 # make linux+krb5+ssl 2>log (Linux with MIT Kerberos 5 and OpenSSL)
64 # make netbsd 2>log (default NetBSD build)
65 #
66 # Note: optional 'make' parameters as in 'make linux KFLAGS="-DNODEBUG"'
67 # are not captured by this script but you can specify them on the
68 # ckubuildlog command line.
69 #
70 # osname-and-version:
71 # There is no standard Unix shell command or utility that returns the
72 # computer's operating-system name and version. In some cases C-Kermit
73 # (which is executing this script) can find the OS name and version on its
74 # own, in which case they will be in one or more of the following built-in
75 # C-Kermit variables:
76 #
77 # \v(osname)
78 # \v(osversion)
79 # \v(osrelease)
80 # \v(platform)
81 #
82 # In other cases, for selected OS's, this script's GETOSNAME macro can find
83 # them somewhere in the /etc/*release* or other directories. As a last
84 # resort, you can simply provide the OS name and version as a command-line
85 # parameter, e.g.:
86 #
87 # ckubuildlog "MINIX 3"
88 # ckubuildlog "Solaris 11"
89 # ckubuildlog "HP-UX 10.0"
90 # ckubuildlog "4.2BSD"
91 #
92 # GETOSNAME clauses for additional platforms are welcome.
93 # Note: string comparisons in this script are case-independent
94 #
95 if not equ "\v(system)" "UNIX" {
96 exit 1 "Sorry, ckubuildlog only works in UNIX-based operating systems"
97 }
98 undef osname # Clear the OS name
99 undef resultfile # Clear result-file name
100 undef kflags # Clear KFLAGS
101 undef logfile # Clear compilation log file name
102 undef ccdata # Clear C compiler data
103 .\%n = 0 # Command-line parameter counter
104
105 if debug show args
106
107 while def \%1 { # Get parameters from command line
108 incr \%n
109 msg LOOP \%n "\%1"
110 if equ "\%1" "-h" { # -h = help
111 msg HELP TEXT
112 echo
113 echo {Usage: ckubuildlog [-v] [-h] ["OS name and version"]}
114 echo " -v = verbose; -h = help (this message)"
115 echo { also: resultfile=filename, logfile=filename, -
116 kflags="-Dxxxx [-Dyyyy ...]"}
117 echo " All command-line options are optional."
118 echo " Order doesn't matter."
119 echo " Options that contain spaces must be enclosed in doublequotes."
120 echo
121 echo "Instructions:"
122 echo " cd to the C-Kermit source directory."
123 echo { Build C-Kermit with "make xxxx 2>log"}
124 echo { where xxxx is the target from the makefile, e.g. 'linux'.}
125 echo { '2>log' puts any warnings or errors in a filed named 'log'}
126 echo { Example: 'make linux 2>log'}
127 echo { Then run this script, supplying OS and version if necessary.}
128 echo { Examples:}
129 echo
130 echo { ckubuildlog}
131 echo { ckubuildlog "SunOS 4"}
132 echo { ckubuildlog "HP-UX B10.20"}
133 echo
134 echo { The results are in the same directory as xxx.txt,}
135 echo { where xxx is the make target name; e.g. linux.txt}
136 echo { or, if 'resultfile=xxx' was given, in the file named xxx},
137 echo { where xxx is a name of your choice.}
138 echo
139 exit
140 }
141 if equ "\%1" "-v" { # -v = verbose
142 echo SET DEBUG MESSAGE ON
143 set debug message on
144 shift
145 continue
146 }
147 if \findex(=,\%1) { # Keyword parameter
148 msg KEYWORD FROM COMMAND LINE = '\%1'
149 void \fkeywordvalue(\%1); # Get keyword and its value
150 shift
151 continue
152 } else if def \%1 {
153 msg OSNAME FROM COMMAND LINE = '\%1'
154 .osname := \%1 # OS name & version from command line
155 shift
156 continue
157 }
158 }
159 # Macro to get OS name and version for selected OS's; others can be added.
160 # WARNING: This requires C-Kermit to have BIGBUFOK defined in ckcdeb.h.
161 #
162 #if def osname forward :SKIPOSNAME
163
164 define GETOSNAME {
165 # Macintosh
166 if ( match "\v(platform)" "mac*" || match "\v(platform)" "*OS_X*" ) {
167 .osname := \freplace(\v(platform),_,\32)
168 return
169 }
170 if exist /etc/release { # NetBSD...
171 .name := \fcommand(grep NetBSD /etc/release | head -1)
172 if def name {
173 void \fsplit(\m(name),&a,\32/)
174 .osname := \&a[1] \&a[2]
175 return
176 }
177 }
178 if not exist /etc/oracle-release {
179 # Oracle has redhat-release AND oracle-release
180 if exist /etc/redhat-release { # Ret Hat Enterprise Linux
181 .name := \fcommand(grep "Red Hat" /etc/redhat-release | head -1)
182 if def name {
183 void \fsplit(\m(name),&a,\32)
184 .osname := RHEL \&a[7]
185 return
186 }
187 }
188 }
189 if exist /etc/fedora-release { # Fedora Linux
190 .name := \fcommand(grep "Fedora" /etc/fedora-release | head -1)
191 if def name {
192 .osname := Fedora \fword(\m(name),3)
193 return
194 }
195 }
196 if \findex(HP-UX,\v(osname)) { # HP-UX
197 local hpccdata &x &y
198 .osname := HP-UX \v(osrelease)
199 .hpccdata := \fcommand(what `whence cc`)
200 if debug show mac hpccdata
201 void \fsplit(\m(hpccdata),&x,$)
202 void \fsplit(\&x[5],&y,\32)
203 .ccdata := HP C Compiler \&y[2]
204 if debug show mac ccdata
205 return
206 }
207 if match \v(platform) SunOS* { # SunOS
208 .osname := \v(osname) \v(osrelease)
209 return
210 } else if match \v(platform) Solaris* { # Solaris
211 .osname := \v(osname) \v(osrelease)
212 return
213 }
214 if match \v(platform) OpenBSD* { # OpenBSD
215 .osname := \freplace(\v(platform),_,\32)
216 return
217 }
218 if equ \v(platform) Linux { # Common Linux distributions
219 # Centos, Debian, Fedora, Oracle, Red Hat, Rocky, SUSE, ...
220 if exist /etc/os-release {
221 .osname := \fcommand(grep "PRETTY_NAME" /etc/os-release)
222 if def osname {
223 .osname := \fword(\m(osname),2,\")
224 } else {
225 .osname := \fcommand(grep "NAME=" /etc/os-release)
226 if def osname {
227 .osname := \fword(\m(osname),2,\")
228 .osversion := \fcommand(grep "VERSION-ID=" /etc/os-release)
229 .osname := \m(osname) \m(osversion)
230 }
231 }
232 if def osname return
233 }
234 }
235 }
236 :SKIPOSNAME
237
238 echo ckubuildlog \m(version) \m(verdate)
239 echo "This directory: \v(dir)" # Orientation
240
241 if not def osname getosname # Get OS name if not passed on cmdline
242
243 # Check for makefile
244 if not exist makefile exit 1 "makefile not found in \v(dir)"
245
246 dir /array:x /count:filecount ck*.[ch]
247 if not exist ckcmai.c {
248 echo "Error: ckcmai.c not found in \v(dir)"
249 exit 1 "This script must be run in the C-Kermit build directory"
250 }
251 if < \m(filecount) 54 {
252 echo "Warning: some C-Kermit source code files seem to be missing"
253 }
254 undeclare x
255 msg C-Kermit source files found.
256
257 # Check whether C-Kermit binary (wermit) exists
258 if not exist ./wermit {
259 echo 'wermit' binary not found in \v(dir).
260 exit 1 "Please give an appropriate 'make' command to build C-Kermit"
261 }
262 # Run wermit to get SHOW FEATURES listing into a file
263 void \fcommand(./wermit -C "show features" > shofeat.txt, exit)
264 if fail exit 1 "wermit SHOW FEATURES failed"
265 msg Feature list ok:
266 if debug dir shofeat.txt
267 void \fcommand(grep BIGBUFOK shofeat.txt)
268 if fail {
269 echo WARNING: BIGBUFOK not defined in this C-Kermit build
270 echo Some operations might fail
271 }
272 # Makefile target...
273 undef target
274 .target := \fword(\fcommand(grep Target: shofeat.txt),2,\32,ALL)
275 if not def target { exit 1 "Target not found in shofeat.txt" }
276 if debug sho mac target
277
278 # Check whether the build failed
279 .failed = 0
280 if not exist wermit {
281 echo "MOST RECENT BUILD FAILED - wermit binary not found"
282 .failed = 1 # the build build failed
283 forward :ARCH
284 }
285 # Build failed but previous wermit still exists
286 if exist log {
287 if newer log wermit {
288 echo "MOST RECENT BUILD FAILED - wermit binary older than log"
289 if exist log echo "See log for errors"
290 .failed = 1
291 forward :ARCH
292 }
293 }
294 # Check whether wermit binary is newer than all the source code modules
295 dir /sort:date /reverse /top:1 /array:o ck*.[ch]
296 if newer \&o[1] wermit {
297 echo "Error: some source modules are newer than the wermit executable..."
298 exit 1 "Please rebuild C-Kermit and run this script again."
299 }
300 # Check object files
301 if \ffiles(ck*.o) {
302 dir /sort:date /reverse /top:1 /array:o ck*.o
303 if newer \&o[1] wermit {
304 echo {'make' command failed - Object file(s) are newer than wermit.}
305 echo {This probably means that the most recent 'make' command failed.}
306 exit 1
307 }
308 }
309 undeclare o
310
311 .banner := \fcommand(grep "C-Kermit " shofeat.txt | grep for)
312 if def banner {
313 echo wermit: \m(banner)
314 }
315 if failed { # If the build failed...
316 .size = N/A
317 } else {
318 msg wermit executable found and up-to-date.
319 if debug dir wermit
320 .size := \fsize(wermit)
321 if not numeric \m(size) .size = (unknown)
322 }
323 msg Size: \m(size) bytes
324
325 # Architecture...
326 :ARCH
327 undef arch
328 .arch := \fword(\fcommand(grep Machine: shofeat.txt),2,\32)
329 if debug sho mac arch
330
331 .maxnamelen := 72
332 if not def osname {
333 .tmpname := \fcommand(grep "OS Version:" shofeat.txt)
334 .dots =
335 if > \flen(\m(tmpname)) \m(maxnamelen) .dots := ...
336 .osname := \s(tmpname[14:\m(maxnamelen)])\m(dots)
337 if debug sho mac osname
338 }
339 # Kermit code date from ckcmai.c
340 undef codedate
341 .tmpdate := \fcommand(grep EDITNDATE ckcmai.c | head -1)
342 void \fsplit(\m(tmpdate),&a)
343 # show array a
344 .codedate := \fleft(\freplace(\fcvtdate(\&a[3],5),:,-),10)
345 if debug show mac codedate
346
347 # Look for compiler name and version
348 .maxcclen := 72
349 undef cc
350 .\%c = 0
351 .tag := "GCC version:"
352 .tmpcc := \fcommand(grep "\m(tag)" shofeat.txt)
353 # NOTE: can also look for __DECC and __DECC_VER in shofeat.txt.
354 if def tmpcc {
355 .\%c = 1
356 } else {
357 .tag = "Compiler version:"
358 .tmpcc := \fcommand(grep "\m(tag)" shofeat.txt)
359 if def tmpcc {
360 .\%c = 2
361 } else if def ccdata {
362 .\%c = 3
363 .tmpcc := \m(ccdata)
364 } else {
365 .tmpcc := \fcommand(strings wermit | egrep -i "(cc |gcc|clang)")
366 if def tmpcc .\%c = 4
367 else .tmpcc = "(unknown)"
368 }
369 }
370 if def tmpcc {
371 .tmpcc := \freplace(\m(tmpcc),{Compiler version: },)
372 }
373 msg tmpcc[\%c] = \m(tmpcc)
374 if > \%c 0 {
375 .dots =
376 .tmpcc := \fltrim(\freplace(\m(tmpcc),GCC version:,))
377 if numeric \s(tmpcc[1.]) .tmpcc := gcc \m(tmpcc)
378 # .tmpcc := \fltrim(\freplace(\m(tmpcc),\m(tag),))
379 if not \fverify(0123456789.,\m(tmpcc)) .tmpcc := "gcc \m(tmpcc)"
380 if debug show mac tmpcc
381 if > \flen(\m(tmpcc)) \m(maxcclen) .dots := ...
382 .cc := \m(tmpcc)\m(dots)
383 }
384 if debug sho mac cc
385
386 .security =
387 .ssl =
388 if \findex(ssl,\m(target)) {
389 .ssl := \fcommand(openssl version)
390 .security := \m(ssl)
391 }
392 .krb5 =
393 if \findex(krb5,\m(target)) {
394 .krb5 := \fcommand(krb5-config --version)
395 .security := \m(security) \m(krb5)
396 }
397 .tmpsecurity := \m(security)
398 if not def security .tmpsecurity = (none)
399 msg Security: \m(tmpsecurity)
400 if failed {
401 .status = Failed
402 } else {
403 .status = OK
404 }
405 if not def resultfile .resultfile := \m(target).txt
406 if not def logfile .logfile := log
407 fopen /write \%o \m(resultfile)
408 if fail exit 1 Can't create \m(target).txt
409 fwrite /line \%o <tr>
410 fwrite /line \%o <td>\m(osname)
411 fwrite /line \%o <td>\m(arch)
412 if def kflags {
413 .kflags := KFLAGS="\m(kflags)"
414 }
415 fwrite /line \%o <td>make \m(target) \m(kflags)
416 fwrite /line \%o <td>\m(codedate)
417 fwrite /line \%o <td>\m(size)
418 fwrite /line \%o <td>\m(cc)
419 fwrite /line \%o <td>\m(security)
420 fwrite /line \%o <td>\m(status)
421
422 echo Executable:
423 dir wermit
424 if def logfile {
425 if not exist \m(logfile) {
426 echo "No log file found - if there were warnings or errors,"
427 xecho "please 'make clean' and then rebuild with "
428 echo "'make \m(target) 2> log', thanks."
429 } else if > \fsize(\m(logfile)) 0 {
430 echo "(there were some warnings or errors):"
431 dir \m(logfile)
432 fwrite \%o <td>
433 fclose \%o
434 copy /append \m(logfile) \m(resultfile)
435 } else {
436 fwrite /line \%o <td>No warnings
437 }
438 }
439 if \f_status(\%o) fclose \%o
440 echo ckubuildlog done, result (please email it to [email protected]):
441 dir \m(resultfile)
442 type \m(resultfile)
443
444 exit
445
446 ; Local Variables:
447 ; comment-column:40
448 ; comment-start:"# "
449 ; End: