From 866b2e910017039e46315394e76b1a02fd5a897a Mon Sep 17 00:00:00 2001 From: Simon John Date: Sat, 11 Jan 2014 13:24:36 +0000 Subject: [PATCH] Simplified package vs. git detection, fixes #147 Removed ARDMK_FILE as it was in the wrong case and a bit pointless anyway. Fixed ChipKIT.mk which wouldn't work when packaged and had a lot of duplicated code (needs checking this still works!) Removed the git vs. package detection of the arduino-mk subdirectory - ARDMK_DIR is now calculated based on where the *.mk files are. Removed ARDMK_PATH as we now check for ard-reset-arduino in the $PATH when packaged or fall back to it being one level above the *.mk files in bin/ when checked out of git. Merged Common.mk back into Arduino.mk as it meant nasty workarounds for missing routines e.g. dir_if_exists and show_config_variable which meant that AUTO_ARDUINO_DIR was broken. So now all you need to set is BOARD_TAG (plus MONITOR_PORT or ISP_PROG for upload/reset). --- arduino-mk/Arduino.mk | 98 ++++++++++++++++++++++++------------------- arduino-mk/Common.mk | 38 ----------------- arduino-mk/chipKIT.mk | 23 ++-------- 3 files changed, 59 insertions(+), 100 deletions(-) delete mode 100644 arduino-mk/Common.mk diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 3241cca..bca18b5 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -29,9 +29,8 @@ # # We need to worry about three different sorts of file: # -# 1. Things which are included in this distribution e.g. ard-reset-arduino -# => ARDMK_DIR - Where the *.mk files are stored -# => ARDMK_PATH - Where the ard-reset-arduino script is stored +# 1. The directory where the *.mk files are stored +# => ARDMK_DIR # # 2. Things which are always in the Arduino distribution e.g. # boards.txt, libraries, &c. @@ -54,7 +53,7 @@ # On Linux, you might prefer: # # ARDUINO_DIR = /usr/share/arduino -# ARDMK_DIR = /usr +# ARDMK_DIR = /usr/share/arduino # AVR_TOOLS_DIR = /usr # # You can either set these up in the Makefile, or put them in your @@ -63,10 +62,6 @@ # 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-reset-arduino binary to /usr/local/bin, but -# instead copy them to e.g. /home/mjo/arduino.mk/bin then set -# ARDMK_PATH = /home/mjo/arduino.mk/bin -# # If you'd rather not see the configuration output, define ARDUINO_QUIET. # ######################################################################## @@ -112,8 +107,8 @@ # 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 +# ARDMK_DIR := $(realpath ../../tools/Arduino-Makefile/arduino-mk) +# include $(ARDMK_DIR)/Arduino.mk # # In any case, once this file has been created the typical workflow is just # @@ -215,6 +210,7 @@ # ######################################################################## +# Useful functions arduino_output = # When output is not suppressed and we're in the top-level makefile, # running for the first time (i.e., not after a restart after @@ -227,44 +223,55 @@ ifndef ARDUINO_QUIET endif endif +# 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. +space_pad_to = $(shell echo $(1) " " | head -c$(2)) + +# Call with some text, and a prefix tag if desired (like [AUTODETECTED]), +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 = $(call arduino_output,-------------------------) + +$(call show_separator) +$(call arduino_output,Arduino.mk Configuration:) + +######################################################################## +# +# Detect OS +ifeq ($(OS),Windows_NT) + CURRENT_OS = WINDOWS +else + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Linux) + CURRENT_OS = LINUX + endif + ifeq ($(UNAME_S),Darwin) + CURRENT_OS = MAC + endif +endif +$(call show_config_variable,CURRENT_OS,[AUTODETECTED]) + ######################################################################## # Makefile distribution path ifndef ARDMK_DIR - # presume it's a level above the path to our own file - ARDMK_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST))))/..) -else - # show_config_variable macro is defined in Common.mk file and is not available yet. - # Let's define a variable to know that user specified ARDMK_DIR - ARDMK_DIR_MSG = USER -endif - -ifneq ($(wildcard $(ARDMK_DIR)/arduino-mk/Common.mk),) - # git checkout - ARDMK_FILE = $(ARDMK_DIR)/arduino-mk/arduino.mk - include $(ARDMK_DIR)/arduino-mk/Common.mk -else - ifneq ($(wildcard $(ARDMK_DIR)/Common.mk),) - # package install - ARDMK_FILE = $(ARDMK_DIR)/arduino.mk - include $(ARDMK_DIR)/Common.mk - endif -endif - -# show_config_variable macro is available now. So let's print config details for ARDMK_DIR -ifndef ARDMK_DIR_MSG + # presume it's the same path to our own file + ARDMK_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST))))) $(call show_config_variable,ARDMK_DIR,[COMPUTED],(relative to $(notdir $(lastword $(MAKEFILE_LIST))))) else $(call show_config_variable,ARDMK_DIR,[USER]) endif -ifndef ARDMK_PATH - ARDMK_PATH = $(ARDMK_DIR)/bin - $(call show_config_variable,ARDMK_PATH,[COMPUTED],(relative to ARDMK_DIR)) -else - $(call show_config_variable,ARDMK_PATH,[USER]) -endif - ######################################################################## # Arduino Directory @@ -590,12 +597,19 @@ endif ######################################################################## # Reset +ARD_RESET_ARDUINO := $(shell which ard-reset-arduino) +ifndef ARD_RESET_ARDUINO + # one level up from *.mk in bin directory when checked out from git + # or in $PATH when packaged + ARD_RESET_ARDUINO = $(ARDMK_DIR)/../bin/ard-reset-arduino +endif + ifndef RESET_CMD ifneq ($(CATERINA),) - RESET_CMD = $(ARDMK_PATH)/ard-reset-arduino --caterina \ + RESET_CMD = $(ARD_RESET_ARDUINO) --caterina \ $(ARD_RESET_OPTS) $(call get_monitor_port) else - RESET_CMD = $(ARDMK_PATH)/ard-reset-arduino \ + RESET_CMD = $(ARD_RESET_ARDUINO) \ $(ARD_RESET_OPTS) $(call get_monitor_port) endif endif @@ -1221,7 +1235,7 @@ help: make set_fuses - set fuses without burning bootloader\n\ make help - show this help\n\ " - @$(ECHO) "Please refer to $(ARDMK_FILE) for more details.\n" + @$(ECHO) "Please refer to Arduino.mk for more details.\n" .PHONY: all upload raw_upload raw_eeprom error_on_caterina reset reset_stty ispload \ clean depends size show_boards monitor disasm symbol_sizes generated_assembly \ diff --git a/arduino-mk/Common.mk b/arduino-mk/Common.mk deleted file mode 100644 index a94c37f..0000000 --- a/arduino-mk/Common.mk +++ /dev/null @@ -1,38 +0,0 @@ -# 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. -space_pad_to = $(shell echo $(1) " " | head -c$(2)) - -# Call with some text, and a prefix tag if desired (like [AUTODETECTED]), -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 = $(call arduino_output,-------------------------) - -$(call show_separator) -$(call arduino_output,Arduino.mk Configuration:) - -######################################################################## -# -# Detect OS -ifeq ($(OS),Windows_NT) - CURRENT_OS = WINDOWS -else - UNAME_S := $(shell uname -s) - ifeq ($(UNAME_S),Linux) - CURRENT_OS = LINUX - endif - ifeq ($(UNAME_S),Darwin) - CURRENT_OS = MAC - endif -endif -$(call show_config_variable,CURRENT_OS,[AUTODETECTED]) diff --git a/arduino-mk/chipKIT.mk b/arduino-mk/chipKIT.mk index 2d9abb4..90add05 100644 --- a/arduino-mk/chipKIT.mk +++ b/arduino-mk/chipKIT.mk @@ -22,27 +22,10 @@ ######################################################################## # Makefile distribution path -# -# The show_config_variable is unavailable before we include the common makefile, -# so we defer logging the ARDMK_DIR info until it happens in Arduino.mk ifndef ARDMK_DIR - # presume it's a level above the path to our own file - ARDMK_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST))))/..) -endif - -ifndef ARDMK_PATH - ARDMK_PATH = $(ARDMK_DIR)/bin -endif - -ifneq ($(wildcard $(ARDMK_DIR)/arduino-mk/Common.mk),) - # git checkout - include $(ARDMK_DIR)/arduino-mk/Common.mk -else - ifneq ($(wildcard $(ARDMK_DIR)/Common.mk),) - # package install - include $(ARDMK_DIR)/Common.mk - endif + # presume it's the same path to our own file + ARDMK_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST))))) endif ifndef MPIDE_DIR @@ -110,4 +93,4 @@ LDFLAGS += -T$(ARDUINO_CORE_PATH)/chipKIT-application-COMMON.ld CPPFLAGS += -mno-smart-io -fno-short-double CFLAGS_STD = -include $(ARDMK_DIR)/arduino-mk/Arduino.mk +include $(ARDMK_DIR)/Arduino.mk