1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #10195 from jcarrano/thin-archives

Makefile.base: use thin static archives.
This commit is contained in:
benpicco 2019-09-15 13:04:25 +02:00 committed by GitHub
commit 65b7102608
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 4 deletions

View File

@ -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)

View File

@ -498,6 +498,49 @@ print-size: $(ELFFILE)
endif # BUILD_IN_DOCKER
# Rules to check the correctness of thin archives.
relpath = $(shell realpath --relative-to=$(abspath .) $(1))
# Each ARCHECK file contains all the absolute paths found inside the archive.
BASELIB_ARCHECKS = $(patsubst %.a,%.a-check,$(filter %.a,$(BASELIBS)))
# For each a file, print the absolute paths found inside it
# If "ar t" is called with an absolute path it will print an abs path regardless
# of how the archive is internally
# In case of a malformed archive, ar prints to stderr (and sets an error code).
# Doing `2>&1` is hacky, the correct thing would be to get the exit code.
# The `| %.a` is necessary to be able to check file produced in docker.
%.a-check: %.a
$(Q)$(AR) t $(call relpath,$<) 2>&1 | grep '^/' | '$(LAZYSPONGE)' $(LAZYSPONGE_FLAGS) '$@'
# There's no point on keeping files whose content is later copied to another file
.INTERMEDIATE: $(BASELIB_ARCHECKS)
ARCHIVE_CHECK = $(BINDIR)/$(APPLICATION).archive-check
$(ARCHIVE_CHECK): $(BASELIB_ARCHECKS)
$(Q)cat $^ | '$(LAZYSPONGE)' $(LAZYSPONGE_FLAGS) '$@'
# Rule to check if thin archives are correctly produced, that is, with a correct
# relative path.
ifeq ($(BUILD_IN_DOCKER),1)
archive-check: ..in-docker-container
else
archive-check: $(ARCHIVE_CHECK) FORCE
@if [ -s '$<' ] ; then \
$(COLOR_ECHO) '$(COLOR_RED)Found the following absolute paths in archives' ;\
cat '$<';\
$(COLOR_ECHO) '$(COLOR_RESET)' ;\
exit 1;\
elif [ -f '$<' ] ; then \
$(COLOR_ECHO) '$(COLOR_GREEN)Archives correctly formed$(COLOR_RESET)' ;\
else \
$(COLOR_ECHO) '$(COLOR_RED)Unexpected error (file not found)$(COLOR_RESET)' ;\
exit 1;\
fi
endif # BUILD_IN_DOCKER
# Check given command is available in the path
# check_cmd 'command' 'description'
define check_cmd

View File

@ -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

View File

@ -9,6 +9,7 @@ export DOCKER_MAKECMDGOALS_POSSIBLE = \
scan-build \
scan-build-analyze \
tests-% \
archive-check \
#
export DOCKER_MAKECMDGOALS = $(filter $(DOCKER_MAKECMDGOALS_POSSIBLE),$(MAKECMDGOALS))

View File

@ -2,7 +2,7 @@
# Define application sketches module, it will be generated into $(BINDIR)
SKETCH_MODULE ?= arduino_sketches
SKETCH_MODULE_DIR ?= $(BINDIR)/$(SKETCH_MODULE)
SKETCH_MODULE_DIR ?= $(BINDIR)/$(SKETCH_MODULE)_src
SKETCHES = $(wildcard $(APPDIR)/*.sketch)
include $(RIOTBASE)/sys/arduino/sketches.inc.mk

View File

@ -19,7 +19,8 @@ SKETCH_GENERATED_FILES = $(SKETCH_MODULE_DIR)/Makefile $(SKETCH_MODULE_DIR)/$(SK
# Building the module files
# Do not use $^ in receipes as Makefile is also a prerequisite
$(SKETCH_MODULE_DIR)/Makefile: $(SKETCH_MODULE_DIR)/$(SKETCH_CPP)
$(Q)echo 'SRCXX = $(SKETCH_CPP)' > $@
$(Q)echo 'MODULE = $(SKETCH_MODULE)' > $@
$(Q)echo 'SRCXX = $(SKETCH_CPP)' >> $@
$(Q)echo 'include $$(RIOTBASE)/Makefile.base' >> $@
$(SKETCH_MODULE_DIR)/$(SKETCH_CPP): $(SKETCHES_ALL)
@mkdir -p $(@D)