From 06bc8d6aa388b1f24789c5f29e312eb199e74619 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 23 Aug 2012 12:39:31 -0500 Subject: [PATCH 01/10] Allow passing extra flags --- arduino-mk/Arduino.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index d50ff22..dc2ee0f 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -575,10 +575,10 @@ CPPFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -DARDUINO=$(ARDUINO_VERSION) \ -I. -I$(ARDUINO_CORE_PATH) -I$(ARDUINO_VAR_PATH)/$(VARIANT) \ $(SYS_INCLUDES) $(USER_INCLUDES) -g -Os -w -Wall \ -ffunction-sections -fdata-sections -CFLAGS = -std=gnu99 -CXXFLAGS = -fno-exceptions +CFLAGS = -std=gnu99 $(EXTRA_FLAGS) $(EXTRA_CFLAGS) +CXXFLAGS = -fno-exceptions $(EXTRA_FLAGS) $(EXTRA_CXXFLAGS) ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp -LDFLAGS = -mmcu=$(MCU) -Wl,--gc-sections -Os +LDFLAGS = -mmcu=$(MCU) -Wl,--gc-sections -Os $(EXTRA_FLAGS) $(EXTRA_CXXFLAGS) # Expand and pick the first port ARD_PORT = $(firstword $(wildcard $(ARDUINO_PORT))) From aaed1fc6faefb93fb810a5f28491c764ffb032e2 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 23 Aug 2012 12:39:42 -0500 Subject: [PATCH 02/10] Make listing files more useful --- arduino-mk/Arduino.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index dc2ee0f..5dad154 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -705,7 +705,7 @@ $(OBJDIR)/%.eep: $(OBJDIR)/%.elf --change-section-lma .eeprom=0 -O ihex $< $@ $(OBJDIR)/%.lss: $(OBJDIR)/%.elf - $(OBJDUMP) -h -S $< > $@ + $(OBJDUMP) -h --source --demangle --wide $< > $@ $(OBJDIR)/%.sym: $(OBJDIR)/%.elf $(NM) -n $< > $@ From 87060fa5c2d1f55375f643ac98f7c7818a8615ce Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 20 Sep 2012 11:28:42 -0500 Subject: [PATCH 03/10] Add knowledge of device-specific assembler --- arduino-mk/Arduino.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 5dad154..a71def9 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -536,6 +536,7 @@ DEP_FILE = $(OBJDIR)/depends.mk # Names of executables CC = $(AVR_TOOLS_PATH)/avr-gcc CXX = $(AVR_TOOLS_PATH)/avr-g++ +AS = $(AVR_TOOLS_PATH)/avr-as OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump AR = $(AVR_TOOLS_PATH)/avr-ar From 24c2366f26d68f242353a8d5471320fe56adde47 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 20 Sep 2012 11:29:15 -0500 Subject: [PATCH 04/10] Use variables instead of hardcoded commands --- arduino-mk/Arduino.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index a71def9..0fb384b 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -697,8 +697,8 @@ $(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.cpp # various object conversions $(OBJDIR)/%.hex: $(OBJDIR)/%.elf $(OBJCOPY) -O ihex -R .eeprom $< $@ - @echo - @echo + @$(ECHO) + @$(ECHO) $(call avr_size,$<,$@) $(OBJDIR)/%.eep: $(OBJDIR)/%.elf @@ -787,7 +787,7 @@ clean: $(REMOVE) $(LOCAL_OBJS) $(CORE_OBJS) $(LIB_OBJS) $(CORE_LIB) $(TARGETS) $(DEP_FILE) $(DEPS) $(USER_LIB_OBJS) depends: $(DEPS) - cat $(DEPS) > $(DEP_FILE) + $(CAT) $(DEPS) > $(DEP_FILE) size: $(OBJDIR) $(TARGET_HEX) $(call avr_size,$(TARGET_ELF),$(TARGET_HEX)) From 05a31db4817b57101d7a2a29fed099ed63e0a4c4 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 20 Sep 2012 11:29:26 -0500 Subject: [PATCH 05/10] Make disasm more helpful --- arduino-mk/Arduino.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 0fb384b..5ed7206 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -798,7 +798,8 @@ show_boards: monitor: $(MONITOR_CMD) $(ARD_PORT) $(MONITOR_BAUDRATE) -disasm: all $(OBJDIR)/$(TARGET).lss +disasm: $(OBJDIR)/$(TARGET).lss + @$(ECHO) The compiled ELF file has been disassembled to $(OBJDIR)/$(TARGET).lss .PHONY: all clean depends upload raw_upload reset reset_stty size show_boards monitor From 6041f6201da0cacedaec55504cf31365120dbe30 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 20 Sep 2012 11:29:36 -0500 Subject: [PATCH 06/10] Change .sym output --- arduino-mk/Arduino.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 5ed7206..e564369 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -709,7 +709,7 @@ $(OBJDIR)/%.lss: $(OBJDIR)/%.elf $(OBJDUMP) -h --source --demangle --wide $< > $@ $(OBJDIR)/%.sym: $(OBJDIR)/%.elf - $(NM) -n $< > $@ + $(NM) --size-sort --demangle --reverse-sort --line-numbers $< > $@ ######################################################################## # From 84648978fbdcd569e12ac43579d452941b78a3e1 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 20 Sep 2012 11:30:46 -0500 Subject: [PATCH 07/10] Provide symbol_sizes and generated_assembly targets. Also update existing auxiliary targets with help, and make the .PHONY list complete and in order. --- arduino-mk/Arduino.mk | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index e564369..5179f9d 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -687,6 +687,13 @@ $(OBJDIR)/%.o: $(OBJDIR)/%.cpp $(OBJDIR)/%.d: $(OBJDIR)/%.cpp $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o) +# generated assembly +$(OBJDIR)/%.s: $(OBJDIR)/%.cpp + $(CXX) -S -fverbose-asm $(CPPFLAGS) $(CXXFLAGS) $< -o $@ + +#$(OBJDIR)/%.lst: $(OBJDIR)/%.s +# $(AS) -mmcu=$(MCU) -alhnd $< > $@ + # core files $(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.c $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ @@ -801,6 +808,12 @@ monitor: disasm: $(OBJDIR)/$(TARGET).lss @$(ECHO) The compiled ELF file has been disassembled to $(OBJDIR)/$(TARGET).lss -.PHONY: all clean depends upload raw_upload reset reset_stty size show_boards monitor +symbol_sizes: $(OBJDIR)/$(TARGET).sym + @$(ECHO) A symbol listing sorted by their size have been dumped to $(OBJDIR)/$(TARGET).sym + +generated_assembly: $(OBJDIR)/$(TARGET).s + @$(ECHO) Compiler-generated assembly for the main input source has been dumped to $(OBJDIR)/$(TARGET).s + +.PHONY: all upload raw_upload reset reset_stty ispload clean depends size show_boards monitor disasm symbol_sizes generated_assembly include $(DEP_FILE) From a814a9c276bd6586f50e366f8df32c2c93ee7651 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 1 Nov 2012 10:33:46 -0500 Subject: [PATCH 08/10] Be able to silence configuration output --- arduino-mk/Arduino.mk | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 5179f9d..b90f81b 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -124,6 +124,8 @@ # instead copy them to e.g. /home/mjo/arduino.mk/bin then set # ARDML_DIR = /home/mjo/arduino.mk # +# If you'd rather not see the configuration output, define ARDUINO_QUIET. +# ######################################################################## # # DEPENDENCIES @@ -254,19 +256,25 @@ dir_if_exists = $(if $(wildcard $(1)$(2)),$(1)) # the number of bytes indicated by the second argument. space_pad_to = $(shell echo $(1) " " | head --bytes=$(2)) +ifndef ARDUINO_QUIET + arduino_output = $(info $(1)) +else + arduino_output = +endif + # Call with some text, and a prefix tag if desired (like [AUTODETECTED]), -show_config_info = $(info - $(call space_pad_to,$(2),20) $(1)) +show_config_info = $(call arduino_output,- $(call space_pad_to,$(2),20) $(1)) # Call with the name of the variable, a prefix tag if desired (like [AUTODETECTED]), # and an explanation if desired (like (found in $$PATH) show_config_variable = $(call show_config_info,$(1) = $($(1)) $(3),$(2)) # Just a nice simple visual separator -show_separator = $(info -------------------------) +show_separator = $(call arduino_output,-------------------------) $(call show_separator) -$(info Arduino.mk Configuration:) +$(call arduino_output,Arduino.mk Configuration:) ifndef ARDUINO_DIR AUTO_ARDUINO_DIR := $(firstword \ @@ -598,7 +606,7 @@ endif ifneq (,$(strip $(ARDUINO_LIBS))) - $(info -) + $(call arduino_output,-) $(call show_config_info,ARDUINO_LIBS =) endif ifneq (,$(strip $(USER_LIB_NAMES))) From ee98d0c89b66adb5c54c0867d14d6c72261ef9a9 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 1 Nov 2012 10:34:09 -0500 Subject: [PATCH 09/10] Make everybody depend on the makefile, in case cflags are changed, etc. --- arduino-mk/Arduino.mk | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index b90f81b..a12c5d2 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -649,81 +649,82 @@ $(OBJDIR)/libs/%.o: $(USER_LIB_PATH)/%.c # normal local sources # .o rules are for objects, .d for dependency tracking # there seems to be an awful lot of duplication here!!! -$(OBJDIR)/%.o: %.c +COMMON_DEPS := Makefile +$(OBJDIR)/%.o: %.c $(COMMON_DEPS) $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ -$(OBJDIR)/%.o: %.cc +$(OBJDIR)/%.o: %.cc $(COMMON_DEPS) $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ -$(OBJDIR)/%.o: %.cpp +$(OBJDIR)/%.o: %.cpp $(COMMON_DEPS) $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ -$(OBJDIR)/%.o: %.S +$(OBJDIR)/%.o: %.S $(COMMON_DEPS) $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@ -$(OBJDIR)/%.o: %.s +$(OBJDIR)/%.o: %.s $(COMMON_DEPS) $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@ -$(OBJDIR)/%.d: %.c +$(OBJDIR)/%.d: %.c $(COMMON_DEPS) $(CC) -MM $(CPPFLAGS) $(CFLAGS) $< -MF $@ -MT $(@:.d=.o) -$(OBJDIR)/%.d: %.cc +$(OBJDIR)/%.d: %.cc $(COMMON_DEPS) $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o) -$(OBJDIR)/%.d: %.cpp +$(OBJDIR)/%.d: %.cpp $(COMMON_DEPS) $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o) -$(OBJDIR)/%.d: %.S +$(OBJDIR)/%.d: %.S $(COMMON_DEPS) $(CC) -MM $(CPPFLAGS) $(ASFLAGS) $< -MF $@ -MT $(@:.d=.o) -$(OBJDIR)/%.d: %.s +$(OBJDIR)/%.d: %.s $(COMMON_DEPS) $(CC) -MM $(CPPFLAGS) $(ASFLAGS) $< -MF $@ -MT $(@:.d=.o) # the pde -> cpp -> o file -$(OBJDIR)/%.cpp: %.pde +$(OBJDIR)/%.cpp: %.pde $(COMMON_DEPS) $(ECHO) '#include "WProgram.h"' > $@ $(CAT) $< >> $@ # the ino -> cpp -> o file -$(OBJDIR)/%.cpp: %.ino +$(OBJDIR)/%.cpp: %.ino $(COMMON_DEPS) $(ECHO) '#include ' > $@ $(CAT) $< >> $@ -$(OBJDIR)/%.o: $(OBJDIR)/%.cpp +$(OBJDIR)/%.o: $(OBJDIR)/%.cpp $(COMMON_DEPS) $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ -$(OBJDIR)/%.d: $(OBJDIR)/%.cpp +$(OBJDIR)/%.d: $(OBJDIR)/%.cpp $(COMMON_DEPS) $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o) # generated assembly -$(OBJDIR)/%.s: $(OBJDIR)/%.cpp +$(OBJDIR)/%.s: $(OBJDIR)/%.cpp $(COMMON_DEPS) $(CXX) -S -fverbose-asm $(CPPFLAGS) $(CXXFLAGS) $< -o $@ #$(OBJDIR)/%.lst: $(OBJDIR)/%.s # $(AS) -mmcu=$(MCU) -alhnd $< > $@ # core files -$(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.c +$(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.c $(COMMON_DEPS) $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ -$(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.cpp +$(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.cpp $(COMMON_DEPS) $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ # various object conversions -$(OBJDIR)/%.hex: $(OBJDIR)/%.elf +$(OBJDIR)/%.hex: $(OBJDIR)/%.elf $(COMMON_DEPS) $(OBJCOPY) -O ihex -R .eeprom $< $@ @$(ECHO) @$(ECHO) $(call avr_size,$<,$@) -$(OBJDIR)/%.eep: $(OBJDIR)/%.elf +$(OBJDIR)/%.eep: $(OBJDIR)/%.elf $(COMMON_DEPS) -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ --change-section-lma .eeprom=0 -O ihex $< $@ -$(OBJDIR)/%.lss: $(OBJDIR)/%.elf +$(OBJDIR)/%.lss: $(OBJDIR)/%.elf $(COMMON_DEPS) $(OBJDUMP) -h --source --demangle --wide $< > $@ -$(OBJDIR)/%.sym: $(OBJDIR)/%.elf +$(OBJDIR)/%.sym: $(OBJDIR)/%.elf $(COMMON_DEPS) $(NM) --size-sort --demangle --reverse-sort --line-numbers $< > $@ ######################################################################## From edd514d65cc70b140e2882900e461ce87294bdd8 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 1 Nov 2012 10:57:11 -0500 Subject: [PATCH 10/10] Make the makefile error if the arduino port is not present. --- arduino-mk/Arduino.mk | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index a12c5d2..84c451b 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -589,8 +589,8 @@ CXXFLAGS = -fno-exceptions $(EXTRA_FLAGS) $(EXTRA_CXXFLAGS) ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp LDFLAGS = -mmcu=$(MCU) -Wl,--gc-sections -Os $(EXTRA_FLAGS) $(EXTRA_CXXFLAGS) -# Expand and pick the first port -ARD_PORT = $(firstword $(wildcard $(ARDUINO_PORT))) +# Returns the Arduino port (first wildcard expansion) if it exists, otherwise it errors. +get_arduino_port = $(if $(wildcard $(ARDUINO_PORT)),$(firstword $(wildcard $(ARDUINO_PORT))),$(error Arduino port $(ARDUINO_PORT) not found!)) # Command for avr_size: do $(call avr_size,elffile,hexfile) ifneq (,$(findstring AVR,$(shell $(SIZE) --help))) @@ -740,7 +740,7 @@ ifdef AVRDUDE_CONF AVRDUDE_COM_OPTS += -C $(AVRDUDE_CONF) endif -AVRDUDE_ARD_OPTS = -c $(AVRDUDE_ARD_PROGRAMMER) -b $(AVRDUDE_ARD_BAUDRATE) -P $(ARD_PORT) +AVRDUDE_ARD_OPTS = -c $(AVRDUDE_ARD_PROGRAMMER) -b $(AVRDUDE_ARD_BAUDRATE) -P $(call get_arduino_port) ifndef ISP_PROG ISP_PROG = -c stk500v2 @@ -775,7 +775,7 @@ raw_upload: $(TARGET_HEX) -U flash:w:$(TARGET_HEX):i reset: - $(RESET_CMD) $(ARD_PORT) + $(RESET_CMD) $(call get_arduino_port) # stty on MacOS likes -F, but on Debian it likes -f redirecting # stdin/out appears to work but generates a spurious error on MacOS at @@ -784,9 +784,9 @@ reset_stty: for STTYF in 'stty -F' 'stty --file' 'stty -f' 'stty <' ; \ do $$STTYF /dev/tty >/dev/null 2>/dev/null && break ; \ done ;\ - $$STTYF $(ARD_PORT) hupcl ;\ + $$STTYF $(call get_arduino_port) hupcl ;\ (sleep 0.1 || sleep 1) ;\ - $$STTYF $(ARD_PORT) -hupcl + $$STTYF $(call get_arduino_port) -hupcl ispload: $(TARGET_HEX) $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e \ @@ -812,7 +812,7 @@ show_boards: $(PARSE_BOARD_CMD) --boards monitor: - $(MONITOR_CMD) $(ARD_PORT) $(MONITOR_BAUDRATE) + $(MONITOR_CMD) $(call get_arduino_port) $(MONITOR_BAUDRATE) disasm: $(OBJDIR)/$(TARGET).lss @$(ECHO) The compiled ELF file has been disassembled to $(OBJDIR)/$(TARGET).lss