From 854a7aa8c03bd4bc5c5e9fc6fb5d6c46bf860472 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 28 Jun 2012 18:28:22 -0500 Subject: [PATCH 01/21] Be able to autodetect ARDUINO_DIR in some cases --- arduino-mk/Arduino.mk | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 5261afa..18a9860 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -263,6 +263,23 @@ # ######################################################################## +dir_if_exists = $(shell test -e $(1)$(2) && echo $(1) || true) + +ifndef ARDUINO_DIR +NIX_DEFAULT_ARDUINO_DIR := $(call dir_if_exists,/usr/share/arduino) +ifdef NIX_DEFAULT_ARDUINO_DIR +ARDUINO_DIR = $(NIX_DEFAULT_ARDUINO_DIR) +endif + +MAC_DEFAULT_ARDUINO_DIR := $(call dir_if_exists,/Applications/Arduino.app/Contents/Resources/Java) +ifdef MAC_DEFAULT_ARDUINO_DIR +ARDUINO_DIR = $(MAC_DEFAULT_ARDUINO_DIR) +endif + +ifdef ARDUINO_DIR +$(info Using autodetected ARDUINO_DIR '$(ARDUINO_DIR)') +endif +endif ######################################################################## # # Default TARGET to cwd (ex Daniele Vergini) From 7f3fe664956930c35181d6c2f8198f565177718a Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 28 Jun 2012 18:32:23 -0500 Subject: [PATCH 02/21] Only use Arduino's bundled AVR tools if they exist, otherwise try using "which" --- arduino-mk/Arduino.mk | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 18a9860..6102893 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -301,10 +301,26 @@ endif ifdef ARDUINO_DIR ifndef AVR_TOOLS_DIR -AVR_TOOLS_DIR = $(ARDUINO_DIR)/hardware/tools/avr + +BUNDLED_AVR_TOOLS_DIR := $(call dir_if_exists,$(ARDUINO_DIR)/hardware/tools/avr) + +ifdef BUNDLED_AVR_TOOLS_DIR +$(info Using autodetected (bundled) AVR_TOOLS_DIR '$(BUNDLED_AVR_TOOLS_DIR)') +AVR_TOOLS_DIR = $(BUNDLED_AVR_TOOLS_DIR) # The avrdude bundled with Arduino can't find it's config AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf -endif + +else + +SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which avr-gcc))/..)) +ifdef SYSTEMPATH_AVR_TOOLS_DIR +$(info Using autodetected (from PATH) AVR_TOOLS_DIR '$(SYSTEMPATH_AVR_TOOLS_DIR)') +AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR) +endif # SYSTEMPATH_AVR_TOOLS_DIR + +endif # BUNDLED_AVR_TOOLS_EIR + +endif #ndef AVR_TOOLS_DIR ifndef AVR_TOOLS_PATH AVR_TOOLS_PATH = $(AVR_TOOLS_DIR)/bin From dfd32d2b2cbc3925f8967dc3abff6c824a238495 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 28 Jun 2012 18:32:41 -0500 Subject: [PATCH 03/21] Properly categorize libs into user and system automatically. --- arduino-mk/Arduino.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 6102893..d846977 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -514,8 +514,8 @@ CAT = cat ECHO = echo # General arguments -SYS_LIBS = $(patsubst %,$(ARDUINO_LIB_PATH)/%,$(ARDUINO_LIBS)) -USER_LIBS = $(patsubst %,$(USER_LIB_PATH)/%,$(ARDUINO_LIBS)) +SYS_LIBS = $(foreach libdir,$(patsubst %,$(ARDUINO_LIB_PATH)/%,$(ARDUINO_LIBS)),$(call dir_if_exists,$(libdir))) +USER_LIBS = $(foreach libdir,$(patsubst %,$(USER_LIB_PATH)/%,$(ARDUINO_LIBS)),$(call dir_if_exists,$(libdir))) SYS_INCLUDES = $(patsubst %,-I%,$(SYS_LIBS)) USER_INCLUDES = $(patsubst %,-I%,$(USER_LIBS)) LIB_C_SRCS = $(wildcard $(patsubst %,%/*.c,$(SYS_LIBS))) From 9027158e5f3db99e51f21432f7be9bfdb7ad476c Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 3 Jul 2012 12:36:00 -0500 Subject: [PATCH 04/21] Add a disasm target to build the .lss file. --- arduino-mk/Arduino.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index d846977..ab83302 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -721,6 +721,8 @@ show_boards: monitor: $(MONITOR_CMD) $(ARD_PORT) $(MONITOR_BAUDRATE) +disasm: all $(OBJDIR)/$(TARGET).lss + .PHONY: all clean depends upload raw_upload reset reset_stty size show_boards monitor include $(DEP_FILE) From 8896b8fcf60aea8ace1f2e08648dba5e1f60255f Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 12:29:33 -0500 Subject: [PATCH 05/21] Autodetect arduino version when possible --- arduino-mk/Arduino.mk | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index ab83302..f3c22e4 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -292,8 +292,17 @@ endif # # Arduino version number ifndef ARDUINO_VERSION + +# Remove all the decimals, and right-pad with zeros, and finally grab the first 3 bytes. +# Works for 1.0 and 1.0.1 +AUTO_ARDUINO_VERSION := $(shell cat $(ARDUINO_DIR)/lib/version.txt | sed -e 's/[.]//g' -e 's/$$/0000/' | head --bytes=3) +ifdef AUTO_ARDUINO_VERSION +$(info Using guessed/detected ARDUINO version define $(AUTO_ARDUINO_VERSION)) +ARDUINO_VERSION = $(AUTO_ARDUINO_VERSION) +else ARDUINO_VERSION = 100 endif +endif ######################################################################## # Arduino and system paths From abad0738c047e503819e174b970f2317c3541cf2 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 12:45:05 -0500 Subject: [PATCH 06/21] Deduce whether we have an avr-patched version of size, and use it. --- arduino-mk/Arduino.mk | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index f3c22e4..11c7cf0 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -548,6 +548,14 @@ LDFLAGS = -mmcu=$(MCU) -Wl,--gc-sections -Os # Expand and pick the first port ARD_PORT = $(firstword $(wildcard $(ARDUINO_PORT))) +# Command for avr_size: do $(call avr_size,elffile,hexfile) +SIZE_ACCEPTS_MCU = $(shell $(SIZE) --help | grep 'AVR' && echo TRUE || true) +ifdef SIZE_ACCEPTS_MCU +avr_size = $(SIZE) --mcu=$(MCU) --format=avr $(1) +else +avr_size = $(SIZE) $(2) +endif + # Implicit rules for building everything (needed to get everything in # the right directory) # @@ -722,7 +730,7 @@ depends: $(DEPS) cat $(DEPS) > $(DEP_FILE) size: $(OBJDIR) $(TARGET_HEX) - $(SIZE) $(TARGET_HEX) + $(call avr_size,$(TARGET_ELF),$(TARGET_HEX)) show_boards: $(PARSE_BOARD_CMD) --boards From 8273ef1153fc4ad103653749b980cc418f01dc4c Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 12:45:19 -0500 Subject: [PATCH 07/21] Dump size at the end of the build. --- arduino-mk/Arduino.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 11c7cf0..de16a0e 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -640,6 +640,9 @@ $(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.cpp # various object conversions $(OBJDIR)/%.hex: $(OBJDIR)/%.elf $(OBJCOPY) -O ihex -R .eeprom $< $@ + # Dump size for microcontroller. + echo + $(call avr_size,$<,$@) $(OBJDIR)/%.eep: $(OBJDIR)/%.elf -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ From 040f5c7388367dc0633707e90fe86bb780a959ff Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 12:45:52 -0500 Subject: [PATCH 08/21] Remove trailing spaces --- arduino-mk/Arduino.mk | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index de16a0e..58337fe 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -6,7 +6,7 @@ # Copyright (C) 2010,2011,2012 Martin Oldfield , based on # work that is copyright Nicholas Zambetti, David A. Mellis & Hernando # Barragan. -# +# # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the @@ -39,13 +39,13 @@ # # 0.6 22.vi.2011 M J Oldfield # - added ard-parse-boards supports -# - added -lc to linker opts, +# - added -lc to linker opts, # on Fabien Le Lez's advice # # 0.7 12.vii.2011 M J Oldfield # - moved -lm to the end of linker opts, # to solve Frank Knopf's problem; -# - added -F to stty opts: Craig Hollabaugh +# - added -F to stty opts: Craig Hollabaugh # reckons it's good for Ubuntu # # 0.8 12.ii.2012 M J Oldfield @@ -72,12 +72,12 @@ # defined (ex Peplin) # - Added a monitor target which talks to the # Arduino serial port (Peplin's suggestion) -# - Rejigged PATH calculations for general +# - Rejigged PATH calculations for general # tidiness (ex Peplin) # - Moved the reset target to Perl for # clarity and better error handling (ex # Daniele Vergini) -# +# ######################################################################## # # PATHS YOU NEED TO SET UP @@ -90,7 +90,7 @@ # 1. Things which are included in this distribution e.g. ard-parse-boards # => ARDMK_DIR # -# 2. Things which are always in the Arduino distribution e.g. +# 2. Things which are always in the Arduino distribution e.g. # boards.txt, libraries, &c. # => ARDUINO_DIR # @@ -114,13 +114,13 @@ # ARDMK_DIR = /usr/local # AVR_TOOLS_DIR = /usr # -# You can either set these up in the Makefile, or put them in your +# You can either set these up in the Makefile, or put them in your # environment e.g. in your .bashrc # # If you don't install the ard-... binaries to /usr/local/bin, but # instead copy them to e.g. /home/mjo/arduino.mk/bin then set # ARDML_DIR = /home/mjo/arduino.mk -# +# ######################################################################## # # DEPENDENCIES @@ -148,7 +148,7 @@ # # ARDUINO_LIBS - A list of any libraries used by the sketch (we # assume these are in -# $(ARDUINO_DIR)/hardware/libraries +# $(ARDUINO_DIR)/hardware/libraries # # ARDUINO_PORT - The port where the Arduino can be found (only needed # when uploading @@ -182,7 +182,7 @@ # SERIAL MONITOR # # The serial monitor just invokes the GNU screen program with suitable -# options. For more information see screen (1) and search for +# options. For more information see screen (1) and search for # 'character special device'. # # The really useful thing to know is that ^A-k gets you out! @@ -207,7 +207,7 @@ # 1. Things which are included in this distribution e.g. ard-parse-boards # => ARDMK_DIR # -# 2. Things which are always in the Arduino distribution e.g. +# 2. Things which are always in the Arduino distribution e.g. # boards.txt, libraries, &c. # => ARDUINO_DIR # @@ -232,7 +232,7 @@ # AVR_TOOLS_DIR = /usr # # -# +# # ######################################################################## # @@ -246,7 +246,7 @@ # # You might also need to set the fuse bits, but typically they'll be # read from boards.txt, based on the BOARD_TAG variable: -# +# # ISP_LOCK_FUSE_PRE = 0x3f # ISP_LOCK_FUSE_POST = 0xcf # ISP_HIGH_FUSE = 0xdf @@ -255,7 +255,7 @@ # # I think the fuses here are fine for uploading to the ATmega168 # without bootloader. -# +# # To actually do this upload use the ispload target: # # make ispload @@ -281,7 +281,7 @@ $(info Using autodetected ARDUINO_DIR '$(ARDUINO_DIR)') endif endif ######################################################################## -# +# # Default TARGET to cwd (ex Daniele Vergini) ifndef TARGET TARGET = $(notdir $(CURDIR)) @@ -701,19 +701,19 @@ raw_upload: $(TARGET_HEX) $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \ -U flash:w:$(TARGET_HEX):i -reset: +reset: $(RESET_CMD) $(ARD_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 # least. Perhaps it would be better to just do it in perl ? -reset_stty: +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 ;\ (sleep 0.1 || sleep 1) ;\ - $$STTYF $(ARD_PORT) -hupcl + $$STTYF $(ARD_PORT) -hupcl ispload: $(TARGET_HEX) $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e \ @@ -735,7 +735,7 @@ depends: $(DEPS) size: $(OBJDIR) $(TARGET_HEX) $(call avr_size,$(TARGET_ELF),$(TARGET_HEX)) -show_boards: +show_boards: $(PARSE_BOARD_CMD) --boards monitor: From 3bb4bde491e4a390312a5cedaf92f40d459deffd Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 12:57:02 -0500 Subject: [PATCH 09/21] Remove duplicated section of documentation. --- arduino-mk/Arduino.mk | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 58337fe..5ae497a 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -197,45 +197,6 @@ # ######################################################################## # -# PATHS -# -# I've reworked the way paths to executables are constructed in this -# version of Makefile. -# -# We need to worry about three different sorts of file: -# -# 1. Things which are included in this distribution e.g. ard-parse-boards -# => ARDMK_DIR -# -# 2. Things which are always in the Arduino distribution e.g. -# boards.txt, libraries, &c. -# => ARDUINO_DIR -# -# 3. Things which might be bundled with the Arduino distribution, but -# might come from the system. Most of the toolchain is like this: -# on Linux it's supplied by the system. -# => AVR_TOOLS_DIR -# -# Having set these three variables, we can work out the rest assuming -# that things are canonically arranged beneath the directories defined -# above. -# -# So, on the Mac you might want to set: -# -# ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java -# ARDMK_DIR = /usr/local -# -# On Linux, you might prefer: -# -# ARDUINO_DIR = /usr/share/arduino -# ARDMK_DIR = /usr/local -# AVR_TOOLS_DIR = /usr -# -# -# -# -######################################################################## -# # ARDUINO WITH ISP # # You need to specify some details of your ISP programmer and might From aaf74a971acf570c9ed71894915c7f476a814e97 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 12:57:24 -0500 Subject: [PATCH 10/21] Add autodetection caveat to docs --- arduino-mk/Arduino.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 5ae497a..2c88de3 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -117,6 +117,9 @@ # You can either set these up in the Makefile, or put them in your # environment e.g. in your .bashrc # +# If you don't specify these, we can try to guess, but that might not work +# or work the way you want it to. +# # If you don't install the ard-... binaries to /usr/local/bin, but # instead copy them to e.g. /home/mjo/arduino.mk/bin then set # ARDML_DIR = /home/mjo/arduino.mk From 2a5e7fd242e38256b3a4e80bc655a97b8791e85b Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 12:57:32 -0500 Subject: [PATCH 11/21] Fix typo in docs --- 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 2c88de3..d33640b 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -154,7 +154,7 @@ # $(ARDUINO_DIR)/hardware/libraries # # ARDUINO_PORT - The port where the Arduino can be found (only needed -# when uploading +# when uploading) # # BOARD_TAG - The ard-parse-boards tag for the board e.g. uno or mega # 'make show_boards' shows a list From 229187d26c444feeb64fffd24757237735d2b36c Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 12:57:45 -0500 Subject: [PATCH 12/21] add the size and disasm targets to the docs --- arduino-mk/Arduino.mk | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index d33640b..1c7935e 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -179,6 +179,11 @@ # make raw_upload - upload without first resetting # make show_boards - list all the boards defined in boards.txt # make monitor - connect to the Arduino's serial port +# make size - show the size of the compiled output (relative to +# resources, if you have a patched avr-size) +# make disasm - generate a .lss file in build-cli that contains +# disassembly of the compiled file interspersed +# with your original source code. # ######################################################################## # From 6ab91c23be6a9a7b34d1d634a0d5b12b9b5ca7f3 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 12:58:05 -0500 Subject: [PATCH 13/21] Clarify where we actually look for libs --- arduino-mk/Arduino.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 1c7935e..f3f2e32 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -150,8 +150,8 @@ # Hopefully these will be self-explanatory but in case they're not: # # ARDUINO_LIBS - A list of any libraries used by the sketch (we -# assume these are in -# $(ARDUINO_DIR)/hardware/libraries +# assume these are in $(ARDUINO_DIR)/hardware/libraries +# or your sketchbook's libraries directory) # # ARDUINO_PORT - The port where the Arduino can be found (only needed # when uploading) From 13000c35ca5026d4ca8e22c3b973eabcd272ddec Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 12:58:32 -0500 Subject: [PATCH 14/21] Add info about setting USER_LIB_PATH and ARDMK_DIR relative to source. --- arduino-mk/Arduino.mk | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index f3f2e32..88bf0c4 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -159,7 +159,19 @@ # BOARD_TAG - The ard-parse-boards tag for the board e.g. uno or mega # 'make show_boards' shows a list # -# Once this file has been created the typical workflow is just +# If you have your additional libraries relative to your source, rather +# than in your "sketchbook", also set USER_LIB_PATH, like this example: +# +# USER_LIB_PATH := $(realpath ../../libraries) +# +# If you've added the Arduino-Makefile repository to your git repo as a +# submodule (or other similar arrangement), you might have lines like this +# in your Makefile: +# +# ARDMK_DIR := $(realpath ../../tools/Arduino-Makefile) +# include $(ARDMK_DIR)/arduino-mk/Arduino.mk +# +# In any case, once this file has been created the typical workflow is just # # $ make upload # From 1f1f43822787985e4de308949f14f9314cedb05e Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 13:58:54 -0500 Subject: [PATCH 15/21] Clean up and improve displayed output. --- arduino-mk/Arduino.mk | 99 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 84 insertions(+), 15 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 88bf0c4..e8c5f56 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -245,6 +245,25 @@ ######################################################################## dir_if_exists = $(shell test -e $(1)$(2) && echo $(1) || true) +# Useful functions +# Returns the first argument (typically a directory), if the file or directory +# named by concatenating the first and optionally second argument +# (directory and optional filename) exists + +# For message printing: pad the right side of the first argument with spaces to +# the number of bytes indicated by the second argument. +space_pad_to = $(shell echo $(1) " " | head --bytes=$(2)) + +# 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_info = $(info - $(call space_pad_to,$(2),20) $(1) = $($(1)) $(3)) + +# Just a nice simple visual separator +show_separator = $(info -------------------------) + + +$(call show_separator) +$(info Arduino.mk Configuration:) ifndef ARDUINO_DIR NIX_DEFAULT_ARDUINO_DIR := $(call dir_if_exists,/usr/share/arduino) @@ -258,8 +277,11 @@ ARDUINO_DIR = $(MAC_DEFAULT_ARDUINO_DIR) endif ifdef ARDUINO_DIR -$(info Using autodetected ARDUINO_DIR '$(ARDUINO_DIR)') +$(call show_config_info,ARDUINO_DIR,[AUTODETECTED]) endif + +else +$(call show_config_info,ARDUINO_DIR) endif ######################################################################## # @@ -278,11 +300,14 @@ ifndef ARDUINO_VERSION # Works for 1.0 and 1.0.1 AUTO_ARDUINO_VERSION := $(shell cat $(ARDUINO_DIR)/lib/version.txt | sed -e 's/[.]//g' -e 's/$$/0000/' | head --bytes=3) ifdef AUTO_ARDUINO_VERSION -$(info Using guessed/detected ARDUINO version define $(AUTO_ARDUINO_VERSION)) ARDUINO_VERSION = $(AUTO_ARDUINO_VERSION) +$(call show_config_info,ARDUINO_VERSION,[AUTODETECTED]) else ARDUINO_VERSION = 100 +$(call show_config_info,ARDUINO_VERSION,[DEFAULT]) endif +else +$(call show_config_info,ARDUINO_VERSION) endif ######################################################################## @@ -293,29 +318,27 @@ ifdef ARDUINO_DIR ifndef AVR_TOOLS_DIR BUNDLED_AVR_TOOLS_DIR := $(call dir_if_exists,$(ARDUINO_DIR)/hardware/tools/avr) - ifdef BUNDLED_AVR_TOOLS_DIR -$(info Using autodetected (bundled) AVR_TOOLS_DIR '$(BUNDLED_AVR_TOOLS_DIR)') AVR_TOOLS_DIR = $(BUNDLED_AVR_TOOLS_DIR) # The avrdude bundled with Arduino can't find it's config AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf +$(call show_config_info,AVR_TOOLS_DIR,[BUNDLED],(in Arduino distribution)) else SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which avr-gcc))/..)) ifdef SYSTEMPATH_AVR_TOOLS_DIR -$(info Using autodetected (from PATH) AVR_TOOLS_DIR '$(SYSTEMPATH_AVR_TOOLS_DIR)') AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR) +$(call show_config_info,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH)) endif # SYSTEMPATH_AVR_TOOLS_DIR -endif # BUNDLED_AVR_TOOLS_EIR +endif # BUNDLED_AVR_TOOLS_DIR +else + +$(call show_config_info,AVR_TOOLS_DIR) endif #ndef AVR_TOOLS_DIR -ifndef AVR_TOOLS_PATH -AVR_TOOLS_PATH = $(AVR_TOOLS_DIR)/bin -endif - ARDUINO_LIB_PATH = $(ARDUINO_DIR)/libraries ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ARDUINO_VAR_PATH = $(ARDUINO_DIR)/hardware/arduino/variants @@ -326,13 +349,26 @@ echo $(error "ARDUINO_DIR is not defined") endif +ifdef AVR_TOOLS_DIR + +ifndef AVR_TOOLS_PATH +AVR_TOOLS_PATH = $(AVR_TOOLS_DIR)/bin +endif + +endif + ######################################################################## # Makefile distribution path # ifdef ARDMK_DIR +$(call show_config_info,ARDMK_DIR) ifndef ARDMK_PATH ARDMK_PATH = $(ARDMK_DIR)/bin +$(call show_config_info,ARDMK_PATH,[COMPUTED],(relative to ARDMK_DIR)) + +else +$(call show_config_info,ARDMK_PATH) endif else @@ -350,6 +386,9 @@ endif ifndef USER_LIB_PATH USER_LIB_PATH = $(ARDUINO_SKETCHBOOK)/libraries +$(call show_config_info,USER_LIB_PATH,[DEFAULT],(in user sketchbook)) +else +$(call show_config_info,USER_LIB_PATH) endif ######################################################################## @@ -378,6 +417,9 @@ endif # ifndef BOARD_TAG BOARD_TAG = uno +$(call show_config_info,BOARD_TAG,[DEFAULT]) +else +$(call show_config_info,BOARD_TAG) endif ifndef BOARDS_TXT @@ -468,12 +510,15 @@ CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp) ifneq ($(strip $(NO_CORE_MAIN_CPP)),) CORE_CPP_SRCS := $(filter-out %main.cpp, $(CORE_CPP_SRCS)) +$(call show_config_info,CORE_CPP_SRCS,[MODIFIED],(Modified by the variable NO_CORE_MAIN_CPP)) endif CORE_OBJ_FILES = $(CORE_C_SRCS:.c=.o) $(CORE_CPP_SRCS:.cpp=.o) CORE_OBJS = $(patsubst $(ARDUINO_CORE_PATH)/%, \ $(OBJDIR)/%,$(CORE_OBJ_FILES)) endif +else +$(call show_config_info,CORE_CPP_SRCS,[MODIFIED],(Modified by the variable NO_CORE)) endif @@ -529,14 +574,38 @@ LDFLAGS = -mmcu=$(MCU) -Wl,--gc-sections -Os # Expand and pick the first port ARD_PORT = $(firstword $(wildcard $(ARDUINO_PORT))) +ifndef SIZE_UTILITY_TYPE # Command for avr_size: do $(call avr_size,elffile,hexfile) -SIZE_ACCEPTS_MCU = $(shell $(SIZE) --help | grep 'AVR' && echo TRUE || true) -ifdef SIZE_ACCEPTS_MCU -avr_size = $(SIZE) --mcu=$(MCU) --format=avr $(1) +ifneq (,$(findstring AVR,$(shell $(SIZE) --help))) +SIZE_UTILITY_TYPE = AVR_ENHANCED else +SIZE_UTILITY_TYPE = BASIC +endif +$(call show_config_info,SIZE_UTILITY_TYPE,[AUTODETECTED]) + +else +$(call show_config_info,SIZE_UTILITY_TYPE,[MANUAL OVERRIDE],Warning - Manually overriding this is not recommended!) +endif + +ifeq ($(SIZE_UTILITY_TYPE),BASIC) +# We have a plain-old binutils version - just give it the hex. avr_size = $(SIZE) $(2) endif +ifeq ($(SIZE_UTILITY_TYPE),AVR_ENHANCED) +# We have a patched version of binutils that mentions AVR - pass the MCU +# and the elf to get nice output. +avr_size = $(SIZE) --mcu=$(MCU) --format=avr $(1) +endif + +ifndef avr_size +$(error "We told you not to override SIZE_UTILITY_TYPE!") +endif + +# end of config output +$(call show_separator) + + # Implicit rules for building everything (needed to get everything in # the right directory) # @@ -621,8 +690,8 @@ $(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.cpp # various object conversions $(OBJDIR)/%.hex: $(OBJDIR)/%.elf $(OBJCOPY) -O ihex -R .eeprom $< $@ - # Dump size for microcontroller. - echo + @echo + @echo $(call avr_size,$<,$@) $(OBJDIR)/%.eep: $(OBJDIR)/%.elf From 49cca1da1161ce909c1d28a95a7e48084cdfc871 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 13:59:12 -0500 Subject: [PATCH 16/21] Less shell-based implementation of dir_if_exists --- 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 e8c5f56..4a020bc 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -244,11 +244,11 @@ # ######################################################################## -dir_if_exists = $(shell test -e $(1)$(2) && echo $(1) || true) # Useful functions # Returns the first argument (typically a directory), if the file or directory # named by concatenating the first and optionally second argument # (directory and optional filename) exists +dir_if_exists = $(if $(wildcard $(1)$(2)),$(1)) # For message printing: pad the right side of the first argument with spaces to # the number of bytes indicated by the second argument. From 744cb5350d5a80d4368d7a22e4a9ec1e7c9fb408 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 14:04:35 -0500 Subject: [PATCH 17/21] Clarify by adding (space-based) indentation. Helps simplify understanding all the nested conditionals. --- arduino-mk/Arduino.mk | 230 +++++++++++++++++++++--------------------- 1 file changed, 115 insertions(+), 115 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 4a020bc..39e5697 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -266,28 +266,28 @@ $(call show_separator) $(info Arduino.mk Configuration:) ifndef ARDUINO_DIR -NIX_DEFAULT_ARDUINO_DIR := $(call dir_if_exists,/usr/share/arduino) -ifdef NIX_DEFAULT_ARDUINO_DIR -ARDUINO_DIR = $(NIX_DEFAULT_ARDUINO_DIR) -endif + NIX_DEFAULT_ARDUINO_DIR := $(call dir_if_exists,/usr/share/arduino) + ifdef NIX_DEFAULT_ARDUINO_DIR + ARDUINO_DIR = $(NIX_DEFAULT_ARDUINO_DIR) + endif -MAC_DEFAULT_ARDUINO_DIR := $(call dir_if_exists,/Applications/Arduino.app/Contents/Resources/Java) -ifdef MAC_DEFAULT_ARDUINO_DIR -ARDUINO_DIR = $(MAC_DEFAULT_ARDUINO_DIR) -endif + MAC_DEFAULT_ARDUINO_DIR := $(call dir_if_exists,/Applications/Arduino.app/Contents/Resources/Java) + ifdef MAC_DEFAULT_ARDUINO_DIR + ARDUINO_DIR = $(MAC_DEFAULT_ARDUINO_DIR) + endif -ifdef ARDUINO_DIR -$(call show_config_info,ARDUINO_DIR,[AUTODETECTED]) -endif + ifdef ARDUINO_DIR + $(call show_config_info,ARDUINO_DIR,[AUTODETECTED]) + endif else -$(call show_config_info,ARDUINO_DIR) + $(call show_config_info,ARDUINO_DIR) endif ######################################################################## # # Default TARGET to cwd (ex Daniele Vergini) ifndef TARGET -TARGET = $(notdir $(CURDIR)) + TARGET = $(notdir $(CURDIR)) endif ######################################################################## @@ -296,18 +296,18 @@ endif # Arduino version number ifndef ARDUINO_VERSION -# Remove all the decimals, and right-pad with zeros, and finally grab the first 3 bytes. -# Works for 1.0 and 1.0.1 -AUTO_ARDUINO_VERSION := $(shell cat $(ARDUINO_DIR)/lib/version.txt | sed -e 's/[.]//g' -e 's/$$/0000/' | head --bytes=3) -ifdef AUTO_ARDUINO_VERSION -ARDUINO_VERSION = $(AUTO_ARDUINO_VERSION) -$(call show_config_info,ARDUINO_VERSION,[AUTODETECTED]) + # Remove all the decimals, and right-pad with zeros, and finally grab the first 3 bytes. + # Works for 1.0 and 1.0.1 + AUTO_ARDUINO_VERSION := $(shell cat $(ARDUINO_DIR)/lib/version.txt | sed -e 's/[.]//g' -e 's/$$/0000/' | head --bytes=3) + ifdef AUTO_ARDUINO_VERSION + ARDUINO_VERSION = $(AUTO_ARDUINO_VERSION) + $(call show_config_info,ARDUINO_VERSION,[AUTODETECTED]) + else + ARDUINO_VERSION = 100 + $(call show_config_info,ARDUINO_VERSION,[DEFAULT]) + endif else -ARDUINO_VERSION = 100 -$(call show_config_info,ARDUINO_VERSION,[DEFAULT]) -endif -else -$(call show_config_info,ARDUINO_VERSION) + $(call show_config_info,ARDUINO_VERSION) endif ######################################################################## @@ -315,45 +315,45 @@ endif # ifdef ARDUINO_DIR -ifndef AVR_TOOLS_DIR + ifndef AVR_TOOLS_DIR -BUNDLED_AVR_TOOLS_DIR := $(call dir_if_exists,$(ARDUINO_DIR)/hardware/tools/avr) -ifdef BUNDLED_AVR_TOOLS_DIR -AVR_TOOLS_DIR = $(BUNDLED_AVR_TOOLS_DIR) -# The avrdude bundled with Arduino can't find it's config -AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf -$(call show_config_info,AVR_TOOLS_DIR,[BUNDLED],(in Arduino distribution)) + BUNDLED_AVR_TOOLS_DIR := $(call dir_if_exists,$(ARDUINO_DIR)/hardware/tools/avr) + ifdef BUNDLED_AVR_TOOLS_DIR + AVR_TOOLS_DIR = $(BUNDLED_AVR_TOOLS_DIR) + # The avrdude bundled with Arduino can't find it's config + AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf + $(call show_config_info,AVR_TOOLS_DIR,[BUNDLED],(in Arduino distribution)) + + else + + SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which avr-gcc))/..)) + ifdef SYSTEMPATH_AVR_TOOLS_DIR + AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR) + $(call show_config_info,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH)) + endif # SYSTEMPATH_AVR_TOOLS_DIR + + endif # BUNDLED_AVR_TOOLS_DIR + + else + + $(call show_config_info,AVR_TOOLS_DIR) + endif #ndef AVR_TOOLS_DIR + + ARDUINO_LIB_PATH = $(ARDUINO_DIR)/libraries + ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/arduino/cores/arduino + ARDUINO_VAR_PATH = $(ARDUINO_DIR)/hardware/arduino/variants else -SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which avr-gcc))/..)) -ifdef SYSTEMPATH_AVR_TOOLS_DIR -AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR) -$(call show_config_info,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH)) -endif # SYSTEMPATH_AVR_TOOLS_DIR - -endif # BUNDLED_AVR_TOOLS_DIR - -else - -$(call show_config_info,AVR_TOOLS_DIR) -endif #ndef AVR_TOOLS_DIR - -ARDUINO_LIB_PATH = $(ARDUINO_DIR)/libraries -ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/arduino/cores/arduino -ARDUINO_VAR_PATH = $(ARDUINO_DIR)/hardware/arduino/variants - -else - -echo $(error "ARDUINO_DIR is not defined") + echo $(error "ARDUINO_DIR is not defined") endif ifdef AVR_TOOLS_DIR -ifndef AVR_TOOLS_PATH -AVR_TOOLS_PATH = $(AVR_TOOLS_DIR)/bin -endif + ifndef AVR_TOOLS_PATH + AVR_TOOLS_PATH = $(AVR_TOOLS_DIR)/bin + endif endif @@ -361,19 +361,19 @@ endif # Makefile distribution path # ifdef ARDMK_DIR -$(call show_config_info,ARDMK_DIR) + $(call show_config_info,ARDMK_DIR) -ifndef ARDMK_PATH -ARDMK_PATH = $(ARDMK_DIR)/bin -$(call show_config_info,ARDMK_PATH,[COMPUTED],(relative to ARDMK_DIR)) + ifndef ARDMK_PATH + ARDMK_PATH = $(ARDMK_DIR)/bin + $(call show_config_info,ARDMK_PATH,[COMPUTED],(relative to ARDMK_DIR)) -else -$(call show_config_info,ARDMK_PATH) -endif + else + $(call show_config_info,ARDMK_PATH) + endif else -echo $(error "ARDMK_DIR is not defined") + echo $(error "ARDMK_DIR is not defined") endif @@ -381,14 +381,14 @@ endif # Miscellanea # ifndef ARDUINO_SKETCHBOOK -ARDUINO_SKETCHBOOK = $(HOME)/sketchbook + ARDUINO_SKETCHBOOK = $(HOME)/sketchbook endif ifndef USER_LIB_PATH -USER_LIB_PATH = $(ARDUINO_SKETCHBOOK)/libraries -$(call show_config_info,USER_LIB_PATH,[DEFAULT],(in user sketchbook)) + USER_LIB_PATH = $(ARDUINO_SKETCHBOOK)/libraries + $(call show_config_info,USER_LIB_PATH,[DEFAULT],(in user sketchbook)) else -$(call show_config_info,USER_LIB_PATH) + $(call show_config_info,USER_LIB_PATH) endif ######################################################################## @@ -399,87 +399,87 @@ endif # for more information (search for 'character special device'). # ifndef MONITOR_BAUDRATE -MONITOR_BAUDRATE = 9600 + MONITOR_BAUDRATE = 9600 endif ifndef MONITOR_CMD -MONITOR_CMD = screen + MONITOR_CMD = screen endif ######################################################################## # Reset ifndef RESET_CMD -RESET_CMD = $(ARDMK_PATH)/ard-reset-arduino $(ARD_RESET_OPTS) + RESET_CMD = $(ARDMK_PATH)/ard-reset-arduino $(ARD_RESET_OPTS) endif ######################################################################## # boards.txt parsing # ifndef BOARD_TAG -BOARD_TAG = uno -$(call show_config_info,BOARD_TAG,[DEFAULT]) + BOARD_TAG = uno + $(call show_config_info,BOARD_TAG,[DEFAULT]) else -$(call show_config_info,BOARD_TAG) + $(call show_config_info,BOARD_TAG) endif ifndef BOARDS_TXT -BOARDS_TXT = $(ARDUINO_DIR)/hardware/arduino/boards.txt + BOARDS_TXT = $(ARDUINO_DIR)/hardware/arduino/boards.txt endif ifndef PARSE_BOARD -PARSE_BOARD = $(ARDMK_PATH)/ard-parse-boards + PARSE_BOARD = $(ARDMK_PATH)/ard-parse-boards endif ifndef PARSE_BOARD_OPTS -PARSE_BOARD_OPTS = --boards_txt=$(BOARDS_TXT) + PARSE_BOARD_OPTS = --boards_txt=$(BOARDS_TXT) endif ifndef PARSE_BOARD_CMD -PARSE_BOARD_CMD = $(PARSE_BOARD) $(PARSE_BOARD_OPTS) + PARSE_BOARD_CMD = $(PARSE_BOARD) $(PARSE_BOARD_OPTS) endif # Which variant ? This affects the include path ifndef VARIANT -VARIANT = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) build.variant) + VARIANT = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) build.variant) endif # processor stuff ifndef MCU -MCU = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) build.mcu) + MCU = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) build.mcu) endif ifndef F_CPU -F_CPU = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) build.f_cpu) + F_CPU = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) build.f_cpu) endif # normal programming info ifndef AVRDUDE_ARD_PROGRAMMER -AVRDUDE_ARD_PROGRAMMER = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) upload.protocol) + AVRDUDE_ARD_PROGRAMMER = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) upload.protocol) endif ifndef AVRDUDE_ARD_BAUDRATE -AVRDUDE_ARD_BAUDRATE = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) upload.speed) + AVRDUDE_ARD_BAUDRATE = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) upload.speed) endif # fuses if you're using e.g. ISP ifndef ISP_LOCK_FUSE_PRE -ISP_LOCK_FUSE_PRE = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) bootloader.unlock_bits) + ISP_LOCK_FUSE_PRE = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) bootloader.unlock_bits) endif ifndef ISP_LOCK_FUSE_POST -ISP_LOCK_FUSE_POST = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) bootloader.lock_bits) + ISP_LOCK_FUSE_POST = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) bootloader.lock_bits) endif ifndef ISP_HIGH_FUSE -ISP_HIGH_FUSE = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) bootloader.high_fuses) + ISP_HIGH_FUSE = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) bootloader.high_fuses) endif ifndef ISP_LOW_FUSE -ISP_LOW_FUSE = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) bootloader.low_fuses) + ISP_LOW_FUSE = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) bootloader.low_fuses) endif ifndef ISP_EXT_FUSE -ISP_EXT_FUSE = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) bootloader.extended_fuses) + ISP_EXT_FUSE = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) bootloader.extended_fuses) endif # Everything gets built in here @@ -504,21 +504,21 @@ DEPS = $(LOCAL_OBJS:.o=.d) # core sources ifeq ($(strip $(NO_CORE)),) -ifdef ARDUINO_CORE_PATH -CORE_C_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.c) -CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp) + ifdef ARDUINO_CORE_PATH + CORE_C_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.c) + CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp) -ifneq ($(strip $(NO_CORE_MAIN_CPP)),) -CORE_CPP_SRCS := $(filter-out %main.cpp, $(CORE_CPP_SRCS)) -$(call show_config_info,CORE_CPP_SRCS,[MODIFIED],(Modified by the variable NO_CORE_MAIN_CPP)) -endif + ifneq ($(strip $(NO_CORE_MAIN_CPP)),) + CORE_CPP_SRCS := $(filter-out %main.cpp, $(CORE_CPP_SRCS)) + $(call show_config_info,CORE_CPP_SRCS,[MODIFIED],(Modified by the variable NO_CORE_MAIN_CPP)) + endif -CORE_OBJ_FILES = $(CORE_C_SRCS:.c=.o) $(CORE_CPP_SRCS:.cpp=.o) -CORE_OBJS = $(patsubst $(ARDUINO_CORE_PATH)/%, \ - $(OBJDIR)/%,$(CORE_OBJ_FILES)) -endif + CORE_OBJ_FILES = $(CORE_C_SRCS:.c=.o) $(CORE_CPP_SRCS:.cpp=.o) + CORE_OBJS = $(patsubst $(ARDUINO_CORE_PATH)/%, \ + $(OBJDIR)/%,$(CORE_OBJ_FILES)) + endif else -$(call show_config_info,CORE_CPP_SRCS,[MODIFIED],(Modified by the variable NO_CORE)) + $(call show_config_info,CORE_CPP_SRCS,[MODIFIED],(Modified by the variable NO_CORE)) endif @@ -575,31 +575,31 @@ LDFLAGS = -mmcu=$(MCU) -Wl,--gc-sections -Os ARD_PORT = $(firstword $(wildcard $(ARDUINO_PORT))) ifndef SIZE_UTILITY_TYPE -# Command for avr_size: do $(call avr_size,elffile,hexfile) -ifneq (,$(findstring AVR,$(shell $(SIZE) --help))) -SIZE_UTILITY_TYPE = AVR_ENHANCED -else -SIZE_UTILITY_TYPE = BASIC -endif -$(call show_config_info,SIZE_UTILITY_TYPE,[AUTODETECTED]) + # Command for avr_size: do $(call avr_size,elffile,hexfile) + ifneq (,$(findstring AVR,$(shell $(SIZE) --help))) + SIZE_UTILITY_TYPE = AVR_ENHANCED + else + SIZE_UTILITY_TYPE = BASIC + endif + $(call show_config_info,SIZE_UTILITY_TYPE,[AUTODETECTED]) else -$(call show_config_info,SIZE_UTILITY_TYPE,[MANUAL OVERRIDE],Warning - Manually overriding this is not recommended!) + $(call show_config_info,SIZE_UTILITY_TYPE,[MANUAL OVERRIDE],Warning - Manually overriding this is not recommended!) endif ifeq ($(SIZE_UTILITY_TYPE),BASIC) -# We have a plain-old binutils version - just give it the hex. -avr_size = $(SIZE) $(2) + # We have a plain-old binutils version - just give it the hex. + avr_size = $(SIZE) $(2) endif ifeq ($(SIZE_UTILITY_TYPE),AVR_ENHANCED) -# We have a patched version of binutils that mentions AVR - pass the MCU -# and the elf to get nice output. -avr_size = $(SIZE) --mcu=$(MCU) --format=avr $(1) + # We have a patched version of binutils that mentions AVR - pass the MCU + # and the elf to get nice output. + avr_size = $(SIZE) --mcu=$(MCU) --format=avr $(1) endif ifndef avr_size -$(error "We told you not to override SIZE_UTILITY_TYPE!") + $(error "We told you not to override SIZE_UTILITY_TYPE!") endif # end of config output @@ -709,18 +709,18 @@ $(OBJDIR)/%.sym: $(OBJDIR)/%.elf # Avrdude # ifndef AVRDUDE -AVRDUDE = $(AVR_TOOLS_PATH)/avrdude + AVRDUDE = $(AVR_TOOLS_PATH)/avrdude endif AVRDUDE_COM_OPTS = -q -V -p $(MCU) ifdef AVRDUDE_CONF -AVRDUDE_COM_OPTS += -C $(AVRDUDE_CONF) + AVRDUDE_COM_OPTS += -C $(AVRDUDE_CONF) endif AVRDUDE_ARD_OPTS = -c $(AVRDUDE_ARD_PROGRAMMER) -b $(AVRDUDE_ARD_BAUDRATE) -P $(ARD_PORT) ifndef ISP_PROG -ISP_PROG = -c stk500v2 + ISP_PROG = -c stk500v2 endif AVRDUDE_ISP_OPTS = -P $(ISP_PORT) $(ISP_PROG) From 940a6b6ecca5af82fc2363027fde2be41642f33e Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 14:39:32 -0500 Subject: [PATCH 18/21] Simplify finding arduino dir --- arduino-mk/Arduino.mk | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 39e5697..0118855 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -266,17 +266,11 @@ $(call show_separator) $(info Arduino.mk Configuration:) ifndef ARDUINO_DIR - NIX_DEFAULT_ARDUINO_DIR := $(call dir_if_exists,/usr/share/arduino) - ifdef NIX_DEFAULT_ARDUINO_DIR - ARDUINO_DIR = $(NIX_DEFAULT_ARDUINO_DIR) - endif - - MAC_DEFAULT_ARDUINO_DIR := $(call dir_if_exists,/Applications/Arduino.app/Contents/Resources/Java) - ifdef MAC_DEFAULT_ARDUINO_DIR - ARDUINO_DIR = $(MAC_DEFAULT_ARDUINO_DIR) - endif - - ifdef ARDUINO_DIR + AUTO_ARDUINO_DIR := $(firstword \ + $(call dir_if_exists,/usr/share/arduino) \ + $(call dir_if_exists,/Applications/Arduino.app/Contents/Resources/Java) ) + ifdef AUTO_ARDUINO_DIR + ARDUINO_DIR = $(AUTO_ARDUINO_DIR) $(call show_config_info,ARDUINO_DIR,[AUTODETECTED]) endif From e6ac1cae3aeb851bad9a22767cbf4d2faa8261c2 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 14:39:50 -0500 Subject: [PATCH 19/21] Simplify user and system libraries --- arduino-mk/Arduino.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 0118855..f28a104 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -543,8 +543,8 @@ CAT = cat ECHO = echo # General arguments -SYS_LIBS = $(foreach libdir,$(patsubst %,$(ARDUINO_LIB_PATH)/%,$(ARDUINO_LIBS)),$(call dir_if_exists,$(libdir))) -USER_LIBS = $(foreach libdir,$(patsubst %,$(USER_LIB_PATH)/%,$(ARDUINO_LIBS)),$(call dir_if_exists,$(libdir))) +SYS_LIBS = $(wildcard $(patsubst %,$(ARDUINO_LIB_PATH)/%,$(ARDUINO_LIBS))) +USER_LIBS = $(wildcard $(patsubst %,$(USER_LIB_PATH)/%,$(ARDUINO_LIBS))) SYS_INCLUDES = $(patsubst %,-I%,$(SYS_LIBS)) USER_INCLUDES = $(patsubst %,-I%,$(USER_LIBS)) LIB_C_SRCS = $(wildcard $(patsubst %,%/*.c,$(SYS_LIBS))) From 6c7a8bad60e56502c91da9ab4b3588dbd3ab21f4 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 15:01:11 -0500 Subject: [PATCH 20/21] rename functions to allow nicer output. This also lets us restore the non-overridable detection of avr-size type. --- arduino-mk/Arduino.mk | 79 ++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index f28a104..5ab69c8 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -254,9 +254,12 @@ 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)) +# Call with some text, and a prefix tag if desired (like [AUTODETECTED]), +show_config_info = $(info - $(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_info = $(info - $(call space_pad_to,$(2),20) $(1) = $($(1)) $(3)) +show_config_variable = $(call show_config_info,$(1) = $($(1)) $(3),$(2)) # Just a nice simple visual separator show_separator = $(info -------------------------) @@ -271,11 +274,11 @@ ifndef ARDUINO_DIR $(call dir_if_exists,/Applications/Arduino.app/Contents/Resources/Java) ) ifdef AUTO_ARDUINO_DIR ARDUINO_DIR = $(AUTO_ARDUINO_DIR) - $(call show_config_info,ARDUINO_DIR,[AUTODETECTED]) + $(call show_config_variable,ARDUINO_DIR,[AUTODETECTED]) endif else - $(call show_config_info,ARDUINO_DIR) + $(call show_config_variable,ARDUINO_DIR) endif ######################################################################## # @@ -295,13 +298,13 @@ ifndef ARDUINO_VERSION AUTO_ARDUINO_VERSION := $(shell cat $(ARDUINO_DIR)/lib/version.txt | sed -e 's/[.]//g' -e 's/$$/0000/' | head --bytes=3) ifdef AUTO_ARDUINO_VERSION ARDUINO_VERSION = $(AUTO_ARDUINO_VERSION) - $(call show_config_info,ARDUINO_VERSION,[AUTODETECTED]) + $(call show_config_variable,ARDUINO_VERSION,[AUTODETECTED]) else ARDUINO_VERSION = 100 - $(call show_config_info,ARDUINO_VERSION,[DEFAULT]) + $(call show_config_variable,ARDUINO_VERSION,[DEFAULT]) endif else - $(call show_config_info,ARDUINO_VERSION) + $(call show_config_variable,ARDUINO_VERSION) endif ######################################################################## @@ -316,24 +319,25 @@ ifdef ARDUINO_DIR AVR_TOOLS_DIR = $(BUNDLED_AVR_TOOLS_DIR) # The avrdude bundled with Arduino can't find it's config AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf - $(call show_config_info,AVR_TOOLS_DIR,[BUNDLED],(in Arduino distribution)) + $(call show_config_variable,AVR_TOOLS_DIR,[BUNDLED],(in Arduino distribution)) else SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which avr-gcc))/..)) ifdef SYSTEMPATH_AVR_TOOLS_DIR AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR) - $(call show_config_info,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH)) + $(call show_config_variable,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH)) endif # SYSTEMPATH_AVR_TOOLS_DIR endif # BUNDLED_AVR_TOOLS_DIR else - $(call show_config_info,AVR_TOOLS_DIR) + $(call show_config_variable,AVR_TOOLS_DIR) endif #ndef AVR_TOOLS_DIR ARDUINO_LIB_PATH = $(ARDUINO_DIR)/libraries + $(call show_config_variable,ARDUINO_LIB_PATH,[COMPUTED],(from ARDUINO_DIR)) ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ARDUINO_VAR_PATH = $(ARDUINO_DIR)/hardware/arduino/variants @@ -355,14 +359,14 @@ endif # Makefile distribution path # ifdef ARDMK_DIR - $(call show_config_info,ARDMK_DIR) + $(call show_config_variable,ARDMK_DIR) ifndef ARDMK_PATH ARDMK_PATH = $(ARDMK_DIR)/bin - $(call show_config_info,ARDMK_PATH,[COMPUTED],(relative to ARDMK_DIR)) + $(call show_config_variable,ARDMK_PATH,[COMPUTED],(relative to ARDMK_DIR)) else - $(call show_config_info,ARDMK_PATH) + $(call show_config_variable,ARDMK_PATH) endif else @@ -380,9 +384,9 @@ endif ifndef USER_LIB_PATH USER_LIB_PATH = $(ARDUINO_SKETCHBOOK)/libraries - $(call show_config_info,USER_LIB_PATH,[DEFAULT],(in user sketchbook)) + $(call show_config_variable,USER_LIB_PATH,[DEFAULT],(in user sketchbook)) else - $(call show_config_info,USER_LIB_PATH) + $(call show_config_variable,USER_LIB_PATH) endif ######################################################################## @@ -411,9 +415,9 @@ endif # ifndef BOARD_TAG BOARD_TAG = uno - $(call show_config_info,BOARD_TAG,[DEFAULT]) + $(call show_config_variable,BOARD_TAG,[DEFAULT]) else - $(call show_config_info,BOARD_TAG) + $(call show_config_variable,BOARD_TAG) endif ifndef BOARDS_TXT @@ -504,7 +508,7 @@ ifeq ($(strip $(NO_CORE)),) ifneq ($(strip $(NO_CORE_MAIN_CPP)),) CORE_CPP_SRCS := $(filter-out %main.cpp, $(CORE_CPP_SRCS)) - $(call show_config_info,CORE_CPP_SRCS,[MODIFIED],(Modified by the variable NO_CORE_MAIN_CPP)) + $(call show_config_info,NO_CORE_MAIN_CPP set so core library will not include main.cpp,[MANUAL]) endif CORE_OBJ_FILES = $(CORE_C_SRCS:.c=.o) $(CORE_CPP_SRCS:.cpp=.o) @@ -512,7 +516,7 @@ ifeq ($(strip $(NO_CORE)),) $(OBJDIR)/%,$(CORE_OBJ_FILES)) endif else - $(call show_config_info,CORE_CPP_SRCS,[MODIFIED],(Modified by the variable NO_CORE)) + $(call show_config_info,NO_CORE set so core library will not be built,[MANUAL]) endif @@ -568,32 +572,29 @@ LDFLAGS = -mmcu=$(MCU) -Wl,--gc-sections -Os # Expand and pick the first port ARD_PORT = $(firstword $(wildcard $(ARDUINO_PORT))) -ifndef SIZE_UTILITY_TYPE - # Command for avr_size: do $(call avr_size,elffile,hexfile) - ifneq (,$(findstring AVR,$(shell $(SIZE) --help))) - SIZE_UTILITY_TYPE = AVR_ENHANCED - else - SIZE_UTILITY_TYPE = BASIC - endif - $(call show_config_info,SIZE_UTILITY_TYPE,[AUTODETECTED]) - -else - $(call show_config_info,SIZE_UTILITY_TYPE,[MANUAL OVERRIDE],Warning - Manually overriding this is not recommended!) -endif - -ifeq ($(SIZE_UTILITY_TYPE),BASIC) - # We have a plain-old binutils version - just give it the hex. - avr_size = $(SIZE) $(2) -endif - -ifeq ($(SIZE_UTILITY_TYPE),AVR_ENHANCED) +# Command for avr_size: do $(call avr_size,elffile,hexfile) +ifneq (,$(findstring AVR,$(shell $(SIZE) --help))) # We have a patched version of binutils that mentions AVR - pass the MCU # and the elf to get nice output. avr_size = $(SIZE) --mcu=$(MCU) --format=avr $(1) + $(call show_config_info,Size utility: AVR-aware for enhanced output,[AUTODETECTED]) +else + # We have a plain-old binutils version - just give it the hex. + avr_size = $(SIZE) $(2) + $(call show_config_info,Size utility: Basic (not AVR-aware),[AUTODETECTED]) endif -ifndef avr_size - $(error "We told you not to override SIZE_UTILITY_TYPE!") + +ifneq (,$(strip $(ARDUINO_LIBS))) + $(info -) + $(call show_config_info,ARDUINO_LIBS =) +endif +ifneq (,$(strip $(USER_LIB_NAMES))) + $(foreach lib,$(USER_LIB_NAMES),$(call show_config_info, $(lib),[USER])) +endif + +ifneq (,$(strip $(SYS_LIB_NAMES))) + $(foreach lib,$(SYS_LIB_NAMES),$(call show_config_info, $(lib),[SYSTEM])) endif # end of config output From c93c8e16a5480205f452e18e022ad7f812ca7206 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 5 Jul 2012 15:02:24 -0500 Subject: [PATCH 21/21] Improved library finding logic. Look first in the user dir. Any not found there are sought in the system (Arduino) dir. If any are not found, error out right away with a useful message. Show all libraries and where they were found (user or system) in the config info. --- arduino-mk/Arduino.mk | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 5ab69c8..d50ff22 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -547,8 +547,19 @@ CAT = cat ECHO = echo # General arguments -SYS_LIBS = $(wildcard $(patsubst %,$(ARDUINO_LIB_PATH)/%,$(ARDUINO_LIBS))) USER_LIBS = $(wildcard $(patsubst %,$(USER_LIB_PATH)/%,$(ARDUINO_LIBS))) +USER_LIB_NAMES= $(patsubst $(USER_LIB_PATH)/%,%,$(USER_LIBS)) + +# Let user libraries override system ones. +SYS_LIBS = $(wildcard $(patsubst %,$(ARDUINO_LIB_PATH)/%,$(filter-out $(USER_LIB_NAMES),$(ARDUINO_LIBS)))) +SYS_LIB_NAMES = $(patsubst $(ARDUINO_LIB_PATH)/%,%,$(SYS_LIBS)) + +# Error here if any are missing. +LIBS_NOT_FOUND = $(filter-out $(USER_LIB_NAMES) $(SYS_LIB_NAMES),$(ARDUINO_LIBS)) +ifneq (,$(strip $(LIBS_NOT_FOUND))) + $(error The following libraries specified in ARDUINO_LIBS could not be found (searched USER_LIB_PATH and ARDUINO_LIB_PATH): $(LIBS_NOT_FOUND)) +endif + SYS_INCLUDES = $(patsubst %,-I%,$(SYS_LIBS)) USER_INCLUDES = $(patsubst %,-I%,$(USER_LIBS)) LIB_C_SRCS = $(wildcard $(patsubst %,%/*.c,$(SYS_LIBS)))