mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Cc: linux-kernel@vger.kernel.org,
	Masahiro Yamada <masahiroy@kernel.org>,
	Arnd Bergmann <arnd@arndb.de>, Willy Tarreau <w@1wt.eu>
Subject: [RFC PATCH 3/3] tools/nolibc: add a new "install_all_archs" target
Date: Fri, 20 Jun 2025 12:37:05 +0200	[thread overview]
Message-ID: <20250620103705.10208-4-w@1wt.eu> (raw)
In-Reply-To: <20250620103705.10208-1-w@1wt.eu>

This installs all supported archs together, both from nolibc and kernel
headers. The arch-specific asm/ subdirs are renamed to asm-arch-$arch,
and asm/ is rebuilt from all these files in order to include the right
one depending on the build architecture.

This allows to use a single unified sysroot for all archs, and to only
change the compiler or the target architecture. This way, a complete
sysroot is much easier to use (a single directory is needed) and much
smaller.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 tools/include/nolibc/Makefile | 39 +++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
index 8de6ac5cec425..b6ed11d0b5419 100644
--- a/tools/include/nolibc/Makefile
+++ b/tools/include/nolibc/Makefile
@@ -88,6 +88,7 @@ help:
 	@echo "  headers_all_archs   prepare a multi-arch sysroot in \$${OUTPUT}sysroot"
 	@echo "  headers_standalone  like \"headers\", and also install kernel headers"
 	@echo "  help                this help"
+	@echo "  install_all_archs   install a multi-arch sysroot + kernel headers in \$${OUTPUT}sysroot"
 	@echo ""
 	@echo "These targets may also be called from tools as \"make nolibc_<target>\"."
 	@echo ""
@@ -120,6 +121,44 @@ headers_all_archs:
 	$(Q)cp --parents $(all_files) arch.h "$(OUTPUT)sysroot/include/"
 	$(Q)cp $(addsuffix .h,$(addprefix arch-,$(nolibc_supported_archs))) "$(OUTPUT)sysroot/include/"
 
+install_all_archs: headers_all_archs
+	@# install common headers for any arch, take them all. This will clear everything.
+	$(Q)$(MAKE) -C $(srctree) ARCH=x86 mrproper
+	$(Q)$(MAKE) -C $(srctree) ARCH=x86 headers_install no-export-headers= INSTALL_HDR_PATH="$(OUTPUT)sysroot"
+	@# remove the contents of the unused asm dir which we will rebuild from the arch ones
+	$(Q)rm -rf "$(OUTPUT)sysroot/include/asm"
+	$(Q)mkdir -p "$(OUTPUT)sysroot/include/asm"
+	@# Now install headers for all archs
+	$(Q)for arch in $(patsubst aarch64,arm64,$(nolibc_supported_archs)); do \
+		echo "# installing $$arch"; \
+		if ! [ -d $(OUTPUT)sysroot/include/asm-arch-$$arch ]; then \
+			$(MAKE) -C $(srctree) ARCH=$$arch mrproper; \
+			$(MAKE) -C $(srctree) ARCH=$$arch headers_install no-export-headers= \
+				INSTALL_HDR_PATH="$(OUTPUT)sysroot/include/$$arch" >/dev/null; \
+			mv "$(OUTPUT)sysroot/include/$$arch/include/asm" "$(OUTPUT)sysroot/include/asm-arch-$$arch"; \
+			rm -rf "$(OUTPUT)sysroot/include/$$arch"; \
+			case "$$arch" in \
+				arm)       cond="defined(__ARM_EABI__)" ;; \
+				arm64)     cond="defined(__aarch64__)" ;; \
+				loongarch) cond="defined(__loongarch__)" ;; \
+				m68k)      cond="defined(__m68k__)" ;; \
+				mips)      cond="defined(__mips__)" ;; \
+				powerpc)   cond="defined(__powerpc__)" ;; \
+				riscv)     cond="defined(__riscv__)" ;; \
+				s390)      cond="defined(__s390__) || defined(__s390x__)" ;; \
+				sparc)     cond="defined(__sparc__)" ;; \
+				x86)       cond="defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(__x86_64__)";; \
+				*)         echo "Unsupported arch" >&2; exit 1;; \
+			esac;\
+			for file in "$(OUTPUT)sysroot/include/asm-arch-$$arch/"*.h; do \
+				base="$${file##*/}"; \
+				( echo "#if $$cond"; \
+				  echo "#include \"../asm-arch-$$arch/$$base\""; \
+				  echo "#endif" ) >> "$(OUTPUT)sysroot/include/asm/$$base"; \
+			done; \
+		fi;\
+	done
+
 # GCC uses "s390", clang "systemz"
 CLANG_CROSS_FLAGS := $(subst --target=s390-linux,--target=systemz-linux,$(CLANG_CROSS_FLAGS))
 
-- 
2.17.5


  parent reply	other threads:[~2025-06-20 10:37 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-20 10:37 [RFC PATCH 0/3] tools/nolibc: install unified multi-arch headers Willy Tarreau
2025-06-20 10:37 ` [RFC PATCH 1/3] tools/nolibc: merge i386 and x86_64 into a single x86 arch Willy Tarreau
2025-06-21  8:29   ` Thomas Weißschuh
2025-06-21  8:44     ` Willy Tarreau
2025-06-20 10:37 ` [RFC PATCH 2/3] tools/nolibc: add a new target "headers_all_archs" to loop over all archs Willy Tarreau
2025-06-23 21:56   ` Thomas Weißschuh
2025-06-24  6:20     ` Willy Tarreau
2025-06-24  7:46       ` Thomas Weißschuh
2025-06-24 10:00         ` Willy Tarreau
2025-06-20 10:37 ` Willy Tarreau [this message]
2025-06-26 20:18   ` [RFC PATCH 3/3] tools/nolibc: add a new "install_all_archs" target Thomas Weißschuh
2025-06-26 21:15     ` Arnd Bergmann
2025-06-27  3:25       ` Willy Tarreau
2025-06-27  5:58         ` Arnd Bergmann
2025-06-27  6:07           ` Willy Tarreau
2025-06-27  5:11       ` Thomas Weißschuh
2025-06-27  5:46         ` Willy Tarreau
2025-06-27  5:49           ` Willy Tarreau
2025-06-27  7:27             ` Thomas Weißschuh
2025-06-27  7:29               ` Willy Tarreau

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=20250620103705.10208-4-w@1wt.eu \
    --to=w@1wt.eu \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=thomas.weissschuh@linutronix.de \
    /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®