Skip to content

Commit 7bbf06e

Browse files
authored
Merge pull request #1916 from ndim/document-elf2tag
Document elf2tag script
2 parents eec1a9b + f85a584 commit 7bbf06e

File tree

5 files changed

+273
-4
lines changed

5 files changed

+273
-4
lines changed

.github/workflows/check-sourcecode.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,21 @@ jobs:
2222

2323
- name: "Check the sourcecode"
2424
run: ./tools/check-sourcecode
25+
26+
check-generated:
27+
name: "Check Generated Files"
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
32+
- uses: actions/checkout@v4
33+
34+
- name: Install prerequisites
35+
run: >-
36+
sudo apt-get update
37+
38+
sudo apt-get install -y
39+
asciidoctor
40+
41+
- name: "Verify elf2tag.1 consistency"
42+
run: ./src/update-elf2tag-manpage --verify

src/elf2tag

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ for pgm in sort grep awk avr-objdump avr-nm; do
1010
hash $pgm 2>/dev/null || { echo "$progname: $pgm does not seem to be installed, exiting"; exit 1; }
1111
done
1212

13-
if [ "$1" == "" ]; then
14-
cat <<END
13+
case "$1" in
14+
"" | -h | --help )
15+
cat <<END
1516
Syntax: $progname <file>.elf
1617
Function: output a tagfile suitable for the avrdude disasm -t=<tagfile> command
1718
Options: none
1819
END
19-
exit 1
20-
fi
20+
exit 1
21+
;;
22+
esac
2123

2224
echo "# Automatically generated tagfile via ${progname} ${1}"
2325
avr-objdump -d "$1" | grep '<.*>:' | awk '{

