@@ -28,12 +28,13 @@ VPATH :=
2828
2929# Convert all SRC to OBJ
3030define OBJ_FROM_SRC
31- $(patsubst % .c,$1/% .o,$(patsubst % .cpp,$1/% .o,$(patsubst % .cc,$1/% .o,$(patsubst % .S,$1/% .o,$($ 1_SRC ) ) ) ) )
31+ $(patsubst % .c,$1/% .o,$(patsubst % .cpp,$1/% .o,$(patsubst % .cc,$1/% .o,$(patsubst % .S,$1/% .o,$(patsubst % .clib,$1/ % .a, $( $ 1_SRC) ) ) ) ) )
3232endef
3333$(foreach OUTPUT,$(OUTPUTS),$(eval $(OUTPUT)_OBJ +=$(call OBJ_FROM_SRC,$(OUTPUT))))
3434
3535# Define a list of all objects
3636OBJ := $(foreach OUTPUT,$(OUTPUTS ) ,$($(OUTPUT ) _OBJ) )
37+ NO_LTO_OBJ := $(filter % .a,$(OBJ ) )
3738
3839MASTER_OUTPUT := $(firstword $(OUTPUTS ) )
3940
@@ -81,7 +82,9 @@ CSTANDARD = -std=gnu99
8182# -Wall...: warning level
8283# -Wa,...: tell GCC to pass this to the assembler.
8384# -adhlns...: create assembler listing
84- CFLAGS += -g$(DEBUG )
85+ ifndef SKIP_DEBUG_INFO
86+ CFLAGS += -g$(DEBUG )
87+ endif
8588CFLAGS += $(CDEFS )
8689CFLAGS += -O$(OPT )
8790# add color
@@ -110,7 +113,9 @@ CFLAGS += $(CSTANDARD)
110113# -Wall...: warning level
111114# -Wa,...: tell GCC to pass this to the assembler.
112115# -adhlns...: create assembler listing
113- CPPFLAGS += -g$(DEBUG )
116+ ifndef SKIP_DEBUG_INFO
117+ CPPFLAGS += -g$(DEBUG )
118+ endif
114119CPPFLAGS += $(CPPDEFS )
115120CPPFLAGS += -O$(OPT )
116121# to supress "warning: only initialized variables can be placed into program memory area"
@@ -138,7 +143,11 @@ CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
138143# -listing-cont-lines: Sets the maximum number of continuation lines of hex
139144# dump that will be displayed for a given single line of source input.
140145ASFLAGS += $(ADEFS )
141- ASFLAGS += -Wa,-adhlns=$(@:%.o=%.lst ) ,-gstabs,--listing-cont-lines=100
146+ ifndef SKIP_DEBUG_INFO
147+ ASFLAGS += -Wa,-adhlns=$(@:%.o=%.lst ) ,-gstabs,--listing-cont-lines=100
148+ else
149+ ASFLAGS += -Wa,-adhlns=$(@:%.o=%.lst ) ,--listing-cont-lines=100
150+ endif
142151
143152# ---------------- Library Options ----------------
144153# Minimalistic printf version
@@ -210,6 +219,11 @@ ALL_CFLAGS = $(MCUFLAGS) $(CFLAGS) $(EXTRAFLAGS)
210219ALL_CPPFLAGS = $(MCUFLAGS ) -x c++ $(CPPFLAGS ) $(EXTRAFLAGS )
211220ALL_ASFLAGS = $(MCUFLAGS ) -x assembler-with-cpp $(ASFLAGS ) $(EXTRAFLAGS )
212221
222+ define NO_LTO
223+ $(patsubst % .a,% .o,$1) : NOLTO_CFLAGS += -fno-lto
224+ endef
225+ $(foreach LOBJ, $(NO_LTO_OBJ), $(eval $(call NO_LTO,$(LOBJ))))
226+
213227MOVE_DEP = mv -f $(patsubst % .o,% .td,$@ ) $(patsubst % .o,% .d,$@ )
214228
215229
@@ -290,8 +304,8 @@ $1_INCFLAGS := $$(patsubst %,-I%,$$($1_INC))
290304ifdef $1_CONFIG
291305$1_CONFIG_FLAGS += $$(patsubst % ,-include % ,$$($1_CONFIG ) )
292306endif
293- $1_CFLAGS = $$(ALL_CFLAGS ) $$($1_DEFS ) $$($1_INCFLAGS ) $$($1_CONFIG_FLAGS )
294- $1_CPPFLAGS= $$(ALL_CPPFLAGS ) $$($1_DEFS ) $$($1_INCFLAGS ) $$($1_CONFIG_FLAGS )
307+ $1_CFLAGS = $$(ALL_CFLAGS ) $$($1_DEFS ) $$($1_INCFLAGS ) $$($1_CONFIG_FLAGS ) $$( NOLTO_CFLAGS )
308+ $1_CPPFLAGS= $$(ALL_CPPFLAGS ) $$($1_DEFS ) $$($1_INCFLAGS ) $$($1_CONFIG_FLAGS ) $$( NOLTO_CFLAGS )
295309$1_ASFLAGS= $$(ALL_ASFLAGS ) $$($1_DEFS ) $$($1_INCFLAGS ) $$($1_CONFIG_FLAGS )
296310
297311# Compile: create object files from C source files.
@@ -321,6 +335,12 @@ $1/%.o : %.S $1/asflags.txt $1/compiler.txt | $(BEGIN)
321335 $$(eval CMD=$$(CC ) -c $$($1_ASFLAGS ) $$< -o $$@ )
322336 @$$(BUILD_CMD )
323337
338+ $1/%.a : $1/%.o
339+ @mkdir -p $$(@D )
340+ @$(SILENT ) || printf "Archiving: $$< " | $$(AWK_CMD )
341+ $$(eval CMD=$$(AR ) $$@ $$< )
342+ @$$(BUILD_CMD )
343+
324344$1/force:
325345
326346$1/cflags.txt: $1/force
@@ -346,7 +366,7 @@ $(MASTER_OUTPUT)/ldflags.txt: $(MASTER_OUTPUT)/force
346366
347367
348368# We have to use static rules for the .d files for some reason
349- DEPS = $(patsubst % .o,% .d,$(OBJ ) )
369+ DEPS = $(patsubst % .o,% .d,$(patsubst % .a, % .o, $( OBJ ) ) )
350370# Keep the .d files
351371.PRECIOUS : $(DEPS )
352372# Empty rule to force recompilation if the .d file is missing
@@ -391,7 +411,7 @@ $(shell mkdir -p $(BUILD_DIR) 2>/dev/null)
391411$(eval $(foreach OUTPUT,$(OUTPUTS),$(shell mkdir -p $(OUTPUT) 2>/dev/null)))
392412
393413# Include the dependency files.
394- -include $(patsubst % .o,% .d,$(OBJ ) )
414+ -include $(patsubst % .o,% .d,$(patsubst % .a, % .o, $( OBJ ) ) )
395415
396416
397417# Listing of phony targets.
0 commit comments