diff options
-rw-r--r-- | Makefile | 9 | ||||
-rwxr-xr-x | dlopen-notes.py | 42 | ||||
-rw-r--r-- | docs/dlopen-description.man | 11 | ||||
-rw-r--r-- | docs/dlopen-notes.1 | 38 |
4 files changed, 89 insertions, 11 deletions
@@ -1,7 +1,16 @@ all: +dlopen-notes.1: dlopen-notes.py docs/dlopen-description.man Makefile + argparse-manpage \ + --output=docs/$@ \ + --pyfile=$< \ + --function=make_parser \ + --project-name=package-notes \ + --include=docs/dlopen-description.man + install: install -m 755 -D dlopen-notes.py $(DESTDIR)/usr/bin/dlopen-notes + install -m 644 -D docs/dlopen-notes.1 $(DESTDIR)/usr/share/man/man1/dlopen-notes.1 check: make -C test check diff --git a/dlopen-notes.py b/dlopen-notes.py index 29ea270..7d1f4ec 100755 --- a/dlopen-notes.py +++ b/dlopen-notes.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: CC0-1.0 """\ -Read .note.dlopen notes from ELF files and report the contents +Read .note.dlopen notes from ELF files and report the contents. """ import argparse @@ -118,23 +118,43 @@ def group_by_feature(filenames, notes): return features -def parse_args(): - p = argparse.ArgumentParser(description=__doc__) - p.add_argument('--raw', +def make_parser(): + p = argparse.ArgumentParser( + description=__doc__, + allow_abbrev=False, + add_help=False, + epilog='If no option is specifed, --raw is the default.', + ) + p.add_argument('-r', '--raw', action='store_true', - help='show the original JSON extracted from input files') - p.add_argument('--sonames', + help='Show the original JSON extracted from input files') + p.add_argument('-s', '--sonames', action='store_true', - help='list all sonames and their priorities, one soname per line') - p.add_argument('--features', + help='List all sonames and their priorities, one soname per line') + p.add_argument('-f', '--features', nargs='?', const=[], type=lambda s: s.split(','), action='extend', metavar='FEATURE1,FEATURE2', - help='describe features, can be specified multiple times') - p.add_argument('filenames', nargs='+', metavar='filename') - return p.parse_args() + help='Describe features, can be specified multiple times') + p.add_argument('filenames', + nargs='+', + metavar='filename', + help='Library file to extract notes from') + p.add_argument('-h', '--help', + action='help', + help='Show this help message and exit') + return p + +def parse_args(): + args = make_parser().parse_args() + + if not args.raw and args.features is None and not args.sonames: + # Make --raw the default if no action is specified. + args.raw = True + + return args if __name__ == '__main__': args = parse_args() diff --git a/docs/dlopen-description.man b/docs/dlopen-description.man new file mode 100644 index 0000000..315f215 --- /dev/null +++ b/docs/dlopen-description.man @@ -0,0 +1,11 @@ +/report the contents/ +.PP +ELF binaries store link-time dependencies in their headers, which can be parsed +by various tools. There is no machine-readable metadata about dependencies +loaded at build time via +.BR \%dlopen (3) +available by default. The ELF Dlopen Metadata specification aims to fill this +gap, by defining a common format. +.PP +This tool allows parsing such a note, and printing out the result in various +formats. diff --git a/docs/dlopen-notes.1 b/docs/dlopen-notes.1 new file mode 100644 index 0000000..e86f6ba --- /dev/null +++ b/docs/dlopen-notes.1 @@ -0,0 +1,38 @@ +.TH DLOPEN\-NOTES.PY "1" "2024\-05\-22" "package\-notes" "Generated Python Manual" +.SH NAME +dlopen\-notes.py +.SH SYNOPSIS +.B dlopen\-notes.py +[-r] [-s] [-f [FEATURE1,FEATURE2]] [-h] filename [filename ...] +.SH DESCRIPTION +Read .note.dlopen notes from ELF files and report the contents. +.PP +ELF binaries store link-time dependencies in their headers, which can be parsed +by various tools. There is no machine-readable metadata about dependencies +loaded at build time via +.BR \%dlopen (3) +available by default. The ELF Dlopen Metadata specification aims to fill this +gap, by defining a common format. +.PP +This tool allows parsing such a note, and printing out the result in various +formats. + +.TP +\fBfilename\fR +Library file to extract notes from + +.SH OPTIONS +.TP +\fB\-r\fR, \fB\-\-raw\fR +Show the original JSON extracted from input files + +.TP +\fB\-s\fR, \fB\-\-sonames\fR +List all sonames and their priorities, one soname per line + +.TP +\fB\-f\fR \fI\,[FEATURE1,FEATURE2]\/\fR, \fB\-\-features\fR \fI\,[FEATURE1,FEATURE2]\/\fR +Describe features, can be specified multiple times + +.SH COMMENTS +If no option is specifed, \-\-raw is the default. |