This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 40fd3183499a7622ea1d913cfaf32910a7943794 Author: Alan Carvalho de Assis <[email protected]> AuthorDate: Sun Oct 18 08:39:48 2026 -0300 drivers: support pre-built libraries in libdrivers.a Some drivers need a pre-built static library, e.g. the binary host library of a wireless chip vendor. With the Make build there was no way to link it from the driver: only architecture or board Make.defs files can add EXTRA_LIBS. Add the ARCHIVE_ADDLIB macro, that adds all the members of a library to an archive using an ar MRI script (which keeps the members that share the same name), and let the drivers list their pre-built libraries in PREBUILT_LIBS: they are merged into libdrivers.a. The linker then only pulls the referenced members. With CMake the drivers can already use nuttx_add_extra_library(). Signed-off-by: Alan Carvalho de Assis <[email protected]> Assisted-by: Claude Code Opus 5.5 --- drivers/Makefile | 6 +++++- tools/Config.mk | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/Makefile b/drivers/Makefile index fe6b440e539..4dd24c6ee89 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -108,8 +108,12 @@ $(AOBJS): %$(OBJEXT): %.S $(COBJS): %$(OBJEXT): %.c $(call COMPILE, $<, $@) -$(BIN): $(OBJS) +# Pre-built static libraries needed by some drivers (PREBUILT_LIBS) are +# merged into libdrivers.a + +$(BIN): $(OBJS) $(PREBUILT_LIBS) $(call ARCHIVE_REBUILD, $@, $(OBJS)) + $(foreach lib,$(PREBUILT_LIBS),$(call ARCHIVE_ADDLIB, $@, $(lib))$(NEWLINE)) context:: diff --git a/tools/Config.mk b/tools/Config.mk index 49020965636..3206fd4fae5 100644 --- a/tools/Config.mk +++ b/tools/Config.mk @@ -507,6 +507,26 @@ define ARCHIVE_REBUILD $(AR) $1 $2 endef +# ARCHIVE_ADDLIB - Add all the members of a static library to an archive +# Example: $(call ARCHIVE_ADDLIB, archive-file, library-file) +# +# Used to merge a pre-built library (e.g. the binary host library of a +# wireless chip vendor) into a NuttX library, so that it is linked like the +# rest of the code without architecture or board specific link rules. Only +# the library members that are referenced are pulled in by the linker. +# +# The members are copied as they are with an ar MRI script, which keeps the +# members that share the same name (extracting them with 'ar x' would not). +# +# Depends on these settings defined in board-specific Make.defs file +# installed at $(TOPDIR)/Make.defs: +# +# AR - The command to invoke the archiver (includes any options) + +define ARCHIVE_ADDLIB + $(Q) printf "OPEN %s\nADDLIB %s\nSAVE\nEND\n" $1 $2 | $(firstword $(AR)) -M +endef + # PRELINK - Prelink a list of files # This is useful when files were compiled with fvisibility=hidden. # Any symbol which was not explicitly made global is invisible outside the
