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
On 2025-06-20 12:37:05+0200, Willy Tarreau wrote: > 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; \ I'm not a fan of the loop to build the ifdeffery. It is a duplication of what we have in tools/include/nolibc/arch.h and horrible to look at. Can we stick this into a reusable header file? Something along the lines of this: /* asm/foo.h */ #define _NOLIBC_PER_ARCH_HEADER "foo.h" #include "_nolibc_include_per_arch_header.h" /* _nolibc_include_per_arch_header.h */ #if defined(__i386__) #include CONCAT("asm-arch-x86/", _NOLIBC_PER_ARCH_HEADER) #elif ... However, so far I couldn't get it to work. Also it would be great if we can use it for the current arch.h, too. > + fi;\ > + done > + > # GCC uses "s390", clang "systemz" > CLANG_CROSS_FLAGS := $(subst --target=s390-linux,--target=systemz-linux,$(CLANG_CROSS_FLAGS)) > > -- > 2.17.5
On Thu, Jun 26, 2025, at 22:18, Thomas Weißschuh wrote: > On 2025-06-20 12:37:05+0200, Willy Tarreau wrote: >> 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. >> >> + $(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; \ > > I'm not a fan of the loop to build the ifdeffery. It is a duplication > of what we have in tools/include/nolibc/arch.h and horrible to look at. > Can we stick this into a reusable header file? > Something along the lines of this: > > /* asm/foo.h */ > #define _NOLIBC_PER_ARCH_HEADER "foo.h" > #include "_nolibc_include_per_arch_header.h" > > > /* _nolibc_include_per_arch_header.h */ > #if defined(__i386__) > #include CONCAT("asm-arch-x86/", _NOLIBC_PER_ARCH_HEADER) > #elif > ... > > However, so far I couldn't get it to work. > Also it would be great if we can use it for the current arch.h, too. I'm not sure either of those is better than the version we had until commit f3c8d4c7a728 ("kbuild: remove headers_{install,check}_all"). which simply relied on a symlink to the architecture specific directory to be set. If it's indeed possible to concatenate the path name (I couldn't figure that out either), that could also be done in place of the symlink but simpler than the #if/#elif/#elif/... block, like #include <arch.h> // defines ARCH_PREFIX #include CONCAT(ARCH_PREFIX, ioctl.h) Arnd
On 2025-06-26 23:15:07+0200, Arnd Bergmann wrote: > On Thu, Jun 26, 2025, at 22:18, Thomas Weißschuh wrote: > > On 2025-06-20 12:37:05+0200, Willy Tarreau wrote: > >> 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. > >> > >> + $(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; \ > > > > > I'm not a fan of the loop to build the ifdeffery. It is a duplication > > of what we have in tools/include/nolibc/arch.h and horrible to look at. > > Can we stick this into a reusable header file? > > Something along the lines of this: > > > > /* asm/foo.h */ > > #define _NOLIBC_PER_ARCH_HEADER "foo.h" > > #include "_nolibc_include_per_arch_header.h" > > > > > > /* _nolibc_include_per_arch_header.h */ > > #if defined(__i386__) > > #include CONCAT("asm-arch-x86/", _NOLIBC_PER_ARCH_HEADER) > > #elif > > ... > > > > However, so far I couldn't get it to work. > > Also it would be great if we can use it for the current arch.h, too. > > I'm not sure either of those is better than the version we > had until commit f3c8d4c7a728 ("kbuild: remove headers_{install,check}_all"). > which simply relied on a symlink to the architecture specific > directory to be set. Thanks for the pointer, that probably answers the question if this could be part of kbuild proper. It shouldn't. With the symlink, a given generic UAPI tree can be specialized to one specific architecture. But here we want to create a full sysroot that works for all architectures *at the same time*. So a symlink would not be enough. > If it's indeed possible to concatenate the path name (I couldn't > figure that out either), that could also be done in place of the > symlink but simpler than the #if/#elif/#elif/... block, like > > #include <arch.h> // defines ARCH_PREFIX > #include CONCAT(ARCH_PREFIX, ioctl.h) If we can't get it to work like this I would still prefer to have a template header file which gets specialized with sed instead of the Makefile loop. Thomas
On Fri, Jun 27, 2025 at 07:11:45AM +0200, Thomas Weißschuh wrote: > On 2025-06-26 23:15:07+0200, Arnd Bergmann wrote: (...) > With the symlink, a given generic UAPI tree can be specialized to one > specific architecture. But here we want to create a full sysroot that works > for all architectures *at the same time*. So a symlink would not be enough. Exactly! > > If it's indeed possible to concatenate the path name (I couldn't > > figure that out either), that could also be done in place of the > > symlink but simpler than the #if/#elif/#elif/... block, like > > > > #include <arch.h> // defines ARCH_PREFIX > > #include CONCAT(ARCH_PREFIX, ioctl.h) > > If we can't get it to work like this I would still prefer to have a > template header file which gets specialized with sed instead of the > Makefile loop. The thing is that it's not a single header, it's for each header file present in asm/. And we can't request that anyone adding anything into asm would also have to maintain one extra template for each of them. Or I'm simply not getting how you would envision it maybe. Willy
On Fri, Jun 27, 2025 at 07:46:18AM +0200, Willy Tarreau wrote: > On Fri, Jun 27, 2025 at 07:11:45AM +0200, Thomas Weißschuh wrote: > > On 2025-06-26 23:15:07+0200, Arnd Bergmann wrote: > (...) > > With the symlink, a given generic UAPI tree can be specialized to one > > specific architecture. But here we want to create a full sysroot that works > > for all architectures *at the same time*. So a symlink would not be enough. > > Exactly! > > > > If it's indeed possible to concatenate the path name (I couldn't > > > figure that out either), that could also be done in place of the > > > symlink but simpler than the #if/#elif/#elif/... block, like > > > > > > #include <arch.h> // defines ARCH_PREFIX > > > #include CONCAT(ARCH_PREFIX, ioctl.h) > > > > If we can't get it to work like this I would still prefer to have a > > template header file which gets specialized with sed instead of the > > Makefile loop. > > The thing is that it's not a single header, it's for each header file > present in asm/. And we can't request that anyone adding anything into > asm would also have to maintain one extra template for each of them. > > Or I'm simply not getting how you would envision it maybe. Or do you mean a template that contains all #ifdef/#include for all archs, that serves as the basis to rebuild all headers, and that we still have the loop on all files in the makefile ? I.e. you simply want to drop the arch loop ? If that's it, yes I'm fine with this as well and can give it a try. Willy
On 2025-06-27 07:49:18+0200, Willy Tarreau wrote: > On Fri, Jun 27, 2025 at 07:46:18AM +0200, Willy Tarreau wrote: > > On Fri, Jun 27, 2025 at 07:11:45AM +0200, Thomas Weißschuh wrote: > > > On 2025-06-26 23:15:07+0200, Arnd Bergmann wrote: > > (...) > > > With the symlink, a given generic UAPI tree can be specialized to one > > > specific architecture. But here we want to create a full sysroot that works > > > for all architectures *at the same time*. So a symlink would not be enough. > > > > Exactly! > > > > > > If it's indeed possible to concatenate the path name (I couldn't > > > > figure that out either), that could also be done in place of the > > > > symlink but simpler than the #if/#elif/#elif/... block, like > > > > > > > > #include <arch.h> // defines ARCH_PREFIX > > > > #include CONCAT(ARCH_PREFIX, ioctl.h) > > > > > > If we can't get it to work like this I would still prefer to have a > > > template header file which gets specialized with sed instead of the > > > Makefile loop. > > > > The thing is that it's not a single header, it's for each header file > > present in asm/. And we can't request that anyone adding anything into > > asm would also have to maintain one extra template for each of them. > > > > Or I'm simply not getting how you would envision it maybe. > > Or do you mean a template that contains all #ifdef/#include for all > archs, that serves as the basis to rebuild all headers, and that we > still have the loop on all files in the makefile ? I.e. you simply > want to drop the arch loop ? If that's it, yes I'm fine with this as > well and can give it a try. This is exactly what I meant. Thomas
On Fri, Jun 27, 2025 at 09:27:10AM +0200, Thomas Weißschuh wrote: > On 2025-06-27 07:49:18+0200, Willy Tarreau wrote: > > On Fri, Jun 27, 2025 at 07:46:18AM +0200, Willy Tarreau wrote: > > > On Fri, Jun 27, 2025 at 07:11:45AM +0200, Thomas Weißschuh wrote: > > > > On 2025-06-26 23:15:07+0200, Arnd Bergmann wrote: > > > (...) > > > > With the symlink, a given generic UAPI tree can be specialized to one > > > > specific architecture. But here we want to create a full sysroot that works > > > > for all architectures *at the same time*. So a symlink would not be enough. > > > > > > Exactly! > > > > > > > > If it's indeed possible to concatenate the path name (I couldn't > > > > > figure that out either), that could also be done in place of the > > > > > symlink but simpler than the #if/#elif/#elif/... block, like > > > > > > > > > > #include <arch.h> // defines ARCH_PREFIX > > > > > #include CONCAT(ARCH_PREFIX, ioctl.h) > > > > > > > > If we can't get it to work like this I would still prefer to have a > > > > template header file which gets specialized with sed instead of the > > > > Makefile loop. > > > > > > The thing is that it's not a single header, it's for each header file > > > present in asm/. And we can't request that anyone adding anything into > > > asm would also have to maintain one extra template for each of them. > > > > > > Or I'm simply not getting how you would envision it maybe. > > > > Or do you mean a template that contains all #ifdef/#include for all > > archs, that serves as the basis to rebuild all headers, and that we > > still have the loop on all files in the makefile ? I.e. you simply > > want to drop the arch loop ? If that's it, yes I'm fine with this as > > well and can give it a try. > > This is exactly what I meant. OK then, I'll have a look to this and Arnd's idea, hopefully we'll find something better than the current proposal. willy
On Thu, Jun 26, 2025 at 11:15:07PM +0200, Arnd Bergmann wrote: > On Thu, Jun 26, 2025, at 22:18, Thomas Weißschuh wrote: > > On 2025-06-20 12:37:05+0200, Willy Tarreau wrote: > >> 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. > >> > >> + $(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; \ > > > > > I'm not a fan of the loop to build the ifdeffery. It is a duplication > > of what we have in tools/include/nolibc/arch.h and horrible to look at. > > Can we stick this into a reusable header file? > > Something along the lines of this: > > > > /* asm/foo.h */ > > #define _NOLIBC_PER_ARCH_HEADER "foo.h" > > #include "_nolibc_include_per_arch_header.h" > > > > > > /* _nolibc_include_per_arch_header.h */ > > #if defined(__i386__) > > #include CONCAT("asm-arch-x86/", _NOLIBC_PER_ARCH_HEADER) > > #elif > > ... > > > > However, so far I couldn't get it to work. > > Also it would be great if we can use it for the current arch.h, too. > > I'm not sure either of those is better than the version we > had until commit f3c8d4c7a728 ("kbuild: remove headers_{install,check}_all"). > which simply relied on a symlink to the architecture specific > directory to be set. > > If it's indeed possible to concatenate the path name (I couldn't > figure that out either), that could also be done in place of the > symlink but simpler than the #if/#elif/#elif/... block, like > > #include <arch.h> // defines ARCH_PREFIX > #include CONCAT(ARCH_PREFIX, ioctl.h) I have never found how it would be possible to do that, let alone in a more or less portable way, because #include doesn't take a C-string in argument but a special syntax which is specific to it ("x" or <x>). It doesn't support concatenating strings for example: #include "stdio"".h" $ gcc -E inc.h inc.h:1:17: warning: extra tokens at end of #include directive 1 | #include "stdio"".h" | ^~~~ inc.h:1:10: fatal error: stdio: No such file or directory 1 | #include "stdio"".h" | ^~~~~~~ Willy
On Fri, Jun 27, 2025, at 05:25, Willy Tarreau wrote: > On Thu, Jun 26, 2025 at 11:15:07PM +0200, Arnd Bergmann wrote: >> On Thu, Jun 26, 2025, at 22:18, Thomas Weißschuh wrote: >> If it's indeed possible to concatenate the path name (I couldn't >> figure that out either), that could also be done in place of the >> symlink but simpler than the #if/#elif/#elif/... block, like >> >> #include <arch.h> // defines ARCH_PREFIX >> #include CONCAT(ARCH_PREFIX, ioctl.h) > > I have never found how it would be possible to do that, let alone in a > more or less portable way, because #include doesn't take a C-string in > argument but a special syntax which is specific to it ("x" or <x>). It > doesn't support concatenating strings for example: > > #include "stdio"".h" > > $ gcc -E inc.h > inc.h:1:17: warning: extra tokens at end of #include directive > 1 | #include "stdio"".h" > | ^~~~ > inc.h:1:10: fatal error: stdio: No such file or directory > 1 | #include "stdio"".h" > | ^~~~~~~ This variant does seem to work with gcc and clang: #define ARCH i386 #define __ARCH_HEADER(a, b) <a ## _ ## b> #define _ARCH_HEADER(a, b) __ARCH_HEADER(a, b) #include _ARCH_HEADER(ARCH, stdio.h) Or even simpler #define _NOLIBC_ARCH_HEADER(file) <i386_ ## file> The ## concatenation is a bit limited here since cpp requires both sides to expand to an identifier, meaning you can have a '_' next to it, but not a '/' or '-'. Arnd
On Fri, Jun 27, 2025 at 07:58:58AM +0200, Arnd Bergmann wrote: > On Fri, Jun 27, 2025, at 05:25, Willy Tarreau wrote: > > On Thu, Jun 26, 2025 at 11:15:07PM +0200, Arnd Bergmann wrote: > >> On Thu, Jun 26, 2025, at 22:18, Thomas Weißschuh wrote: > > >> If it's indeed possible to concatenate the path name (I couldn't > >> figure that out either), that could also be done in place of the > >> symlink but simpler than the #if/#elif/#elif/... block, like > >> > >> #include <arch.h> // defines ARCH_PREFIX > >> #include CONCAT(ARCH_PREFIX, ioctl.h) > > > > I have never found how it would be possible to do that, let alone in a > > more or less portable way, because #include doesn't take a C-string in > > argument but a special syntax which is specific to it ("x" or <x>). It > > doesn't support concatenating strings for example: > > > > #include "stdio"".h" > > > > $ gcc -E inc.h > > inc.h:1:17: warning: extra tokens at end of #include directive > > 1 | #include "stdio"".h" > > | ^~~~ > > inc.h:1:10: fatal error: stdio: No such file or directory > > 1 | #include "stdio"".h" > > | ^~~~~~~ > > This variant does seem to work with gcc and clang: > > #define ARCH i386 > #define __ARCH_HEADER(a, b) <a ## _ ## b> > #define _ARCH_HEADER(a, b) __ARCH_HEADER(a, b) > #include _ARCH_HEADER(ARCH, stdio.h) > > Or even simpler > > #define _NOLIBC_ARCH_HEADER(file) <i386_ ## file> > > The ## concatenation is a bit limited here since cpp requires > both sides to expand to an identifier, meaning you can have > a '_' next to it, but not a '/' or '-'. Thanks Arnd, will give it a try this week-end. Willy
© 2016 - 2025 Red Hat, Inc.