src/elf2tag.1

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'\" t
2+
.\" Title: elf2tag
3+
.\" Author: [see the "AUTHOR(S)" section]
4+
.\" Generator: Asciidoctor 2.0.20
5+
.\" Date: 2024-11-23
6+
.\" Manual: avrdude Manual
7+
.\" Source: avrdude
8+
.\" Language: English
9+
.\"
10+
.TH "ELF2TAG" "1" "2024-11-23" "avrdude" "avrdude Manual"
11+
.ie \n(.g .ds Aq \(aq
12+
.el .ds Aq '
13+
.ss \n[.ss] 0
14+
.nh
15+
.ad l
16+
.de URL
17+
\fI\\$2\fP <\\$1>\\$3
18+
..
19+
.als MTO URL
20+
.if \n[.g] \{\
21+
. mso www.tmac
22+
. am URL
23+
. ad l
24+
. .
25+
. am MTO
26+
. ad l
27+
. .
28+
. LINKSTYLE blue R < >
29+
.\}
30+
.SH "NAME"
31+
elf2tag \- output a tagfile for the avrdude disasm command
32+
.SH "SYNOPSIS"
33+
.sp
34+
\fBelf2tag\fP <file.elf>
35+
.sp
36+
\fBelf2tag\fP [\fB\-h\fP | \fB\-\-help\fP]
37+
.SH "DESCRIPTION"
38+
.sp
39+
\fIelf2tag\fP generates a tagfile for use with the \fIavrdude disasm\fP command.
40+
.SH "OPTIONS"
41+
.sp
42+
\fB\-h\fP \fB\-\-help\fP
43+
.RS 4
44+
Prints the help message and exits.
45+
.RE
46+
.SH "EXAMPLES"
47+
.sp
48+
.if n .RS 4
49+
.nf
50+
.fam C
51+
$ elf2tag blink.elf > blink.tag
52+
$ avrdude \-qq \-c dryrun \-p m328p \-U blink.elf \-t
53+
avrdude> disasm \-t=blink.tag flash 0 512
54+
.fam
55+
.fi
56+
.if n .RE
57+
.SH "AUTHORS"
58+
.sp
59+
\fIelf2tag\fP was written by Johannes Bauer with small modifications by Stefan Rueger.
60+
.SH "SEE ALSO"
61+
.sp
62+
\fBavrdude(1)\fP, \fBavr\-nm(1)\fP, \fBavr\-objdump(1)\fP

src/elf2tag.1.adoc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
ELF2TAG(1)
2+
==========
3+
:doctype: manpage
4+
:man source: avrdude
5+
:man manual: avrdude Manual
6+
7+
NAME
8+
----
9+
10+
elf2tag - output a tagfile for the avrdude disasm command
11+
12+
SYNOPSIS
13+
--------
14+
15+
*elf2tag* <file.elf>
16+
17+
*elf2tag* [*-h* | *--help*]
18+
19+
DESCRIPTION
20+
-----------
21+
22+
_elf2tag_ generates a tagfile for use with the _avrdude disasm_ command.
23+
24+
OPTIONS
25+
-------
26+
27+
*-h* *--help*::
28+
Prints the help message and exits.
29+
30+
EXAMPLES
31+
--------
32+
33+
....
34+
$ elf2tag blink.elf > blink.tag
35+
$ avrdude -qq -c dryrun -p m328p -U blink.elf -t
36+
avrdude> disasm -t=blink.tag flash 0 512
37+
....
38+
39+
AUTHORS
40+
-------
41+
42+
_elf2tag_ was written by Johannes Bauer with small modifications by Stefan Rueger.
43+
44+
SEE ALSO
45+
--------
46+
47+
*avrdude(1)*, *avr-nm(1)*, *avr-objdump(1)*

src/update-elf2tag-manpage

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/usr/bin/env bash
2+
3+
# update-elf2tag-manpage - update the elf2tag.1 manpage from adoc source
4+
#
5+
# Usage:
6+
# ./path/to/update-elf2tag-manpage
7+
# ./path/to/update-elf2tag-manpage --verify
8+
#
9+
# Without a command line argument given, changes into the directory
10+
# where update-elf2tag-manpage and elf2tag.1.adoc are, runs
11+
# asciidoctor to produce a man page elf2tag.1 from elf2tag.1.adoc, but
12+
# only updates the elf2tag.1 file in the case of actual changes.
13+
#
14+
# Just the asciidoctor version or the current date being different
15+
# from the last asciidoctor run is not considered an actual change.
16+
#
17+
# With the --verify argument given, only verify that elf2tag.1 and
18+
# elf2tag.1.adoc are consistent with each other, i.e. elf2tag.1 would
19+
# not be changed.
20+
#
21+
# Requires asciidoctor to be installed.
22+
#
23+
# Environment variables used (if unset, uses the command from PATH):
24+
# ASCIIDOCTOR the asciidoctor command to run
25+
# CMP the cmp command to run (e.g. "busybox cmp")
26+
# DIFF the diff command to run with -u (used with --verify only)
27+
# SED the sed command to run (e.g. "busybox sed")
28+
29+
# This script uses the shell feature called "process substitution" which
30+
# is implemented by bash and busybox sh, but not by e.g. dash and can
31+
# therefore not be a /bin/sh script.
32+
33+
set -e
34+
35+
prog="$(basename "$0")"
36+
37+
if test "$#" -gt 1; then
38+
echo "$prog: Too many command line arguments"
39+
exit 2
40+
fi
41+
42+
verify=false
43+
if test "$#" -eq 1; then
44+
case "$1" in
45+
-h | --help )
46+
${SED-sed} -n '/^#\( .*\)$/,$p' "$0" \
47+
| ${SED-sed} '/^#\( .*\)\?$/!q' \
48+
| ${SED-sed} '/^$/d' \
49+
| ${SED-sed} 's|^#$||; s|^# ||'
50+
exit 0
51+
;;
52+
--verify )
53+
verify=:
54+
;;
55+
* )
56+
echo "$prog: Unhandled command line argument."
57+
exit 2
58+
;;
59+
esac
60+
fi
61+
62+
cd "$(dirname "$0")"
63+
64+
test -s elf2tag.1.adoc
65+
test -s elf2tag
66+
67+
# Usage: normalize_manpage original.1 normalized.1
68+
#
69+
# Normalizes a man page generated by asciidoctor by replacing data not
70+
# present in the sources such as generation date, asciidoctor version.
71+
normalize_manpage() {
72+
${SED-sed} -f <(cat<<EOF
73+
#s|^\.\\\\|==TITLE==|
74+
s|^\.\\\\" Generator: Asciidoctor .*|.\\" Generator: GENERATOR|
75+
s|^\.\\\\" Date: 20[0-9][0-9]-[0-1][0-9]-[0-3][0-9]|.\\" Date: DATE|
76+
s|^\.TH "ELF2TAG" "1" "20[0-9][0-9]-[0-1][0-9]-[0-3][0-9]" "avrdude" "avrdude Manual"|\.\\" TH HEADER|
77+
EOF
78+
) < "$1" > "$2"
79+
}
80+
81+
tmpdir="tmp$$"
82+
83+
if ! ${ASCIIDOCTOR-asciidoctor} -b manpage -D "$tmpdir" elf2tag.1.adoc; then
84+
echo "$prog: Error updating elf2tag.1"
85+
rm -rf "$tmpdir"
86+
exit 2
87+
fi
88+
89+
# Have sed ensure a trailing newline character by appending empty string
90+
#
91+
# This is necessary as asciidoctor likes to create files without a
92+
# trailing newline, while it is good form for text editors to add one.
93+
if ${SED-sed} '$a\' < "$tmpdir/elf2tag.1" > "$tmpdir/elf2tag.1.newline"; then
94+
mv -f "$tmpdir/elf2tag.1.newline" "$tmpdir/elf2tag.1"
95+
else
96+
echo "$prog: Error ensuring trailing newline character"
97+
rm -rf "$tmpdir"
98+
exit 2
99+
fi
100+
101+
if ! test -e elf2tag.1; then
102+
if "$verify"; then
103+
echo "$prog: Cannot ensure consistency if there is no old elf2tag.1 file"
104+
rm -rf "$tmpdir"
105+
exit 1
106+
fi
107+
echo "$prog: Generate elf2tag.1"
108+
mv -f "$tmpdir/elf2tag.1" elf2tag.1
109+
rmdir "$tmpdir"
110+
exit 0
111+
fi
112+
113+
normalize_manpage elf2tag.1 "$tmpdir/elf2tag.1.norm-old"
114+
normalize_manpage "$tmpdir/elf2tag.1" "$tmpdir/elf2tag.1.norm-new"
115+
116+
if ${CMP-cmp} "$tmpdir/elf2tag.1.norm-old" "$tmpdir/elf2tag.1.norm-new" > /dev/null; then
117+
echo "$prog: elf2tag.1 is up to date"
118+
rm -f "$tmpdir/elf2tag.1"
119+
rm -f "$tmpdir/elf2tag.1.norm-old"
120+
rm -f "$tmpdir/elf2tag.1.norm-new"
121+
rmdir "$tmpdir"
122+
exit 0
123+
fi
124+
125+
if "$verify"; then
126+
echo "$prog: Error: src/elf2tag.1 is inconsistent with src/elf2tag.1.adoc"
127+
${DIFF-diff} -u "$tmpdir/elf2tag.1.norm-old" "$tmpdir/elf2tag.1.norm-new" ||:
128+
rm -f "$tmpdir/elf2tag.1"
129+
rm -f "$tmpdir/elf2tag.1.norm-old"
130+
rm -f "$tmpdir/elf2tag.1.norm-new"
131+
rmdir "$tmpdir"
132+
exit 1
133+
fi
134+
135+
echo "Updating elf2tag.1"
136+
mv -f "$tmpdir/elf2tag.1" elf2tag.1
137+
rm -f "$tmpdir/elf2tag.1.norm-old"
138+
rm -f "$tmpdir/elf2tag.1.norm-new"
139+
rmdir "$tmpdir"
140+
exit 0

0 commit comments

Comments
 (0)