From 24ddf285d228adf1fdfdbf0115a31625a84ad5fd Mon Sep 17 00:00:00 2001 From: Juan Carrano Date: Thu, 18 Oct 2018 14:57:03 +0200 Subject: [PATCH] Makefile.base: use thin static archives. 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 % | --- Makefile.base | 4 +++- makefiles/cflags.inc.mk | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile.base b/Makefile.base index 5174119c09..6f6984153f 100644 --- a/Makefile.base +++ b/Makefile.base @@ -67,10 +67,12 @@ $(BINDIR)/$(MODULE)/: $(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) $@ $^ + $(Q)$(AR) $(ARFLAGS) $(foreach f,$@ $^,$(call relpath,$f)) CXXFLAGS = $(filter-out $(CXXUWFLAGS), $(CFLAGS)) $(CXXEXFLAGS) CCASFLAGS = $(filter-out $(CCASUWFLAGS), $(CFLAGS)) $(CCASEXFLAGS) diff --git a/makefiles/cflags.inc.mk b/makefiles/cflags.inc.mk index 4f1b163963..2f7cf22e95 100644 --- a/makefiles/cflags.inc.mk +++ b/makefiles/cflags.inc.mk @@ -65,5 +65,5 @@ CFLAGS += $(filter-out $(OPTIONAL_CFLAGS_BLACKLIST),$(OPTIONAL_CFLAGS)) # Default ARFLAGS for platforms which do not specify it. # Note: make by default provides ARFLAGS=rv which we want to override ifeq ($(origin ARFLAGS),default) - ARFLAGS = rcs + ARFLAGS = rcTs endif