mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Jonathan Corbet <corbet@lwn.net>,
	Linux Doc Mailing List <linux-doc@vger.kernel.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	intel-wired-lan@lists.osuosl.org,
	linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, Randy Dunlap <rdunlap@infradead.org>,
	Shuah Khan <skhan@linuxfoundation.org>
Subject: [PATCH v4 39/41] docs: kdoc_output: pick a better default for modulename
Date: Sat, 31 Jan 2026 15:25:13 +0100	[thread overview]
Message-ID: <9bf76cd7412f49f0cf8628ceb3ebb2e1535d9d4c.1769867954.git.mchehab+huawei@kernel.org> (raw)
In-Reply-To: <cover.1769867953.git.mchehab+huawei@kernel.org>

Instead of placing the same data for modulename for all generated
man pages, use the directory from the filename used to produce
kernel docs as basis.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 tools/docs/kernel-doc                |  1 -
 tools/lib/python/kdoc/kdoc_output.py | 41 +++++++++++++++++-----------
 2 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/tools/docs/kernel-doc b/tools/docs/kernel-doc
index aed09f9a54dd..3a932f95bdf5 100755
--- a/tools/docs/kernel-doc
+++ b/tools/docs/kernel-doc
@@ -210,7 +210,6 @@ def main():
                         help="Enable debug messages")
 
     parser.add_argument("-M", "-modulename", "--modulename",
-                        default="Kernel API",
                         help="Allow setting a module name at the output.")
 
     parser.add_argument("-l", "-enable-lineno", "--enable_lineno",
diff --git a/tools/lib/python/kdoc/kdoc_output.py b/tools/lib/python/kdoc/kdoc_output.py
index 1e3dc47bc696..44e40a6e8ca6 100644
--- a/tools/lib/python/kdoc/kdoc_output.py
+++ b/tools/lib/python/kdoc/kdoc_output.py
@@ -589,7 +589,8 @@ class ManFormat(OutputFormat):
     ``modulename``
         Defines the module name to be used at the troff ``.TH`` output.
 
-        This argument is mandatory.
+        This argument is optional. If not specified, it will be filled
+        with the directory which contains the documented file.
 
     ``section``
         Usually a numeric value from 0 to 9, but man pages also accept
@@ -634,14 +635,21 @@ class ManFormat(OutputFormat):
         "%m %d %Y",
     ]
 
-    def emit_th(self, name):
+    def emit_th(self, name, args):
         """Emit a title header line."""
-        name = name.strip()
+        title = name.strip()
+        module = self.modulename(args)
 
-        self.data += f'.TH "{name}" {self.section} "{self.date}" '
-        self.data += f' "{self.modulename}" "{self.manual}"\n'
+        self.data += f'.TH "{title}" {self.section} "{self.date}" '
+        self.data += f' "{module}" "{self.manual}"\n'
 
