Skip to content

Commit ab261dd

Browse files
committed
Added LTO flags etc. to provide smaller/faster AVR code.
Works with 1.6.10 or later; or 1.0.x with avr-gcc toolchain 4.8+
1 parent 7c28446 commit ab261dd

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

Arduino.mk

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,6 @@ ifndef OBJDUMP_NAME
392392
OBJDUMP_NAME = avr-objdump
393393
endif
394394

395-
ifndef AR_NAME
396-
AR_NAME = avr-ar
397-
endif
398-
399395
ifndef SIZE_NAME
400396
SIZE_NAME = avr-size
401397
endif
@@ -1031,16 +1027,32 @@ ifneq ($(CATERINA),)
10311027
CPPFLAGS += -DUSB_VID=$(USB_VID) -DUSB_PID=$(USB_PID)
10321028
endif
10331029

1030+
# avr-gcc version that we can do maths on
1031+
CC_VERNUM = $(shell $(CC) -dumpversion | sed 's/\.//g')
1032+
1033+
# moved from above so we can find version-dependant ar
1034+
ifndef AR_NAME
1035+
ifeq ($(shell expr $(CC_VERNUM) '>' 480), 1)
1036+
AR_NAME = avr-gcc-ar
1037+
else
1038+
AR_NAME = avr-ar
1039+
endif
1040+
endif
1041+
10341042
ifndef CFLAGS_STD
1035-
CFLAGS_STD =
1043+
ifeq ($(shell expr $(CC_VERNUM) '>' 480), 1)
1044+
CFLAGS_STD = -std=gnu11 -flto -fno-fat-lto-objects
1045+
else
1046+
CFLAGS_STD =
1047+
endif
10361048
$(call show_config_variable,CFLAGS_STD,[DEFAULT])
10371049
else
10381050
$(call show_config_variable,CFLAGS_STD,[USER])
10391051
endif
10401052

10411053
ifndef CXXFLAGS_STD
1042-
ifeq ($(shell expr $(ARDUINO_VERSION) '>' 150), 1)
1043-
CXXFLAGS_STD = -std=gnu++11 -fno-threadsafe-statics
1054+
ifeq ($(shell expr $(CC_VERNUM) '>' 480), 1)
1055+
CXXFLAGS_STD = -std=gnu++11 -fno-threadsafe-statics -flto
10441056
else
10451057
CXXFLAGS_STD =
10461058
endif
@@ -1050,9 +1062,15 @@ else
10501062
endif
10511063

10521064
CFLAGS += $(CFLAGS_STD)
1053-
CXXFLAGS += -fno-exceptions $(CXXFLAGS_STD)
1065+
CXXFLAGS += -fpermissive -fno-exceptions $(CXXFLAGS_STD)
10541066
ASFLAGS += -x assembler-with-cpp
1067+
ifeq ($(shell expr $(CC_VERNUM) '>' 480), 1)
1068+
ASFLAGS += -flto
1069+
endif
10551070
LDFLAGS += -$(MCU_FLAG_NAME)=$(MCU) -Wl,--gc-sections -O$(OPTIMIZATION_LEVEL)
1071+
ifeq ($(shell expr $(CC_VERNUM) '>' 480), 1)
1072+
LDFLAGS += -flto -fuse-linker-plugin
1073+
endif
10561074
SIZEFLAGS ?= --mcu=$(MCU) -C
10571075

10581076
# for backwards compatibility, grab ARDUINO_PORT if the user has it set

0 commit comments

Comments
 (0)