Xen does not currently document how to build the hypervisor on macOS, and
there is no Darwin configuration for a Homebrew-based toolchain. In
addition, the Makefile silent-mode detection can be tripped by -I paths
that contain an "s", which hides build commands unexpectedly.

Add a minimal Darwin configuration, document the Homebrew toolchain and
PATH setup (including prefix differences and an out-of-tree example), and
clarify that the guide is tested on arm64. Tighten silent-mode detection
to only look at the short option word.

Functional impact: The Xen hypervisor can be cross-built on macOS (arm64)
with the documented Homebrew toolchain, and make output is no longer forced
silent by --include-dir paths.

Signed-off-by: Bertrand Marquis <[email protected]>
---
This patch does not intent to say that building on mac os is supported
but it can be helpful for people developing on mac os (I have been using
that for a while) and is solving a Makefile issue that could be hit by
others in other environments.
The doc file is quick attempt to document that for others, happy to get
comments from others to find out if they think this is useful or not or
if this should not be documented there.
---
 config/Darwin.mk            |  4 +++
 docs/misc/build-on-macos.md | 66 +++++++++++++++++++++++++++++++++++++
 xen/Makefile                |  2 +-
 3 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 config/Darwin.mk
 create mode 100644 docs/misc/build-on-macos.md

diff --git a/config/Darwin.mk b/config/Darwin.mk
new file mode 100644
index 000000000000..64a1dfcb42ed
--- /dev/null
+++ b/config/Darwin.mk
@@ -0,0 +1,4 @@
+include $(XEN_ROOT)/config/StdGNU.mk
+
+# We are always cross compiling so fake COMPILE_ARCH
+XEN_COMPILE_ARCH = Darwin
diff --git a/docs/misc/build-on-macos.md b/docs/misc/build-on-macos.md
new file mode 100644
index 000000000000..6b56cd8eccab
--- /dev/null
+++ b/docs/misc/build-on-macos.md
@@ -0,0 +1,66 @@
+# Building Xen Hypervisor on macOS
+
+This guide explains how to cross-compile the Xen hypervisor (xen
+subdirectory only) on macOS. This does **not** build the tools.
+
+## Prerequisites
+
+Install the following packages using Homebrew:
+
+```bash
+# Cross-compilation toolchain for ARM64
+brew install aarch64-elf-gcc
+
+# GNU tools (required for compatibility)
+brew install make gnu-sed
+```
+
+Homebrew installs under `/opt/homebrew` on Apple Silicon and `/usr/local` on
+Intel Macs. Adjust paths below accordingly.
+
+### Verification
+
+Verify your installation:
+
+```bash
+# Check cross compiler
+aarch64-elf-gcc --version
+
+# Check GNU make (adjust prefix if needed)
+/opt/homebrew/opt/make/libexec/gnubin/make --version
+
+# Check GNU sed (adjust prefix if needed)
+/opt/homebrew/opt/gnu-sed/libexec/gnubin/sed --version
+```
+
+## Building the Hypervisor
+
+Set up GNU tools in PATH and build:
+
+```bash
+# Set up GNU tools in PATH (adjust prefix if needed)
+export 
PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/opt/make/libexec/gnubin:$PATH"
+
+# Build Xen hypervisor only (in-tree)
+cd xen/
+make XEN_TARGET_ARCH=arm64 CROSS_COMPILE=aarch64-elf- HOSTCC=gcc
+
+# Optional: out-of-tree build directory
+# make XEN_TARGET_ARCH=arm64 CROSS_COMPILE=aarch64-elf- HOSTCC=gcc 
O=$PWD/build-mac
+```
+
+## Architecture Support
+
+Currently supported architectures:
+
+- **ARM64** (`arm64`) - Default, uses `aarch64-elf-gcc`
+
+Other targets may work if the corresponding cross toolchain is installed,
+but this guide has only been tested on ARM64.
+
+## Limitations
+
+- **Hypervisor only**: This only builds the Xen hypervisor, not the tools
+- **Cross-compilation only**: Native builds are not supported
+- **macOS-specific**: Instructions optimized for macOS with Homebrew
+- **GNU tools required**: Native BSD tools are not compatible
diff --git a/xen/Makefile b/xen/Makefile
index 13e336ba5484..adeb869f32ad 100644
--- a/xen/Makefile
+++ b/xen/Makefile
@@ -116,7 +116,7 @@ endif
 # If the user is running make -s (silent mode), suppress echoing of
 # commands
 
-ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
+ifneq ($(findstring s,$(firstword $(MAKEFLAGS))),)
     quiet := silent_
 endif
 
-- 
2.52.0


Reply via email to