[make][buildall] add ability to filter buildall by architecture

Clean up make targets list-arch and list-toolchain to be much faster and
work without needing to invoke the archtecture's arch rules.mk. This
should make it work on machines that do not have that particular
toolchain in the path.

This is setting up for using it in the github action script.
This commit is contained in:
Travis Geiselbrecht
2025-07-18 21:32:05 -07:00
parent 50dc95b85e
commit be52909f49
7 changed files with 60 additions and 21 deletions

View File

@@ -332,7 +332,6 @@ endif
# try to find toolchain # try to find toolchain
include $(LOCAL_DIR)/toolchain.mk include $(LOCAL_DIR)/toolchain.mk
TOOLCHAIN_PREFIX := $(ARCH_$(ARCH)_TOOLCHAIN_PREFIX) TOOLCHAIN_PREFIX := $(ARCH_$(ARCH)_TOOLCHAIN_PREFIX)
$(info TOOLCHAIN_PREFIX = $(TOOLCHAIN_PREFIX))
ARCH_COMPILEFLAGS += $(ARCH_$(ARCH)_COMPILEFLAGS) ARCH_COMPILEFLAGS += $(ARCH_$(ARCH)_COMPILEFLAGS)
ARCH_COMPILEFLAGS_NOFLOAT := ARCH_COMPILEFLAGS_NOFLOAT :=

View File

@@ -4,7 +4,6 @@ ARCH_arm_TOOLCHAIN_INCLUDED := 1
# try to find the toolchain # try to find the toolchain
ifndef ARCH_arm_TOOLCHAIN_PREFIX ifndef ARCH_arm_TOOLCHAIN_PREFIX
$(info $(TOOLCHAIN_PREFIX))
# if TOOLCHAIN_PREFIX is not empty, try to use it first # if TOOLCHAIN_PREFIX is not empty, try to use it first
ifneq ($(TOOLCHAIN_PREFIX),) ifneq ($(TOOLCHAIN_PREFIX),)
ARCH_arm_TOOLCHAIN_PREFIX := $(TOOLCHAIN_PREFIX) ARCH_arm_TOOLCHAIN_PREFIX := $(TOOLCHAIN_PREFIX)

View File

@@ -89,7 +89,6 @@ GLOBAL_DEFINES += \
# try to find the toolchain # try to find the toolchain
include $(LOCAL_DIR)/toolchain.mk include $(LOCAL_DIR)/toolchain.mk
TOOLCHAIN_PREFIX := $(ARCH_$(ARCH)_TOOLCHAIN_PREFIX) TOOLCHAIN_PREFIX := $(ARCH_$(ARCH)_TOOLCHAIN_PREFIX)
$(info TOOLCHAIN_PREFIX = $(TOOLCHAIN_PREFIX))
ARCH_COMPILEFLAGS += $(ARCH_$(ARCH)_COMPILEFLAGS) ARCH_COMPILEFLAGS += $(ARCH_$(ARCH)_COMPILEFLAGS)
ARCH_COMPILEFLAGS += -fno-omit-frame-pointer ARCH_COMPILEFLAGS += -fno-omit-frame-pointer

View File

@@ -106,9 +106,9 @@ TOOLCHAIN_PREFIX := $(ARCH_x86_64_TOOLCHAIN_PREFIX)
endif endif
endif # SUBARCH x86-64 endif # SUBARCH x86-64
$(warning ARCH_x86_TOOLCHAIN_PREFIX = $(ARCH_x86_TOOLCHAIN_PREFIX)) $(info ARCH_x86_TOOLCHAIN_PREFIX = $(ARCH_x86_TOOLCHAIN_PREFIX))
$(warning ARCH_x86_64_TOOLCHAIN_PREFIX = $(ARCH_x86_64_TOOLCHAIN_PREFIX)) $(info ARCH_x86_64_TOOLCHAIN_PREFIX = $(ARCH_x86_64_TOOLCHAIN_PREFIX))
$(warning TOOLCHAIN_PREFIX = $(TOOLCHAIN_PREFIX)) $(info TOOLCHAIN_PREFIX = $(TOOLCHAIN_PREFIX))
cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc /dev/null 2>&1`"; \ cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc /dev/null 2>&1`"; \
then echo "$(2)"; else echo "$(3)"; fi ;) then echo "$(2)"; else echo "$(3)"; fi ;)
@@ -148,8 +148,6 @@ GLOBAL_DEFINES += X86_LEGACY=0
endif endif
LIBGCC := $(shell $(TOOLCHAIN_PREFIX)gcc $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) -print-libgcc-file-name) LIBGCC := $(shell $(TOOLCHAIN_PREFIX)gcc $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) -print-libgcc-file-name)
$(warning LIBGCC = $(LIBGCC))
LINKER_SCRIPT += $(SUBARCH_BUILDDIR)/kernel.ld LINKER_SCRIPT += $(SUBARCH_BUILDDIR)/kernel.ld
# potentially generated files that should be cleaned out with clean make rule # potentially generated files that should be cleaned out with clean make rule

View File

