tools/nolibc: fix build issues when building from tools/
Willy Tarreau
maintainercover tools/nolibc: fix build issues when building from tools/
Hi,
Linus reported build issues when trying nolibc according to the documented procedure in "make tools/help":
https://lore.kernel.org/lkml/CAHk-=wgpAHhPVSqBWb4gYT=CRJzKAZ4inmrL_kcpeNWGkcg3pg@mail.gmail.com/
This series addresses this by setting the ARCH and OUTPUT variables and adding a few targets to match default expectations. A "help" target also explains what the existing targets do. This will be particularly useful once the test suite is merged since it will add new targets.
Thanks,
Willy
---
Willy Tarreau (3):
tools/nolibc: fix the makefile to also work as "make -C tools ..." tools/nolibc: make the default target build the headers tools/nolibc: add a help target to list supported targets
tools/Makefile | 3 +++ tools/include/nolibc/Makefile | 37 +++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.5
Willy Tarreau
maintainerPATCH 1/3 tools/nolibc: fix the makefile to also work as "make -C tools ..."
As reported by Linus, the nolibc's makefile is currently broken when invoked as per the documented method (make -C tools nolibc_<target>), because it now relies on the ARCH and OUTPUT variables that are not set in this case.
This patch addresses this by sourcing subarch.include, and by presetting OUTPUT to the current directory if not set. This is sufficient to make the commands work both as a standalone target and as a tools/ sub-target.
--- tools/include/nolibc/Makefile | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
tools/include/nolibc/Makefile +17 -1
@@ -7,6 +7,22 @@ ifeq ($(srctree),) srctree := $(patsubst %/tools/include/,%,$(dir $(CURDIR))) endif +# when run as make -C tools/ nolibc_<foo> the arch is not set +ifeq ($(ARCH),) +include $(srctree)/scripts/subarch.include +ARCH = $(SUBARCH) +endif + +# OUTPUT is only set when run from the main makefile, otherwise +# it defaults to this nolibc directory. +OUTPUT ?= $(CURDIR)/ + +ifeq ($(V),1) +Q= +else +Q=@ +endif + nolibc_arch := $(patsubst arm64,aarch64,$(ARCH)) arch_file := arch-$(nolibc_arch).h all_files := ctype.h errno.h nolibc.h signal.h std.h stdio.h stdlib.h string.h \
@@ -36,7 +52,7 @@ headers: headers_standalone: headers $(Q)$(MAKE) -C $(srctree) headers - $(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)/sysroot + $(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot clean: $(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot"
Signature · 1 line
2.17.5
Willy Tarreau
maintainerPATCH 2/3 tools/nolibc: make the default target build the headers
In reply to Willy TarreauThe help in "make -C tools" enumerates nolibc as a valid target so we must at least make it do something. Let's make it do the equivalent of "make headers" in that it will prepare a sysroot with the arch's headers, but will not install the kernel's headers. This is the minimum some tools will need when built with a full-blown toolchain anyway.
--- tools/Makefile | 3 +++ tools/include/nolibc/Makefile | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)
tools/Makefile +3 -0
@@ -78,6 +78,9 @@ bpf/%: FORCE libapi: FORCE $(call descend,lib/api) +nolibc: FORCE + $(call descend,include/nolibc) + nolibc_%: FORCE $(call descend,include/nolibc,$(patsubst nolibc_%,%,$@))
tools/include/nolibc/Makefile +1 -1
@@ -29,7 +29,7 @@ all_files := ctype.h errno.h nolibc.h signal.h std.h stdio.h stdlib.h string.h \ sys.h time.h types.h unistd.h # install all headers needed to support a bare-metal compiler -all: +all: headers # Note: when ARCH is "x86" we concatenate both x86_64 and i386 headers:
Signature · 1 line
2.17.5
Willy Tarreau
maintainerPATCH 3/3 tools/nolibc: add a help target to list supported targets
In reply to Willy TarreauThe "help" target simply presents the list of supported targets and the current set of variables being used to build the sysroot.
Since the help in tools/ suggests to use "install", which is supported by most tools while such a target is not really relevant here, an "install" target was also added, redirecting to "help".
--- tools/include/nolibc/Makefile | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
tools/include/nolibc/Makefile +17 -0
@@ -31,6 +31,23 @@ all_files := ctype.h errno.h nolibc.h signal.h std.h stdio.h stdlib.h string.h \ # install all headers needed to support a bare-metal compiler all: headers +install: help + +help: + @echo "Supported targets under nolibc:" + @echo " all call \"headers\"" + @echo " clean clean the sysroot" + @echo " headers prepare a sysroot in tools/include/nolibc/sysroot" + @echo " headers_standalone like \"headers\", and also install kernel headers" + @echo " help this help" + @echo "" + @echo "These targets may also be called from tools as \"make nolibc_<target>\"." + @echo "" + @echo "Currently using the following variables:" + @echo " ARCH = $(ARCH)" + @echo " OUTPUT = $(OUTPUT)" + @echo "" + # Note: when ARCH is "x86" we concatenate both x86_64 and i386 headers: $(Q)mkdir -p $(OUTPUT)sysroot
Signature · 1 line
2.17.5
Quoted 7 lines · Willy Tarreau
Hi,
Linus reported build issues when trying nolibc according to the documented procedure in "make
tools/help":https://lore.kernel.org/lkml/CAHk-=wgpAHhPVSqBWb4gYT=CRJzKAZ4inmrL_kcpeNWGkcg3pg@mail.gmail.com/
Quoted 7 lines
This series addresses this by setting the ARCH and OUTPUT variables and adding a few targets to match default expectations. A "help" target also explains what the existing targets do. This will be particularly useful once the test suite is merged since it will add new targets.
Thanks,
Willy
Queued for testing and review, thank you!
Thanx, Paul
Quoted 13 lines
---
Willy Tarreau (3):
tools/nolibc: fix the makefile to also work as "make -C tools ..."tools/nolibc: make the default target build the headerstools/nolibc: add a help target to list supported targetstools/Makefile | 3 +++ tools/include/nolibc/Makefile | 37 +++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-)Signature · 1 line
2.17.5