summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2021-10-13 00:57:45 +0700
committerGitHub <[email protected]>2021-10-13 00:57:45 +0700
commitb26cc2cc4694d883cc060c03c57d201753b4c72a (patch)
tree3d4fc6a647f388c7526cb6282e013081c7e0a9c7 /examples
parent2ba690d31df6e2908cb683494171aa3739bd8991 (diff)
Add linkermap for size analysis (#1136)
* add NO_LTO option to make * add linkermap submodule and linkermap target * add linkermap to ci build * linkermap doesn't work with esp32sx map file yet * add note for linkermap target
Diffstat (limited to 'examples')
-rw-r--r--examples/rules.mk31
1 files changed, 21 insertions, 10 deletions
diff --git a/examples/rules.mk b/examples/rules.mk
index 7e494b3d8..92fa4e14d 100644
--- a/examples/rules.mk
+++ b/examples/rules.mk
@@ -5,12 +5,11 @@
# Set all as default goal
.DEFAULT_GOAL := all
-# ESP32-SX and RP2040 has its own CMake build system
-ifneq ($(FAMILY),esp32s2)
-ifneq ($(FAMILY),esp32s3)
-ifneq ($(FAMILY),rp2040)
+# ESP32-Sx and RP2040 has its own CMake build system
+ifeq (,$(findstring $(FAMILY),esp32s2 esp32s3 rp2040))
+
# ---------------------------------------
-# GNU Make build system
+# Compiler Flags
# ---------------------------------------
# libc
@@ -44,6 +43,12 @@ INC += $(TOP)/src
CFLAGS += $(addprefix -I,$(INC))
+# LTO makes it difficult to analyze map file for optimizing size purpose
+# We will run this option in ci
+ifeq ($(NO_LTO),1)
+CFLAGS := $(filter-out -flto,$(CFLAGS))
+endif
+
LDFLAGS += $(CFLAGS) -Wl,-T,$(TOP)/$(LD_FILE) -Wl,[email protected] -Wl,-cref -Wl,-gc-sections
ifneq ($(SKIP_NANOLIB), 1)
LDFLAGS += -specs=nosys.specs -specs=nano.specs
@@ -67,6 +72,10 @@ $(info LDFLAGS $(LDFLAGS)) $(info )
$(info ASFLAGS $(ASFLAGS)) $(info )
endif
+# ---------------------------------------
+# Rules
+# ---------------------------------------
+
all: $(BUILD)/$(PROJECT).bin $(BUILD)/$(PROJECT).hex size
uf2: $(BUILD)/$(PROJECT).uf2
@@ -126,11 +135,17 @@ $(BUILD)/obj/%_asm.o: %.S
@echo AS $(notdir $@)
@$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $<
+endif # GNU Make
+
size: $(BUILD)/$(PROJECT).elf
-@echo ''
@$(SIZE) $<
-@echo ''
+# linkermap must be install previously at https://github.com/hathach/linkermap
+linkermap: $(BUILD)/$(PROJECT).elf
+ @linkermap -v $<.map
+
.PHONY: clean
clean:
ifeq ($(CMDEXE),1)
@@ -139,10 +154,6 @@ else
$(RM) -rf $(BUILD)
endif
-endif
-endif
-endif # GNU Make
-
# ---------------------------------------
# Flash Targets
# ---------------------------------------
@@ -204,4 +215,4 @@ copy-artifact: $(BIN)
# Print out the value of a make variable.
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
print-%:
- @echo $* = $($*)
+ @echo $* = $($*) \ No newline at end of file