@@ -183,11 +183,25 @@ include platform/$(PLATFORM)/rules.mk
ifndef ARCH ifndef ARCH
$(error couldn't find arch or platform doesn't define arch) $(error couldn't find arch or platform doesn't define arch)
endif endif
# list the architecture specified in the project/target/platform rules.mk and early terminate.
ifeq ($(MAKECMDGOALS), list-arch)
$(info ARCH = $(ARCH))
.PHONY: list-arch
list-arch:
else
include arch/$(ARCH)/rules.mk include arch/$(ARCH)/rules.mk
ifndef TOOLCHAIN_PREFIX ifndef TOOLCHAIN_PREFIX
$(error TOOLCHAIN_PREFIX not set in the arch rules.mk) $(error TOOLCHAIN_PREFIX not set in the arch rules.mk)
endif endif
ifeq ($(MAKECMDGOALS), list-toolchain)
$(info TOOLCHAIN_PREFIX = $(TOOLCHAIN_PREFIX))
.PHONY: list-toolchain
list-toolchain:
else
# default to no ccache # default to no ccache
CCACHE ?= CCACHE ?=
CC ?= $(CCACHE) $(TOOLCHAIN_PREFIX)gcc CC ?= $(CCACHE) $(TOOLCHAIN_PREFIX)gcc
@@ -354,12 +368,6 @@ clean: $(EXTRA_CLEANDEPS)
install: all install: all
scp $(OUTBIN) 192.168.0.4:/tftpboot scp $(OUTBIN) 192.168.0.4:/tftpboot
list-arch:
@echo ARCH = ${ARCH}
list-toolchain:
@echo TOOLCHAIN_PREFIX = ${TOOLCHAIN_PREFIX}
tags: $(BUILDDIR)/srcfiles.txt $(BUILDDIR)/include_paths.txt tags: $(BUILDDIR)/srcfiles.txt $(BUILDDIR)/include_paths.txt
$(info generating tags) $(info generating tags)
@ctags -L $< @ctags -L $<
@@ -382,6 +390,10 @@ ifeq ($(filter $(MAKECMDGOALS), clean), )
-include $(DEPS) -include $(DEPS)
endif endif
endif # ifeq ($(filter $(MAKECMDGOALS), list-toolchain))
endif # ifeq ($(filter $(MAKECMDGOALS), list-arch))
endif # do-nothing = 1 endif # do-nothing = 1
endif # make spotless endif # make spotless

View File

@@ -12,9 +12,14 @@ help:
@echo "LK build system quick help" @echo "LK build system quick help"
@echo "Individual projects are built into a build-<project> directory" @echo "Individual projects are built into a build-<project> directory"
@echo "Output binary is located at build-<project>/lk.bin" @echo "Output binary is located at build-<project>/lk.bin"
@echo ""
@echo "Environment or command line variables controlling build:" @echo "Environment or command line variables controlling build:"
@echo "PROJECT = <project name>" @echo "PROJECT = <project name>"
@echo "TOOLCHAIN_PREFIX = <absolute path to toolchain or relative path with prefix>" @echo "TOOLCHAIN_PREFIX = <absolute path to toolchain or relative path with prefix>"
@echo "WERROR = 1 : treat warnings as errors"
@echo "DEBUG = 0,1,2 : set debug level (0=NONE, 1=INFO, 2=DEBUG), default is 2"
@echo "BUILDDIR = <path to build directory> (default is build-<project>)"
@echo "BUILDDIR_SUFFIX = <suffix to add to build directory> (default is empty)"
@echo "" @echo ""
@echo "Special make targets:" @echo "Special make targets:"
@echo "make help: This help" @echo "make help: This help"
@@ -34,6 +39,9 @@ help:
@echo "make testproject clean" @echo "make testproject clean"
@echo "" @echo ""
@echo "output will be in build-testproject/" @echo "output will be in build-testproject/"
@echo ""
@echo "Check the project/ directory for available projects"
@echo "and their rules.mk files for more information."
endif endif

View File

@@ -13,19 +13,22 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function HELP { function HELP {
echo "help:" echo "help:"
echo "-e build with WERROR=1" echo "-a <arch> : build for <arch> (default: all)"
echo "-r also build DEBUG=0" echo "-e : build with WERROR=1"
echo "-q hide output of build" echo "-r : also build DEBUG=0"
echo "-h for help" echo "-q : hide output of build"
echo "-h : for help"
exit 1 exit 1
} }
RELEASE=0 RELEASE=0
WERROR=0 WERROR=0
QUIET=0 QUIET=0
ARCH="all"
while getopts ehrq FLAG; do while getopts a:ehrq FLAG; do
case $FLAG in case $FLAG in
a) ARCH="$OPTARG";;
e) WERROR=1;; e) WERROR=1;;
h) HELP;; h) HELP;;
r) RELEASE=1;; r) RELEASE=1;;
@@ -48,10 +51,30 @@ function log()
fi fi
} }
# build everything in the projects directory # find all the projects in the project directory
PROJECTS=$(echo project/*.mk | xargs -n1 basename | sed 's/\.mk//') _PROJECTS=$(echo project/*.mk | xargs -n1 basename | sed 's/\.mk//')
FAILED="" FAILED=""
# If ARCH is set to all, we build for all architectures, otherwise we
# filter projects based on the ARCH variable.
if [ "$ARCH" != "all" ]; then
for p in $_PROJECTS; do
# Look for ARCH = <arch> in the output of make list-arch
PROJECT_ARCH="$(PROJECT=$p make list-arch | grep 'ARCH' | tail -1 | cut -d ' ' -f 3)"
if [ "$PROJECT_ARCH" == "$ARCH" ]; then
PROJECTS+="$p "
else
if (( !QUIET )); then
echo "Skipping $p, not compatible with architecture $ARCH"
fi
fi
done
else
PROJECTS+="$_PROJECTS"
fi
echo projects to build: "$PROJECTS"
if (( WERROR )); then if (( WERROR )); then
WERROR_MSG="with WERROR" WERROR_MSG="with WERROR"
fi fi
@@ -73,4 +96,5 @@ if [ "$FAILED" != "" ]; then
echo echo
echo some projects have failed to build: echo some projects have failed to build:
echo "$FAILED" echo "$FAILED"
exit 1
fi fi