The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Chen Miao <chenmiao.ku@gmail.com>
To: corbet@lwn.net, alexs@kernel.org, si.yanteng@linux.dev,
	skhan@linuxfoundation.org, dzm91@hust.edu.cn, mchehab@kernel.org,
	wy@wyuan.org
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Chen Miao <chenmiao.ku@gmail.com>
Subject: [PATCH v2 3/5] docs: sphinx-build-wrapper: prefer gmake
Date: Mon, 10 Aug 2026 22:33:07 +0800	[thread overview]
Message-ID: <20260810143311.57775-4-chenmiao.ku@gmail.com> (raw)
In-Reply-To: <20260810143311.57775-1-chenmiao.ku@gmail.com>

Homebrew installs GNU Make as gmake on macOS, but the Sphinx build
wrapper invokes make directly when generating Info and Rust
documentation. This can make the dependency check succeed while those
documentation targets still use an incompatible make implementation.

Honor MAKE when it names a compatible GNU Make. Otherwise check gmake
and then make, selecting the first GNU Make 4.0 or newer. This keeps the
wrapper's selection consistent with sphinx-pre-install.

Signed-off-by: Chen Miao <chenmiao.ku@gmail.com>
---
 tools/docs/sphinx-build-wrapper | 55 ++++++++++++++++++++++++++++-----
 1 file changed, 48 insertions(+), 7 deletions(-)

diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrapper
index 1bb962202..aa6a297db 100755
--- a/tools/docs/sphinx-build-wrapper
+++ b/tools/docs/sphinx-build-wrapper
@@ -71,6 +71,7 @@ from jobserver import JobserverExec         # pylint: disable=C0413,C0411,E0401
 #
 VENV_DEFAULT = "sphinx_latest"
 MIN_PYTHON_VERSION = PythonVersion("3.7").version
+MIN_MAKE_VERSION = PythonVersion("4.0").version
 PAPER = ["", "a4", "letter"]
 
 TARGETS = {
@@ -97,6 +98,46 @@ class SphinxBuilder:
     with the Kernel.
     """
 
+    @staticmethod
+    def get_make_version(cmd):
+        """Return the GNU Make version, or None for another make."""
+        if not cmd:
+            return None
+
+        try:
+            result = subprocess.run(
+                [cmd, "--version"],
+                stdout=subprocess.PIPE,
+                stderr=subprocess.PIPE,
+                text=True,
+                check=True,
+            )
+        except (OSError, subprocess.CalledProcessError):
+            return None
+
+        match = re.search(
+            r"^GNU Make\s+([0-9]+(?:\.[0-9]+)*)", result.stdout, re.MULTILINE
+        )
+        if not match:
+            return None
+
+        return PythonVersion.parse_version(match.group(1))
+
+    def get_make(self):
+        """Select the first GNU Make 4.0 or newer in preference order."""
+        candidates = [
+            self.env.get("MAKE"),
+            shutil.which("gmake"),
+            shutil.which("make"),
+        ]
+
+        for cmd in candidates:
+            version = self.get_make_version(cmd)
+            if version and version >= MIN_MAKE_VERSION:
+                return cmd
+
+        sys.exit("GNU Make 4.0 or newer is required")
+
     def get_path(self, path, use_cwd=False, abs_path=False):
         """
         Ancillary routine to handle patches the right way, as shell does.
@@ -569,9 +610,10 @@ class SphinxBuilder:
         texinfo directory.
         """
 
+        make = self.get_make()
         for output_dir in output_dirs:
             try:
-                subprocess.run(["make", "info"], cwd=output_dir, check=True)
+                subprocess.run([make, "info"], cwd=output_dir, check=True)
             except subprocess.CalledProcessError as e:
                 sys.exit(f"Error generating info docs: {e}")
 
@@ -787,12 +829,11 @@ class SphinxBuilder:
 
         if rustdoc and target in ["htmldocs", "epubdocs"]:
             print("Building rust docs")
-            if "MAKE" in self.env:
-                cmd = [self.env["MAKE"]]
-            else:
-                cmd = ["make", "LLVM=1"]
-
-            cmd += [ "rustdoc"]
+            make = self.get_make()
+            cmd = [make]
+            if make != self.env.get("MAKE"):
+                cmd.append("LLVM=1")
+            cmd.append("rustdoc")
             if self.verbose:
                 print(" ".join(cmd))
 
-- 
2.50.1 (Apple Git-155)


  parent reply	other threads:[~2026-08-10 14:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-10 14:33 [PATCH v2 0/5] docs: sphinx-pre-install: improve dependency checks Chen Miao
2026-08-10 14:33 ` [PATCH v2 1/5] docs: sphinx-pre-install: add macOS Homebrew support Chen Miao
2026-08-10 19:56   ` Mauro Carvalho Chehab
2026-08-10 14:33 ` [PATCH v2 2/5] docs: sphinx-pre-install: check GNU Make version Chen Miao
2026-08-10 14:33 ` Chen Miao [this message]
2026-08-10 14:33 ` [PATCH v2 4/5] docs/zh_CN: doc-guide: document macOS Sphinx setup Chen Miao
2026-08-10 14:33 ` [PATCH v2 5/5] docs/zh_CN: how-to: document case-sensitive APFS setup Chen Miao

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=20260810143311.57775-4-chenmiao.ku@gmail.com \
    --to=chenmiao.ku@gmail.com \
    --cc=alexs@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dzm91@hust.edu.cn \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=si.yanteng@linux.dev \
    --cc=skhan@linuxfoundation.org \
    --cc=wy@wyuan.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