-    def __init__(self, modulename, section="9", manual="Kernel API Manual"):
+    def modulename(self, args):
+        if self._modulename:
+            return self._modulename
+
+        return os.path.dirname(args.fname)
+
+    def __init__(self, modulename=None, section="9", manual="Kernel API Manual"):
         """
         Creates class variables.
 
@@ -651,7 +659,7 @@ class ManFormat(OutputFormat):
 
         super().__init__()
 
-        self.modulename = modulename
+        self._modulename = modulename
         self.section = section
         self.manual = manual
 
@@ -685,7 +693,8 @@ class ManFormat(OutputFormat):
         dtype = args.type
 
         if dtype == "doc":
-            return self.modulename
+            return name
+#            return os.path.basename(self.modulename(args))
 
         if dtype in ["function", "typedef"]:
             return name
@@ -762,7 +771,7 @@ class ManFormat(OutputFormat):
 
         out_name = self.arg_name(args, name)
 
-        self.emit_th(out_name)
+        self.emit_th(out_name, args)
 
         for section, text in args.sections.items():
             self.data += f'.SH "{section}"' + "\n"
@@ -772,7 +781,7 @@ class ManFormat(OutputFormat):
 
         out_name = self.arg_name(args, name)
 
-        self.emit_th(out_name)
+        self.emit_th(out_name, args)
 
         self.data += ".SH NAME\n"
         self.data += f"{name} \\- {args['purpose']}\n"
@@ -818,7 +827,7 @@ class ManFormat(OutputFormat):
     def out_enum(self, fname, name, args):
         out_name = self.arg_name(args, name)
 
-        self.emit_th(out_name)
+        self.emit_th(out_name, args)
 
         self.data += ".SH NAME\n"
         self.data += f"enum {name} \\- {args['purpose']}\n"
@@ -851,7 +860,7 @@ class ManFormat(OutputFormat):
         out_name = self.arg_name(args, name)
         full_proto = args.other_stuff["full_proto"]
 
-        self.emit_th(out_name)
+        self.emit_th(out_name, args)
 
         self.data += ".SH NAME\n"
         self.data += f"{name} \\- {args['purpose']}\n"
@@ -868,11 +877,11 @@ class ManFormat(OutputFormat):
             self.output_highlight(text)
 
     def out_typedef(self, fname, name, args):
-        module = self.modulename
+        module = self.modulename(args)
         purpose = args.get('purpose')
         out_name = self.arg_name(args, name)
 
-        self.emit_th(out_name)
+        self.emit_th(out_name, args)
 
         self.data += ".SH NAME\n"
         self.data += f"typedef {name} \\- {purpose}\n"
@@ -882,12 +891,12 @@ class ManFormat(OutputFormat):
             self.output_highlight(text)
 
     def out_struct(self, fname, name, args):
-        module = self.modulename
+        module = self.modulename(args)
         purpose = args.get('purpose')
         definition = args.get('definition')
         out_name = self.arg_name(args, name)
 
-        self.emit_th(out_name)
+        self.emit_th(out_name, args)
 
         self.data += ".SH NAME\n"
         self.data += f"{args.type} {name} \\- {purpose}\n"
-- 
2.52.0


  parent reply	other threads:[~2026-01-31 14:25 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-31 14:24 [PATCH v4 00/41] kernel-doc: make it parse new functions and structs Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 01/41] docs: kdoc_re: add support for groups() Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 02/41] docs: kdoc_re: don't go past the end of a line Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 03/41] docs: kdoc_parser: move var transformers to the beginning Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 04/41] docs: kdoc_parser: don't mangle with function defines Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 05/41] docs: kdoc_parser: add functions support for NestedMatch Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 06/41] docs: kdoc_parser: use NestedMatch to handle __attribute__ on functions Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 07/41] docs: kdoc_parser: fix variable regexes to work with size_t Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 08/41] docs: kdoc_parser: fix the default_value logic for variables Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 09/41] docs: kdoc_parser: add some debug for variable parsing Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 10/41] docs: kdoc_parser: don't exclude defaults from prototype Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 11/41] docs: kdoc_parser: fix parser to support multi-word types Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 12/41] docs: kdoc_parser: ignore context analysis and lock attributes Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 13/41] docs: kdoc_parser: add support for LIST_HEAD Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 14/41] docs: kdoc_parser: handle struct member macro VIRTIO_DECLARE_FEATURES(name) Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 15/41] docs: kdoc_re: properly handle strings and escape chars on it Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 16/41] docs: kdoc_re: better show KernRe() at documentation Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 17/41] docs: kdoc_re: don't recompile NestedMatch regex every time Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 18/41] docs: kdoc_re: Change NestedMath args replacement to \0 Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 19/41] docs: kdoc_re: make NestedMatch use KernRe Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 20/41] docs: kdoc_re: add support on NestedMatch for argument replacement Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 21/41] docs: kdoc_parser: better handle struct_group macros Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 22/41] docs: kdoc_re: fix a parse bug on struct page_pool_params Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 23/41] docs: kdoc_re: add a helper class to declare C function matches Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 24/41] docs: kdoc_parser: use the new CFunction class Mauro Carvalho Chehab
2026-01-31 14:24 ` [PATCH v4 25/41] docs: kdoc_parser: minimize differences with struct_group_tagged Mauro Carvalho Chehab
2026-01-31 14:25 ` [PATCH v4 26/41] docs: kdoc_parser: move transform lists to a separate file Mauro Carvalho Chehab
2026-01-31 14:25 ` [PATCH v4 27/41] docs: kdoc_re: don't remove the trailing ";" with NestedMatch Mauro Carvalho Chehab
2026-01-31 14:25 ` [PATCH v4 28/41] docs: kdoc_re: prevent adding whitespaces on sub replacements Mauro Carvalho Chehab
2026-01-31 14:25 ` [PATCH v4 29/41] docs: xforms_lists.py: use CFuntion to handle all function macros Mauro Carvalho Chehab
2026-01-31 14:25 ` [PATCH v4 30/41] docs: kdoc_files: allows the caller to use a different xforms class Mauro Carvalho Chehab
2026-01-31 14:25 ` [PATCH v4 31/41] docs: kdoc_re: Fix NestedMatch.sub() which causes PDF builds to break Mauro Carvalho Chehab
2026-01-31 14:25 ` [PATCH v4 32/41] docs: sphinx-build-wrapper: allow -v override -q Mauro Carvalho Chehab
2026-01-31 14:25 ` [PATCH v4 33/41] tools: sphinx-build-wrapper: improve its help message Mauro Carvalho Chehab
2026-01-31 14:25 ` [PATCH v4 34/41] docs: kdoc_files: document KernelFiles() ABI Mauro Carvalho Chehab
2026-01-31 14:25 ` [PATCH v4 35/41] docs: kdoc_output: add optional args to ManOutput class Mauro Carvalho Chehab
2026-01-31 14:25 ` [PATCH v4 36/41] docs: sphinx-build-wrapper: better handle troff .TH markups Mauro Carvalho Chehab
2026-01-31 14:25 ` [PATCH v4 37/41] docs: kdoc_output: use a more standard order for .TH on man pages Mauro Carvalho Chehab
2026-01-31 14:25 ` [PATCH v4 38/41] docs: kdoc_output: describe the class init parameters Mauro Carvalho Chehab
2026-01-31 14:25 ` Mauro Carvalho Chehab [this message]
2026-01-31 14:25 ` [PATCH v4 40/41] docs: python: add helpers to run unit tests Mauro Carvalho Chehab
2026-01-31 14:25 ` [PATCH v4 41/41] tools: unittests: add tests for kernel-doc NestedMatch and KernRe Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9bf76cd7412f49f0cf8628ceb3ebb2e1535d9d4c.1769867954.git.mchehab+huawei@kernel.org \
    --to=mchehab+huawei@kernel.org \
    --cc=corbet@lwn.net \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®