mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
24ddf285d2
Normal, or thick archives contain a copy of the object code. Thin archives, on the contrary, are just an index to the .o files. This patch does two things: 1. Change ARFLAGS to enable the "T" options. 2. Call AR with all relative paths. The second step is necessary because the build system handles all absolute paths. If the index in the thin archive contains absolute paths, archives created in docker are no usable outside, and moving the objects breaks the archive. If all arguments to AR are relative, the resulting archive contains filenames *relative to the .a file* and nothing should break as long as the relative location of the .a and .o remains unchanged. Compilation time is unchanged, but disc usage is reduced by approximately 50%. These are the result of a full RIOT build: | Thin Archive | no | yes | Savings (%) | | -------------- | ------: | ----: | ----------- | | pkg (10e6 KiB) | 1 790 | 905 | 49% | | Non pkg | 71 | 71 | 1% | | Total | 1 812 | 976 | 46 % |
105 lines
3.1 KiB
Makefile
105 lines
3.1 KiB
Makefile
ifeq (, $(__RIOTBUILD_FLAG))
|
|
$(error You cannot build a module on its own. Use "make" in your application's directory instead.)
|
|
endif
|
|
|
|
unexport DIRS
|
|
DIRS := $(sort $(abspath $(DIRS)))
|
|
|
|
MODULE ?= $(shell basename $(CURDIR))
|
|
|
|
.PHONY: all clean $(DIRS:%=ALL--%) $(DIRS:%=CLEAN--%)
|
|
|
|
all: $(BINDIR)/$(MODULE).a ..nothing
|
|
|
|
..nothing:
|
|
@:
|
|
|
|
clean:: $(DIRS:%=CLEAN--%)
|
|
|
|
$(DIRS:%=ALL--%):
|
|
$(QQ)"$(MAKE)" -C $(@:ALL--%=%)
|
|
|
|
$(DIRS:%=CLEAN--%):
|
|
$(QQ)"$(MAKE)" -C $(@:CLEAN--%=%) clean
|
|
|
|
## submodules
|
|
ifeq (1, $(SUBMODULES))
|
|
# don't use *.c as SRC if SRC is empty (e.g., no module selected)
|
|
NO_AUTO_SRC := 1
|
|
|
|
# allow different submodule basename (e.g., MODULE=cpu_periph_common, but match just periph_%)
|
|
BASE_MODULE ?= $(MODULE)
|
|
|
|
# for each $(BASE_MODULE)_<name> in USEMODULE, add <name>.c to SRC
|
|
SRC += $(patsubst $(BASE_MODULE)_%,%.c,$(filter $(BASE_MODULE)_%,$(USEMODULE)))
|
|
|
|
# don't fail if a selected *.c file does not exist
|
|
ifeq (1, $(SUBMODULES_NOFORCE))
|
|
SRC := $(filter $(SRC), $(wildcard *.c))
|
|
endif
|
|
endif
|
|
|
|
ifeq ($(strip $(SRC))$(NO_AUTO_SRC),)
|
|
SRC := $(filter-out $(SRC_NOLTO), $(wildcard *.c))
|
|
endif
|
|
ifeq ($(strip $(SRCXX))$(NO_AUTO_SRC),)
|
|
SRCXX := $(wildcard *.cpp)
|
|
endif
|
|
ifeq ($(strip $(ASMSRC))$(NO_AUTO_SRC),)
|
|
ASMSRC := $(wildcard *.s)
|
|
endif
|
|
ifeq ($(strip $(ASSMSRC))$(NO_AUTO_SRC),)
|
|
ASSMSRC := $(wildcard *.S)
|
|
endif
|
|
|
|
OBJC_LTO := $(SRC:%.c=$(BINDIR)/$(MODULE)/%.o)
|
|
OBJC_NOLTO := $(SRC_NOLTO:%.c=$(BINDIR)/$(MODULE)/%.o)
|
|
OBJC := $(OBJC_NOLTO) $(OBJC_LTO)
|
|
OBJCXX := $(SRCXX:%.cpp=$(BINDIR)/$(MODULE)/%.o)
|
|
ASMOBJ := $(ASMSRC:%.s=$(BINDIR)/$(MODULE)/%.o)
|
|
ASSMOBJ := $(ASSMSRC:%.S=$(BINDIR)/$(MODULE)/%.o)
|
|
|
|
OBJ := $(OBJC) $(OBJCXX) $(ASMOBJ) $(ASSMOBJ)
|
|
DEP := $(OBJC:.o=.d) $(OBJCXX:.o=.d) $(ASSMOBJ:.o=.d)
|
|
|
|
$(BINDIR)/$(MODULE)/:
|
|
$(Q)mkdir -p $@
|
|
|
|
$(BINDIR)/$(MODULE).a $(OBJ): | $(BINDIR)/$(MODULE)/
|
|
|
|
relpath = $(shell realpath --relative-to=$(abspath .) $(1))
|
|
|
|
$(BINDIR)/$(MODULE).a: $(OBJ) | $(DIRS:%=ALL--%)
|
|
@# Recreate archive to cleanup deleted/non selected source files objects
|
|
$(Q)$(RM) $@
|
|
$(Q)$(AR) $(ARFLAGS) $(foreach f,$@ $^,$(call relpath,$f))
|
|
|
|
CXXFLAGS = $(filter-out $(CXXUWFLAGS), $(CFLAGS)) $(CXXEXFLAGS)
|
|
CCASFLAGS = $(filter-out $(CCASUWFLAGS), $(CFLAGS)) $(CCASEXFLAGS)
|
|
|
|
# compile and generate dependency info
|
|
|
|
$(OBJC_LTO): CFLAGS+=$(LTOFLAGS)
|
|
|
|
$(OBJC): $(BINDIR)/$(MODULE)/%.o: %.c $(RIOTBUILD_CONFIG_HEADER_C)
|
|
$(Q)$(CCACHE) $(CC) \
|
|
-DRIOT_FILE_RELATIVE=\"$(patsubst $(RIOTBASE)/%,%,$(abspath $<))\" \
|
|
-DRIOT_FILE_NOPATH=\"$(notdir $<)\" \
|
|
$(CFLAGS) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)
|
|
|
|
$(OBJCXX): $(BINDIR)/$(MODULE)/%.o: %.cpp $(RIOTBUILD_CONFIG_HEADER_C)
|
|
$(Q)$(CCACHE) $(CXX) \
|
|
-DRIOT_FILE_RELATIVE=\"$(patsubst $(RIOTBASE)/%,%,$(abspath $<))\" \
|
|
-DRIOT_FILE_NOPATH=\"$(notdir $<)\" \
|
|
$(CXXFLAGS) $(CXXINCLUDES) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)
|
|
|
|
$(ASMOBJ): $(BINDIR)/$(MODULE)/%.o: %.s
|
|
$(Q)$(AS) $(ASFLAGS) -o $@ $(abspath $<)
|
|
|
|
$(ASSMOBJ): $(BINDIR)/$(MODULE)/%.o: %.S $(RIOTBUILD_CONFIG_HEADER_C)
|
|
$(Q)$(CCAS) $(CCASFLAGS) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)
|
|
|
|
# pull in dependency info for *existing* .o files
|
|
# deleted header files will be silently ignored
|
|
-include $(DEP)
|