nuttx/libs/libbuiltin/Makefile
Alan Carvalho de Assis c027e7c3e4 tools: fix stale archive members surviving a Kconfig-driven CSRCS change
During the Toybox port to NuttX, Claude noticed that changes in the
menuconfig weren't taking affect. This issue exists for a long time on
NuttX, in fact BayLibre's presentation from 2017 make jokes about our
building system not been reliable:
https://www.youtube.com/watch?v=XUJK2htXxKw&t=320s

Stale archive members from $(AR)'s additive-only behavior can linger
after Kconfig toggles change which files provide a symbol, causing dead
weight or "multiple definition" link errors on incremental builds.
Fixed by splitting ARCHIVE into two macros: ARCHIVE keeps the original
additive behavior for apps/libapps.a, which many independent
subdirectories contribute to across a build, while the new
ARCHIVE_REBUILD deletes then archives for the far more common case
of a single Makefile building its own self-contained $(OBJS)
- all 39 such call sites now use it.

Assisted-By: Claude Sonnet 5
Signed-off-by: Alan C. Assis <acassis@gmail.com>
2026-07-28 21:26:03 -03:00

86 lines
2.3 KiB
Makefile

############################################################################
# libs/libbuiltin/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
###########################################################################
include $(TOPDIR)/Make.defs
BIN ?= libbuiltin$(LIBEXT)
BINDIR ?= bin
KBIN = libkbuiltin$(LIBEXT)
KBINDIR = kbin
include compiler-rt/Make.defs
include libgcc/Make.defs
AOBJS = $(addprefix $(BINDIR)$(DELIM), $(ASRCS:.S=$(OBJEXT)))
COBJS = $(addprefix $(BINDIR)$(DELIM), $(CSRCS:.c=$(OBJEXT)))
CXXOBJS = $(addprefix $(BINDIR)$(DELIM), $(CXXSRCS:.cxx=$(OBJEXT)))
CPPOBJS = $(addprefix $(BINDIR)$(DELIM), $(CPPSRCS:.cpp=$(OBJEXT)))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(CPPSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS) $(CPPOBJS)
all: $(BIN)
.PHONY: depend clean distclean context
$(AOBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
$(CPPOBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.cpp
$(call COMPILEXX, $<, $@)
bin:
$(Q) mkdir $@
kbin:
$(Q) mkdir $@
context:: bin kbin
.depend: Makefile $(SRCS) $(TOPDIR)$(DELIM).config
$(Q) touch $@
depend:: .depend
$(BIN): $(OBJS)
$(call ARCHIVE_REBUILD, $@, $(OBJS))
# C library for the kernel phase of the two-pass kernel build
ifneq ($(BIN),$(KBIN))
$(KBIN): $(OBJS)
$(Q) $(MAKE) $(KBIN) BIN=$(KBIN) BINDIR=$(KBINDIR) EXTRAFLAGS="$(EXTRAFLAGS)"
endif
clean:
$(call CLEAN)
$(call DELFILE, $(BIN))
$(call DELFILE, $(KBIN))
distclean:: clean
$(call DELDIR, bin)
$(call DELDIR, kbin)
$(call DELDIR, .depend)