Skip to content

Commit 31ce2fc

Browse files
authored
Merge pull request #35 from keszybz/autogenerate-man-page
Autogenerate man page
2 parents 60127ce + 965dd69 commit 31ce2fc

4 files changed

Lines changed: 51 additions & 11 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
!/debian/rules
1212
!/debian/source/format
1313
__pycache__/
14+
/dlopen-notes.1

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
all:
22

3+
dlopen-notes.1: dlopen-notes.py docs/dlopen-description.man Makefile
4+
argparse-manpage \
5+
--output=$@ \
6+
--pyfile=$< \
7+
--function=make_parser \
8+
--project-name=package-notes \
9+
--include=docs/dlopen-description.man
10+
311
install:
412
install -m 755 -D dlopen-notes.py $(DESTDIR)/usr/bin/dlopen-notes
513

dlopen-notes.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: CC0-1.0
33

44
"""\
5-
Read .note.dlopen notes from ELF files and report the contents
5+
Read .note.dlopen notes from ELF files and report the contents.
66
"""
77

88
import argparse
@@ -118,23 +118,43 @@ def group_by_feature(filenames, notes):
118118

119119
return features
120120

121-
def parse_args():
122-
p = argparse.ArgumentParser(description=__doc__)
123-
p.add_argument('--raw',
121+
def make_parser():
122+
p = argparse.ArgumentParser(
123+
description=__doc__,
124+
allow_abbrev=False,
125+
add_help=False,
126+
epilog='If no option is specifed, --raw is the default.',
127+
)
128+
p.add_argument('-r', '--raw',
124129
action='store_true',
125-
help='show the original JSON extracted from input files')
126-
p.add_argument('--sonames',
130+
help='Show the original JSON extracted from input files')
131+
p.add_argument('-s', '--sonames',
127132
action='store_true',
128-
help='list all sonames and their priorities, one soname per line')
129-
p.add_argument('--features',
133+
help='List all sonames and their priorities, one soname per line')
134+
p.add_argument('-f', '--features',
130135
nargs='?',
131136
const=[],
132137
type=lambda s: s.split(','),
133138
action='extend',
134139
metavar='FEATURE1,FEATURE2',
135-
help='describe features, can be specified multiple times')
136-
p.add_argument('filenames', nargs='+', metavar='filename')
137-
return p.parse_args()
140+
help='Describe features, can be specified multiple times')
141+
p.add_argument('filenames',
142+
nargs='+',
143+
metavar='filename',
144+
help='Library file to extract notes from')
145+
p.add_argument('-h', '--help',
146+
action='help',
147+
help='Show this help message and exit')
148+
return p
149+
150+
def parse_args():
151+
args = make_parser().parse_args()
152+
153+
if not args.raw and args.features is None and not args.sonames:
154+
# Make --raw the default if no action is specified.
155+
args.raw = True
156+
157+
return args
138158

139159
if __name__ == '__main__':
140160
args = parse_args()

docs/dlopen-description.man

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/report the contents/
2+
.PP
3+
ELF binaries store link-time dependencies in their headers, which can be parsed
4+
by various tools. There is no machine-readable metadata about dependencies
5+
loaded at build time via
6+
.BR \%dlopen (3)
7+
available by default. The ELF Dlopen Metadata specification aims to fill this
8+
gap, by defining a common format.
9+
.PP
10+
This tool allows parsing such a note, and printing out the result in various
11+
formats.

0 commit comments

Comments
 (0)