From e3d42145644ead8706c66acfd5b05cab492b544e Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 21 Dec 2021 16:13:01 +0100 Subject: build: refactor build scripts --- make-scripts/Arduino.mk | 913 +++++++++++------------------------------------- 1 file changed, 197 insertions(+), 716 deletions(-) (limited to 'make-scripts/Arduino.mk') diff --git a/make-scripts/Arduino.mk b/make-scripts/Arduino.mk index 908966b..3ac40a5 100644 --- a/make-scripts/Arduino.mk +++ b/make-scripts/Arduino.mk @@ -1,6 +1,5 @@ # # Makefile for compiling Arduino sketches from command line -# System part (i.e. project independent) # # Copyright (C) 2012 Sudar , based on # M J Oldfield work: https://github.com/mjoldfield/Arduino-Makefile @@ -38,140 +37,50 @@ endif include $(ARDMK_DIR)/Common.mk +ifeq ($(CURRENT_OS), WINDOWS) + echo $(error Error: Windows is not supported! Please upgrade to a better operating system and try again) +endif + $(call show_config_variable,ARDMK_DIR,[USER]) -ifndef TARGET - space := - space += - TARGET = $(notdir $(subst $(space),_,$(CURDIR))) -endif +$(call show_config_variable,TARGET,[DEFAULT]) $(call show_config_variable,ARDUINO_VERSION,[USER]) - -ifdef ARDUINO_VERSION - ARDUINO_VERSION_SHORT = $(shell sed "s/\.//g" <<< $(ARDUINO_VERSION)) - $(call show_config_variable,ARDUINO_VERSION_SHORT,[AUTODETECTED]) -endif +$(call show_config_variable,ARDUINO_VERSION_SHORT,[USER]) $(call show_config_variable,ARCHITECTURE,[USER]) - -#avoid using shell for known architectures -ifeq ($(ARCHITECTURE),avr) - ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_AVR -else - ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_$(shell echo $(ARCHITECTURE) | tr '[:lower:]' '[:upper:]') -endif - -ARDMK_VENDOR = arduino - $(call show_config_variable,ARDMK_VENDOR,[DEFAULT]) -ARDUINO_VAR_PATH = $(ARDUINO_DIR)/hardware/$(ARCHITECTURE)/$(ARDUINO_VERSION)/variants $(call show_config_variable,ARDUINO_VAR_PATH,[COMPUTED],(from ARDUINO_DIR)) - -BOARDS_TXT = $(ARDUINO_DIR)/hardware/$(ARCHITECTURE)/$(ARDUINO_VERSION)/boards.txt $(call show_config_variable,BOARDS_TXT,[COMPUTED],(from ARDUINO_DIR)) -ifeq (,$(wildcard $(BOARDS_TXT))) - $(error Currently BOARDS_TXT='$(BOARDS_TXT)', which is not an existing file or an invalid filename.) -endif - -TOOL_PREFIX = avr - -CC_NAME := $(TOOL_PREFIX)-gcc -CXX_NAME := $(TOOL_PREFIX)-g++ -AS_NAME := $(TOOL_PREFIX)-as -OBJCOPY_NAME := $(TOOL_PREFIX)-objcopy -OBJDUMP_NAME := $(TOOL_PREFIX)-objdump -AR_NAME := $(TOOL_PREFIX)-ar -SIZE_NAME := $(TOOL_PREFIX)-size -NM_NAME := $(TOOL_PREFIX)-nm - -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) - $(call show_config_variable,AVR_TOOLS_DIR,[BUNDLED],(in Arduino distribution)) - - # In Linux distribution of Arduino, the path to avrdude and avrdude.conf are different - # More details at https://github.com/sudar/Arduino-Makefile/issues/48 and - # https://groups.google.com/a/arduino.cc/d/msg/developers/D_m97jGr8Xs/uQTt28KO_8oJ - ifeq ($(CURRENT_OS),LINUX) - - ifndef AVRDUDE - ifeq ($(shell expr $(ARDUINO_VERSION_SHORT) '>' 157), 1) - # 1.5.8 has different location than all prior versions! - AVRDUDE = $(AVR_TOOLS_DIR)/bin/avrdude - else - AVRDUDE = $(AVR_TOOLS_DIR)/../avrdude - endif - endif - - ifndef AVRDUDE_CONF - ifeq ($(shell expr $(ARDUINO_VERSION_SHORT) '>' 157), 1) - AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf - else - AVRDUDE_CONF = $(AVR_TOOLS_DIR)/../avrdude.conf - endif - endif - - else - - ifndef AVRDUDE_CONF - AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf - endif - - endif - - else - - SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which $(CC_NAME)))/..)) - ifdef SYSTEMPATH_AVR_TOOLS_DIR - AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR) - $(call show_config_variable,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH)) - else - # One last attempt using $(TOOL_PREFIX)-gcc in case using arm - SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which $($(TOOL_PREFIX)-gcc)))/..)) - ifdef SYSTEMPATH_AVR_TOOLS_DIR - AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR) - $(call show_config_variable,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH)) - else - echo $(error No AVR tools directory found) - endif - endif # SYSTEMPATH_AVR_TOOLS_DIR - - endif # BUNDLED_AVR_TOOLS_DIR +ifdef BUNDLED_AVR_TOOLS_DIR + AVR_TOOLS_DIR = $(BUNDLED_AVR_TOOLS_DIR) + $(call show_config_variable,AVR_TOOLS_DIR,[BUNDLED],(in Arduino distribution)) + AVRDUDE = $(AVR_TOOLS_DIR)/bin/avrdude + AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf else - $(call show_config_variable,AVR_TOOLS_DIR,[USER]) - - # ensure we can still find avrdude.conf - ifndef AVRDUDE_CONF - ifeq ($(shell expr $(ARDUINO_VERSION_SHORT) '>' 157), 1) - AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf - else - AVRDUDE_CONF = $(AVR_TOOLS_DIR)/../avrdude.conf - endif - endif - + SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which $(CC_NAME)))/..)) + ifdef SYSTEMPATH_AVR_TOOLS_DIR + AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR) + $(call show_config_variable,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH)) + else + # One last attempt using $(TOOL_PREFIX)-gcc in case using arm + SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which $($(TOOL_PREFIX)-gcc)))/..)) + ifdef SYSTEMPATH_AVR_TOOLS_DIR + AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR) + $(call show_config_variable,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH)) + else + echo $(error No AVR tools directory found) + endif + endif endif -TOOLS_PATH = $(ARDUINO_DIR)/tools/avr-gcc/$(shell /bin/ls --color=never -1 $(ARDUINO_DIR)/tools/avr-gcc/ | sort -r | xargs | awk '{print $$1}')/bin - -ARDUINO_LIB_PATH = $(ARDUINO_DIR)/libraries $(call show_config_variable,ARDUINO_LIB_PATH,[COMPUTED],(from ARDUINO_DIR)) - -ifeq ($(shell expr $(ARDUINO_VERSION_SHORT) '>' 150), 1) - ARDUINO_PLATFORM_LIB_PATH = $(ARDUINO_DIR)/hardware/$(ARCHITECTURE)/$(ARDUINO_VERSION)/libraries - $(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[COMPUTED],(from ARDUINO_DIR)) -endif - -PROJ_LIBS_PATH = libraries +$(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[COMPUTED],(from ARDUINO_DIR)) $(call show_config_variable,PROJ_LIBS_PATH,[DEFAULT]) -PRE_BUILD_HOOK = pre-build-hook.sh $(call show_config_variable,PRE_BUILD_HOOK,[DEFAULT]) ######################################################################## @@ -190,221 +99,112 @@ ifdef BOARD_CLOCK $(call show_config_variable,BOARD_CLOCK,[USER]) endif -# If NO_CORE is set, then we don't have to parse boards.txt file -# But the user might have to define MCU, F_CPU etc -ifeq ($(strip $(NO_CORE)),) - - # Select a core from the 'cores' directory. Two main values: 'arduino' or - # 'robot', but can also hold 'tiny', for example, if using - # https://code.google.com/p/arduino-tiny alternate core. - ifndef CORE - CORE = $(call PARSE_BOARD,$(BOARD_TAG),build.core) - $(call show_config_variable,CORE,[COMPUTED],(from build.core)) - else - $(call show_config_variable,CORE,[USER]) - endif - - # Which variant ? This affects the include path - ifndef VARIANT - VARIANT := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.variant) - ifndef VARIANT - VARIANT := $(call PARSE_BOARD,$(BOARD_TAG),build.variant) - endif - $(call show_config_variable,VARIANT,[COMPUTED],(from build.variant)) - else - $(call show_config_variable,VARIANT,[USER]) - endif - - ifndef BOARD - BOARD := $(call PARSE_BOARD,$(BOARD_TAG),build.board) - ifndef BOARD - BOARD := $(shell echo $(ARCHITECTURE)_$(BOARD_TAG) | tr '[:lower:]' '[:upper:]') - endif - $(call show_config_variable,BOARD,[COMPUTED],(from build.board)) - else - $(call show_config_variable,BOARD,[USER]) - endif - - # see if we are a caterina device like leonardo or micro - CATERINA := $(findstring caterina,$(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.file)) - ifndef CATERINA - # 1.5+ method if not a submenu - CATERINA := $(findstring caterina,$(call PARSE_BOARD,$(BOARD_TAG),bootloader.file)) - endif - ifndef CATERINA - # 1.0 method uses deprecated bootloader.path - CATERINA := $(findstring caterina,$(call PARSE_BOARD,$(BOARD_TAG),bootloader.path)) - endif - - # processor stuff - ifndef MCU - MCU := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.mcu) - ifndef MCU - MCU := $(call PARSE_BOARD,$(BOARD_TAG),build.mcu) - endif - endif - - ifndef F_CPU - ifdef BOARD_CLOCK - F_CPU := $(call PARSE_BOARD,$(BOARD_TAG),menu.(speed|clock).$(BOARD_CLOCK).build.f_cpu) - endif - ifndef F_CPU - F_CPU := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.f_cpu) - endif - ifndef F_CPU - F_CPU := $(call PARSE_BOARD,$(BOARD_TAG),build.f_cpu) - endif - endif - - ifneq ($(CATERINA),) - # USB IDs for the caterina devices like leonardo or micro - ifndef USB_VID - USB_VID = $(call PARSE_BOARD,$(BOARD_TAG),build.vid) - endif - - # coping with 2-3 methods sparkfun use for usb.pid - ifndef USB_PID - USB_PID := $(call PARSE_BOARD,$(BOARD_TAG),build.pid) - ifndef USB_PID - USB_PID := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.pid) - endif - endif +# Select a core from the 'cores' directory +CORE = $(call PARSE_BOARD,$(BOARD_TAG),build.core) +$(call show_config_variable,CORE,[COMPUTED],(from build.core)) - ifndef USB_PRODUCT - USB_PRODUCT := $(call PARSE_BOARD,$(BOARD_TAG),build.usb_product) - ifdef USB_PRODUCT - $(call show_config_variable,USB_PRODUCT,[COMPUTED]) - endif - endif +# Which variant? This affects the include path +VARIANT := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.variant) +ifndef VARIANT + VARIANT := $(call PARSE_BOARD,$(BOARD_TAG),build.variant) +endif +$(call show_config_variable,VARIANT,[COMPUTED],(from build.variant)) - ifndef USB_MANUFACTURER - USB_MANUFACTURER := $(call PARSE_BOARD,$(BOARD_TAG),build.usb_manufacturer) - ifndef USB_MANUFACTURER - USB_MANUFACTURER = "Unknown" - else - $(call show_config_variable,USB_MANUFACTURER,[COMPUTED]) - endif - endif - endif +BOARD := $(call PARSE_BOARD,$(BOARD_TAG),build.board) +ifndef BOARD + BOARD := $(shell echo $(ARCHITECTURE)_$(BOARD_TAG) | tr '[:lower:]' '[:upper:]') +endif +$(call show_config_variable,BOARD,[COMPUTED],(from build.board)) - # normal programming info - ifndef AVRDUDE_ARD_PROGRAMMER - AVRDUDE_ARD_PROGRAMMER := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).upload.protocol) - ifndef AVRDUDE_ARD_PROGRAMMER - AVRDUDE_ARD_PROGRAMMER := $(call PARSE_BOARD,$(BOARD_TAG),upload.protocol) - endif - endif +# see if we are a caterina device like leonardo or micro +CATERINA := $(findstring caterina,$(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.file)) +ifndef CATERINA + CATERINA := $(findstring caterina,$(call PARSE_BOARD,$(BOARD_TAG),bootloader.file)) +endif - ifndef AVRDUDE_ARD_BAUDRATE - AVRDUDE_ARD_BAUDRATE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).upload.speed) - ifndef AVRDUDE_ARD_BAUDRATE - AVRDUDE_ARD_BAUDRATE := $(call PARSE_BOARD,$(BOARD_TAG),upload.speed) - endif - endif +# processor stuff +MCU := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.mcu) +ifndef MCU + MCU := $(call PARSE_BOARD,$(BOARD_TAG),build.mcu) +endif - # fuses if you're using e.g. ISP - ifndef ISP_LOCK_FUSE_PRE - ISP_LOCK_FUSE_PRE = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.unlock_bits) - endif +ifdef BOARD_CLOCK + F_CPU := $(call PARSE_BOARD,$(BOARD_TAG),menu.(speed|clock).$(BOARD_CLOCK).build.f_cpu) +endif +ifndef F_CPU + F_CPU := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.f_cpu) +endif +ifndef F_CPU + F_CPU := $(call PARSE_BOARD,$(BOARD_TAG),build.f_cpu) +endif - ifndef ISP_HIGH_FUSE - ifdef BOARD_CLOCK - ISP_HIGH_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(speed|clock).$(BOARD_CLOCK).bootloader.high_fuses) - endif - ifndef ISP_HIGH_FUSE - ISP_HIGH_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.high_fuses) - endif - ifndef ISP_HIGH_FUSE - ISP_HIGH_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),bootloader.high_fuses) - endif - endif +# USB IDs for the caterina devices like leonardo or micro +USB_VID = $(call PARSE_BOARD,$(BOARD_TAG),build.vid) - ifndef ISP_LOW_FUSE - ifdef BOARD_CLOCK - ISP_LOW_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(speed|clock).$(BOARD_CLOCK).bootloader.low_fuses) - endif - ifndef ISP_LOW_FUSE - ISP_LOW_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.low_fuses) - endif - ifndef ISP_LOW_FUSE - ISP_LOW_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),bootloader.low_fuses) - endif - endif +# coping with 2-3 methods sparkfun use for usb.pid +USB_PID := $(call PARSE_BOARD,$(BOARD_TAG),build.pid) +ifndef USB_PID + USB_PID := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.pid) +endif - ifndef ISP_EXT_FUSE - ifdef BOARD_CLOCK - ISP_EXT_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(speed|clock).$(BOARD_CLOCK).bootloader.extended_fuses) - endif - ifndef ISP_EXT_FUSE - ISP_EXT_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.extended_fuses) - endif - ifndef ISP_EXT_FUSE - ISP_EXT_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),bootloader.extended_fuses) - endif - endif +USB_PRODUCT := $(call PARSE_BOARD,$(BOARD_TAG),build.usb_product) +ifdef USB_PRODUCT + $(call show_config_variable,USB_PRODUCT,[COMPUTED]) +endif - ifndef BOOTLOADER_PATH - BOOTLOADER_PATH = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.path) - endif +USB_MANUFACTURER := $(call PARSE_BOARD,$(BOARD_TAG),build.usb_manufacturer) +ifndef USB_MANUFACTURER + USB_MANUFACTURER = "Unknown" +else + $(call show_config_variable,USB_MANUFACTURER,[COMPUTED]) +endif - ifndef BOOTLOADER_FILE - BOOTLOADER_FILE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.file) - ifndef BOOTLOADER_FILE - BOOTLOADER_FILE := $(call PARSE_BOARD,$(BOARD_TAG),bootloader.file) - endif - endif +# normal programming info +AVRDUDE_ARD_PROGRAMMER := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).upload.protocol) +ifndef AVRDUDE_ARD_PROGRAMMER + AVRDUDE_ARD_PROGRAMMER := $(call PARSE_BOARD,$(BOARD_TAG),upload.protocol) +endif - ifndef ISP_LOCK_FUSE_POST - ISP_LOCK_FUSE_POST = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.lock_bits) - endif +AVRDUDE_ARD_BAUDRATE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).upload.speed) +ifndef AVRDUDE_ARD_BAUDRATE + AVRDUDE_ARD_BAUDRATE := $(call PARSE_BOARD,$(BOARD_TAG),upload.speed) +endif - ifndef HEX_MAXIMUM_SIZE - HEX_MAXIMUM_SIZE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).upload.maximum_size) - ifndef HEX_MAXIMUM_SIZE - HEX_MAXIMUM_SIZE := $(call PARSE_BOARD,$(BOARD_TAG),upload.maximum_size) - endif - endif +BOOTLOADER_PATH = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.path) +BOOTLOADER_FILE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.file) +ifndef BOOTLOADER_FILE + BOOTLOADER_FILE := $(call PARSE_BOARD,$(BOARD_TAG),bootloader.file) endif -# Everything gets built in here (include BOARD_TAG now) -ifndef OBJDIR - OBJDIR = build - $(call show_config_variable,OBJDIR,[COMPUTED],(from BOARD_TAG)) -else - $(call show_config_variable,OBJDIR,[USER]) +HEX_MAXIMUM_SIZE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).upload.maximum_size) +ifndef HEX_MAXIMUM_SIZE + HEX_MAXIMUM_SIZE := $(call PARSE_BOARD,$(BOARD_TAG),upload.maximum_size) endif +$(call show_config_variable,OBJDIR,[COMPUTED],(from BOARD_TAG)) + # Now that we have ARDUINO_DIR, ARDMK_VENDOR, ARCHITECTURE and CORE, # we can set ARDUINO_CORE_PATH. -ifndef ARDUINO_CORE_PATH - ifeq ($(strip $(CORE)),) - ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/$(ARCHITECTURE)/$(ARDUINO_VERSION)/cores/arduino - $(call show_config_variable,ARDUINO_CORE_PATH,[DEFAULT]) +ifeq ($(strip $(CORE)),) + ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/$(ARCHITECTURE)/$(ARDUINO_VERSION)/cores/arduino + $(call show_config_variable,ARDUINO_CORE_PATH,[DEFAULT]) +else + ARDUINO_CORE_PATH = $(ALTERNATE_CORE_PATH)/cores/$(CORE) + ifeq ($(wildcard $(ARDUINO_CORE_PATH)),) + ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/$(ARCHITECTURE)/$(ARDUINO_VERSION)/cores/$(CORE) + $(call show_config_variable,ARDUINO_CORE_PATH,[COMPUTED],(from ARDUINO_DIR, BOARD_TAG and boards.txt)) else - ARDUINO_CORE_PATH = $(ALTERNATE_CORE_PATH)/cores/$(CORE) - ifeq ($(wildcard $(ARDUINO_CORE_PATH)),) - ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/$(ARCHITECTURE)/$(ARDUINO_VERSION)/cores/$(CORE) - $(call show_config_variable,ARDUINO_CORE_PATH,[COMPUTED],(from ARDUINO_DIR, BOARD_TAG and boards.txt)) - else - $(call show_config_variable,ARDUINO_CORE_PATH,[COMPUTED],(from ALTERNATE_CORE_PATH, BOARD_TAG and boards.txt)) - endif + $(call show_config_variable,ARDUINO_CORE_PATH,[COMPUTED],(from ALTERNATE_CORE_PATH, BOARD_TAG and boards.txt)) endif -else - $(call show_config_variable,ARDUINO_CORE_PATH,[USER]) endif ######################################################################## # Reset -ifndef RESET_CMD - ARD_RESET_ARDUINO_PATH = tools/reset_leonardo.py - ARD_RESET_ARDUINO := $(PYTHON_CMD) $(ARD_RESET_ARDUINO_PATH) - RESET_CMD = $(ARD_RESET_ARDUINO) $(DEVICE_PATH) - $(call show_config_variable,RESET_CMD,[COMPUTED],(from PYTHON_CMD, ARD_RESET_OPTS and MONITOR_PORT)) -else - $(call show_config_variable,RESET_CMD,[USER]) -endif +ARD_RESET_ARDUINO := $(PYTHON_CMD) $(ARD_RESET_ARDUINO_PATH) +RESET_CMD = $(ARD_RESET_ARDUINO) $(DEVICE_PATH) +$(call show_config_variable,RESET_CMD,[COMPUTED],(from PYTHON_CMD, ARD_RESET_OPTS and MONITOR_PORT)) ifneq ($(CATERINA),) ERROR_ON_CATERINA = $(error On $(BOARD_TAG), raw_xxx operation is not supported) @@ -413,102 +213,31 @@ else endif ######################################################################## -# Local sources - -LOCAL_SRCS ?= $(wildcard src/*.cpp) -LOCAL_OBJ_FILES = $(LOCAL_SRCS:.cpp=.cpp.o) -LOCAL_OBJS = $(patsubst %,$(OBJDIR)/%,$(LOCAL_OBJ_FILES)) - -ifeq ($(words $(LOCAL_SRCS)), 0) - $(error At least one source file is needed) -endif +# Core sources +ifdef ARDUINO_CORE_PATH + CORE_C_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.c) + CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/$(TOOL_PREFIX)-libc/*.c) + CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp) + CORE_AS_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.S) -# core sources -ifeq ($(strip $(NO_CORE)),) - ifdef ARDUINO_CORE_PATH - CORE_C_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.c) - CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/$(TOOL_PREFIX)-libc/*.c) - CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp) - CORE_AS_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.S) - - # ArduinoCore-API - CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/api/*.c) - CORE_CPP_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/api/*.cpp) - - # USB Core if samd or sam - ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam) - CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/avr/*.c) # avr core emulation files - CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/USB/*.c) - CORE_CPP_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/USB/*.cpp) - endif - - ifneq ($(strip $(NO_CORE_MAIN_CPP)),) - CORE_CPP_SRCS := $(filter-out %main.cpp, $(CORE_CPP_SRCS)) - $(call show_config_info,NO_CORE_MAIN_CPP set so core library will not include main.cpp,[MANUAL]) - endif + # ArduinoCore-API + CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/api/*.c) + CORE_CPP_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/api/*.cpp) - # Add core files for sam devices in CORE_OJBS filtering specific paths - ifdef SAM_CORE_PATH - SAM_CORE_OBJ_FILES = $(SAM_CORE_C_SRCS:.c=.c.o) $(SAM_CORE_CPP_SRCS:.cpp=.cpp.o) $(SAM_CORE_AS_SRCS:.S=.S.o) - # variant core files - CORE_OBJS += $(patsubst $(SAM_CORE_PATH)/%, \ - $(OBJDIR)/core/%, $(filter $(SAM_CORE_PATH)/%, $(SAM_CORE_OBJ_FILES))) - # libsam on Due - ifdef SAM_LIBSAM_PATH - CORE_OBJS += $(patsubst $(SAM_LIBSAM_PATH)/source/%, \ - $(OBJDIR)/core/%, $(filter $(SAM_LIBSAM_PATH)/source/%, $(SAM_CORE_OBJ_FILES))) - endif - # chip sources on Due - ifdef SAM_SYSTEM_PATH - CORE_OBJS += $(patsubst $(SAM_SYSTEM_PATH)/source/%, \ - $(OBJDIR)/core/%, $(filter $(SAM_SYSTEM_PATH)/source/%, $(SAM_CORE_OBJ_FILES))) - endif - endif - - CORE_OBJ_FILES = $(CORE_C_SRCS:.c=.c.o) $(CORE_CPP_SRCS:.cpp=.cpp.o) $(CORE_AS_SRCS:.S=.S.o) - CORE_OBJS += $(patsubst $(ARDUINO_CORE_PATH)/%, \ - $(OBJDIR)/core/%,$(CORE_OBJ_FILES)) + ifneq ($(strip $(NO_CORE_MAIN_CPP)),) + CORE_CPP_SRCS := $(filter-out %main.cpp, $(CORE_CPP_SRCS)) + $(call show_config_info,NO_CORE_MAIN_CPP set so core library will not include main.cpp,[MANUAL]) endif -else - $(call show_config_info,NO_CORE set so core library will not be built,[MANUAL]) -endif - -######################################################################## -# Determine ARDUINO_LIBS automatically - -ifndef ARDUINO_LIBS - # automatically determine included libraries - ARDUINO_LIBS += $(filter $(notdir $(wildcard $(ARDUINO_DIR)/libraries/*)), \ - $(shell sed -ne 's/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p' $(LOCAL_SRCS))) - ARDUINO_LIBS += $(filter $(notdir $(wildcard $(PROJ_LIBS_PATH)/*)), \ - $(shell sed -ne 's/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p' $(LOCAL_SRCS))) - ARDUINO_LIBS += $(filter $(notdir $(wildcard $(ARDUINO_PLATFORM_LIB_PATH)/*)), \ - $(shell sed -ne 's/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p' $(LOCAL_SRCS))) + CORE_OBJ_FILES = $(CORE_C_SRCS:.c=.c.o) $(CORE_CPP_SRCS:.cpp=.cpp.o) $(CORE_AS_SRCS:.S=.S.o) + CORE_OBJS += $(patsubst $(ARDUINO_CORE_PATH)/%, \ + $(OBJDIR)/core/%,$(CORE_OBJ_FILES)) endif ######################################################################## -# Serial monitor (just a screen wrapper) - -# Quite how to construct the monitor command seems intimately tied -# to the command we're using (here screen). So, read the screen docs -# for more information (search for 'character special device'). - -ifeq ($(strip $(NO_CORE)),) - ifndef MONITOR_BAUDRATE - MONITOR_BAUDRATE = 9600 - $(call show_config_variable,MONITOR_BAUDRATE,[ASSUMED]) - else - $(call show_config_variable,MONITOR_BAUDRATE,[USER]) - endif +# Serial monitor baudrate - ifndef MONITOR_CMD - MONITOR_CMD = screen - endif -endif - -# Include Arduino Header file -ARDUINO_HEADER=Arduino.h +$(call show_config_variable,MONITOR_BAUDRATE,[USER]) ######################################################################## # Rules for making stuff @@ -520,30 +249,6 @@ TARGET_EEP = $(OBJDIR)/$(TARGET).eep TARGET_BIN = $(OBJDIR)/$(TARGET).bin CORE_LIB = $(OBJDIR)/libcore.a -# Names of executables -# In the rare case of wanting to override a path and/or excecutable -# name, the OVERRIDE_EXECUTABLES variable must be defned and _all_ -# the excecutables (CC, CXX, AS, OBJCOPY, OBJDUMP AR, SIZE and NM) -# _must_ be defined in the calling makefile. -# We can't use "?=" assignment because these are already implicitly -# defined by Make (e.g. $(CC) == cc). -ifndef OVERRIDE_EXECUTABLES - CC = $(TOOLS_PATH)/$(CC_NAME) - CXX = $(TOOLS_PATH)/$(CXX_NAME) - AS = $(TOOLS_PATH)/$(AS_NAME) - OBJCOPY = $(TOOLS_PATH)/$(OBJCOPY_NAME) - OBJDUMP = $(TOOLS_PATH)/$(OBJDUMP_NAME) - AR = $(TOOLS_PATH)/$(AR_NAME) - SIZE = $(TOOLS_PATH)/$(SIZE_NAME) - NM = $(TOOLS_PATH)/$(NM_NAME) -endif - -REMOVE = rm -rf -MV = mv -f -CAT = cat -ECHO = printf -MKDIR = mkdir -p - # recursive wildcard function, call with params: # - start directory (finished with /) or empty string for current dir # - glob pattern @@ -614,31 +319,18 @@ ifdef ARDUINO_PLATFORM_LIB_PATH PLATFORM_LIB_OBJS := $(patsubst $(ARDUINO_PLATFORM_LIB_PATH)/%.cpp,$(OBJDIR)/platformlibs/%.cpp.o,$(PLATFORM_LIB_CPP_SRCS)) \ $(patsubst $(ARDUINO_PLATFORM_LIB_PATH)/%.c,$(OBJDIR)/platformlibs/%.c.o,$(PLATFORM_LIB_C_SRCS)) \ $(patsubst $(ARDUINO_PLATFORM_LIB_PATH)/%.S,$(OBJDIR)/platformlibs/%.S.o,$(PLATFORM_LIB_AS_SRCS)) - endif # Dependency files -DEPS = $(LOCAL_OBJS:.o=.d) $(LIB_OBJS:.o=.d) $(PLATFORM_OBJS:.o=.d) $(PROJ_LIB_OJS:.o=.d) $(CORE_OBJS:.o=.d) +DEPS = $(LOCAL_OBJS:.o=.d) $(LIB_OBJS:.o=.d) $(PLATFORM_OBJS:.o=.d) $(PROJ_LIB_OJS:.o=.d) $(CORE_OBJS:.o=.d) -ifndef OPTIMIZATION_LEVEL - OPTIMIZATION_LEVEL=s - $(call show_config_variable,OPTIMIZATION_LEVEL,[DEFAULT]) -else - $(call show_config_variable,OPTIMIZATION_LEVEL,[USER]) -endif - -DEBUG_FLAGS = -O0 -g +$(call show_config_variable,OPTIMIZATION_LEVEL,[DEFAULT]) # SoftwareSerial requires -Os (some delays are tuned for this optimization level) %SoftwareSerial.cpp.o : OPTIMIZATION_FLAGS = -Os %Uart.cpp.o : OPTIMIZATION_FLAGS = -Os -ifndef MCU_FLAG_NAME - MCU_FLAG_NAME = mmcu - $(call show_config_variable,MCU_FLAG_NAME,[DEFAULT]) -else - $(call show_config_variable,MCU_FLAG_NAME,[USER]) -endif +$(call show_config_variable,MCU_FLAG_NAME,[DEFAULT]) CPPFLAGS += -$(MCU_FLAG_NAME)=$(MCU) -DF_CPU=$(F_CPU) -DARDUINO=$(ARDUINO_VERSION_SHORT) -DARDUINO_$(BOARD) $(ARDUINO_ARCH_FLAG) \ "-DARDUINO_BOARD=\"$(BOARD)\"" "-DARDUINO_VARIANT=\"$(VARIANT)\"" \ @@ -653,19 +345,17 @@ CPPFLAGS += -$(MCU_FLAG_NAME)=$(MCU) -DF_CPU=$(F_CPU) -DARDUINO=$(ARDUINO_VERSIO CPPFLAGS := -D__PROG_TYPES_COMPAT__ $(CPPFLAGS) ifdef DEBUG -OPTIMIZATION_FLAGS= $(DEBUG_FLAGS) + OPTIMIZATION_FLAGS= $(DEBUG_FLAGS) else -OPTIMIZATION_FLAGS = -O$(OPTIMIZATION_LEVEL) + OPTIMIZATION_FLAGS = -O$(OPTIMIZATION_LEVEL) endif CPPFLAGS += $(OPTIMIZATION_FLAGS) # USB IDs for the Caterina devices like leonardo or micro -ifneq ($(CATERINA),) - CPPFLAGS += -DUSB_VID=$(USB_VID) -DUSB_PID=$(USB_PID) - ifdef USB_PRODUCT - CPPFLAGS += -DUSB_PRODUCT='$(USB_PRODUCT)' -DUSB_MANUFACTURER='$(USB_MANUFACTURER)' - endif +CPPFLAGS += -DUSB_VID=$(USB_VID) -DUSB_PID=$(USB_PID) +ifdef USB_PRODUCT + CPPFLAGS += -DUSB_PRODUCT='$(USB_PRODUCT)' -DUSB_MANUFACTURER='$(USB_MANUFACTURER)' endif # $(TOOL_PREFIX)-gcc version that we can do maths on @@ -674,37 +364,29 @@ CC_VERNUM = $(shell $(CC) -dumpversion | sed 's/\.//g') # moved from above so we can find version-dependant ar ifeq ($(TOOL_PREFIX), avr) ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1) - AR_NAME := $(TOOL_PREFIX)-gcc-ar + AR_NAME := $(TOOL_PREFIX)-gcc-ar else - AR_NAME := $(TOOL_PREFIX)-ar + AR_NAME := $(TOOL_PREFIX)-ar endif endif -ifndef CFLAGS_STD - ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1) - CFLAGS_STD = -std=gnu11 - else - CFLAGS_STD = - endif - $(call show_config_variable,CFLAGS_STD,[DEFAULT]) +ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1) + CFLAGS_STD = -std=gnu11 else - $(call show_config_variable,CFLAGS_STD,[USER]) + CFLAGS_STD = endif +$(call show_config_variable,CFLAGS_STD,[DEFAULT]) -ifndef CXXFLAGS_STD - ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1) - CXXFLAGS_STD = -std=gnu++11 - else - CXXFLAGS_STD = - endif - $(call show_config_variable,CXXFLAGS_STD,[DEFAULT]) +ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1) + CXXFLAGS_STD = -std=gnu++11 else - $(call show_config_variable,CXXFLAGS_STD,[USER]) + CXXFLAGS_STD = endif +$(call show_config_variable,CXXFLAGS_STD,[DEFAULT]) -CFLAGS += $(CFLAGS_STD) -CXXFLAGS += -fpermissive -fno-exceptions $(CXXFLAGS_STD) -ASFLAGS += -x assembler-with-cpp +CFLAGS += $(CFLAGS_STD) +CXXFLAGS += -fpermissive -fno-exceptions $(CXXFLAGS_STD) +ASFLAGS += -x assembler-with-cpp DIAGNOSTICS_COLOR_WHEN ?= always # Flags for AVR @@ -723,33 +405,19 @@ else endif endif -LDFLAGS += -$(MCU_FLAG_NAME)=$(MCU) -Wl,--gc-sections -O$(OPTIMIZATION_LEVEL) -SIZEFLAGS ?= --mcu=$(MCU) -C +LDFLAGS += -$(MCU_FLAG_NAME)=$(MCU) -Wl,--gc-sections -O$(OPTIMIZATION_LEVEL) +SIZEFLAGS ?= --mcu=$(MCU) -C -# for backwards compatibility, grab ARDUINO_PORT if the user has it set -# instead of MONITOR_PORT MONITOR_PORT ?= $(ARDUINO_PORT) ifneq ($(strip $(MONITOR_PORT)),) - ifeq ($(CURRENT_OS), WINDOWS) - # Expect MONITOR_PORT to be '1' or 'com1' for COM1 in Windows. Split it up - # into the two styles required: /dev/ttyS* for ard-reset-arduino and com* - # for avrdude. This also could work with /dev/com* device names and be more - # consistent, but the /dev/com* is not recommended by Cygwin and doesn't - # always show up. - COM_PORT_ID = $(subst com,,$(MONITOR_PORT)) - COM_STYLE_MONITOR_PORT = com$(COM_PORT_ID) - DEVICE_PATH = /dev/ttyS$(shell awk 'BEGIN{ print $(COM_PORT_ID) - 1 }') - else - # set DEVICE_PATH based on user-defined MONITOR_PORT or ARDUINO_PORT - DEVICE_PATH = $(MONITOR_PORT) - endif + DEVICE_PATH = $(MONITOR_PORT) $(call show_config_variable,DEVICE_PATH,[COMPUTED],(from MONITOR_PORT)) else # If no port is specified, try to guess it from wildcards. # Will only work if the Arduino is the only/first device matched. DEVICE_PATH = $(firstword $(wildcard \ - /dev/ttyACM? /dev/ttyUSB? /dev/tty.usbserial* /dev/tty.usbmodem* /dev/tty.wchusbserial*)) + /dev/ttyACM? /dev/ttyUSB? /dev/tty.usbserial* /dev/tty.usbmodem* /dev/tty.wchusbserial*)) $(call show_config_variable,DEVICE_PATH,[AUTODETECTED]) endif @@ -764,16 +432,9 @@ ifdef FORCE_MONITOR_PORT get_monitor_port = $(DEVICE_PATH) else # Returns the Arduino port (first wildcard expansion) if it exists, otherwise it errors. - ifeq ($(CURRENT_OS), WINDOWS) - get_monitor_port = $(COM_STYLE_MONITOR_PORT) - else - get_monitor_port = $(if $(wildcard $(DEVICE_PATH)),$(firstword $(wildcard $(DEVICE_PATH))),$(error Arduino port $(DEVICE_PATH) not found!)) - endif + get_monitor_port = $(if $(wildcard $(DEVICE_PATH)),$(firstword $(wildcard $(DEVICE_PATH))),$(error Arduino port $(DEVICE_PATH) not found!)) endif -# Returns the ISP port (first wildcard expansion) if it exists, otherwise it errors. -get_isp_port = $(if $(wildcard $(ISP_PORT)),$(firstword $(wildcard $(ISP_PORT))),$(if $(findstring Xusb,X$(ISP_PORT)),$(ISP_PORT),$(error ISP port $(ISP_PORT) not found!))) - # 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 @@ -808,19 +469,10 @@ ifneq (,$(strip $(PLATFORM_LIB_NAMES))) $(foreach lib,$(PLATFORM_LIB_NAMES),$(call show_config_info, $(lib),[PLATFORM])) endif -# either calculate parent dir from arduino dir, or user-defined path -ifndef BOOTLOADER_PARENT - BOOTLOADER_PARENT = $(ARDUINO_DIR)/hardware/$(ARCHITECTURE)/$(ARDUINO_VERSION)/bootloaders - $(call show_config_variable,BOOTLOADER_PARENT,[COMPUTED],(from ARDUINO_DIR)) -else - $(call show_config_variable,BOOTLOADER_PARENT,[USER]) -endif +$(call show_config_variable,BOOTLOADER_PARENT,[DEFAULT]) ######################################################################## # Tools version info -ARDMK_VERSION = 1.6 -$(call show_config_variable,ARDMK_VERSION,[COMPUTED]) - CC_VERSION := $(shell $(CC) -dumpversion) $(call show_config_variable,CC_VERSION,[COMPUTED],($(CC_NAME))) @@ -981,16 +633,6 @@ $(OBJDIR)/%.sym: $(OBJDIR)/%.elf $(COMMON_DEPS) ######################################################################## # Ctags -# Assume ctags is on path unless has been specified -ifndef CTAGS_EXEC - CTAGS_EXEC = ctags -endif - -# Default to 'tags' unless user has specified a tags file -ifndef TAGS_FILE - TAGS_FILE = tags -endif - # ctags command: append, flags unsort (as will be sorted after) and specify filename CTAGS_CMD = $(CTAGS_EXEC) $(CTAGS_OPTS) -auf @@ -1016,105 +658,15 @@ else AVRDUDE_ARD_OPTS = -D endif AVRDUDE_ARD_OPTS += -c $(AVRDUDE_ARD_PROGRAMMER) -b $(AVRDUDE_ARD_BAUDRATE) -P -ifeq ($(CURRENT_OS), WINDOWS) - # get_monitor_port checks to see if the monitor port exists, assuming it is - # a file. In Windows, avrdude needs the port in the format 'com1' which is - # not a file, so we have to add the COM-style port directly. - AVRDUDE_ARD_OPTS += $(COM_STYLE_MONITOR_PORT) -else - AVRDUDE_ARD_OPTS += $(call get_monitor_port) -endif - -ifndef ISP_PROG - ifneq ($(strip $(AVRDUDE_ARD_PROGRAMMER)),) - ISP_PROG = $(AVRDUDE_ARD_PROGRAMMER) - else - ISP_PROG = stk500v1 - endif -endif - -ifndef AVRDUDE_ISP_BAUDRATE - ifneq ($(strip $(AVRDUDE_ARD_BAUDRATE)),) - AVRDUDE_ISP_BAUDRATE = $(AVRDUDE_ARD_BAUDRATE) - else - AVRDUDE_ISP_BAUDRATE = 19200 - endif -endif - -# Fuse settings copied from Arduino IDE. -# https://github.com/arduino/Arduino/blob/master/app/src/processing/app/debug/AvrdudeUploader.java#L254 - -# Pre fuse settings -ifndef AVRDUDE_ISP_FUSES_PRE - ifneq ($(strip $(ISP_LOCK_FUSE_PRE)),) - AVRDUDE_ISP_FUSES_PRE += -U lock:w:$(ISP_LOCK_FUSE_PRE):m - endif - - ifneq ($(strip $(ISP_EXT_FUSE)),) - AVRDUDE_ISP_FUSES_PRE += -U efuse:w:$(ISP_EXT_FUSE):m - endif - - ifneq ($(strip $(ISP_HIGH_FUSE)),) - AVRDUDE_ISP_FUSES_PRE += -U hfuse:w:$(ISP_HIGH_FUSE):m - endif - - ifneq ($(strip $(ISP_LOW_FUSE)),) - AVRDUDE_ISP_FUSES_PRE += -U lfuse:w:$(ISP_LOW_FUSE):m - endif -endif - -# Bootloader file settings -ifndef AVRDUDE_ISP_BURN_BOOTLOADER - ifneq ($(strip $(BOOTLOADER_FILE)),) - AVRDUDE_ISP_BURN_BOOTLOADER += -U flash:w:$(BOOTLOADER_PARENT)/$(BOOTLOADER_PATH)/$(BOOTLOADER_FILE):i - endif -endif - -# Post fuse settings -ifndef AVRDUDE_ISP_FUSES_POST - ifneq ($(strip $(ISP_LOCK_FUSE_POST)),) - AVRDUDE_ISP_FUSES_POST += -U lock:w:$(ISP_LOCK_FUSE_POST):m - endif -endif - -# Note: setting -D to disable flash erase before programming may cause issues -# with some boards like attiny84a, making the program not "take", -# so we do not set it by default. -AVRDUDE_ISP_OPTS = -c $(ISP_PROG) -b $(AVRDUDE_ISP_BAUDRATE) - -ifndef ISP_PORT - ifneq ($(strip $(ISP_PROG)),$(filter $(ISP_PROG), atmelice_isp usbasp usbtiny gpio linuxgpio avrispmkii dragon_isp dragon_dw)) - # switch for sam devices as bootloader will be on usb serial if using stk500_v2 - ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam) - AVRDUDE_ISP_OPTS += -P $(call get_monitor_port) - else - AVRDUDE_ISP_OPTS += -P $(call get_isp_port) - endif - endif -else - ifeq ($(CURRENT_OS), WINDOWS) - AVRDUDE_ISP_OPTS += -P $(ISP_PORT) - else - AVRDUDE_ISP_OPTS += -P $(call get_isp_port) - endif -endif - -ifndef ISP_EEPROM - ISP_EEPROM = 0 -endif +AVRDUDE_ARD_OPTS += $(call get_monitor_port) AVRDUDE_UPLOAD_HEX = -U flash:w:$(TARGET_HEX):i AVRDUDE_UPLOAD_EEP = -U eeprom:w:$(TARGET_EEP):i -AVRDUDE_ISPLOAD_OPTS = $(AVRDUDE_UPLOAD_HEX) - -ifneq ($(ISP_EEPROM), 0) - AVRDUDE_ISPLOAD_OPTS += $(AVRDUDE_UPLOAD_EEP) -endif ######################################################################## # Explicit targets start here -all: $(TARGET_EEP) $(TARGET_BIN) $(TARGET_HEX) +all: $(TARGET_EEP) $(TARGET_BIN) $(TARGET_HEX) # Rule to create $(OBJDIR) automatically. All rules with recipes that # create a file within it, but do not already depend on a file within it @@ -1123,134 +675,68 @@ all: $(TARGET_EEP) $(TARGET_BIN) $(TARGET_HEX) # list) to prevent remaking the target when any file in the directory # changes. $(OBJDIR): pre-build - $(MKDIR) $(OBJDIR) + $(MKDIR) $(OBJDIR) pre-build: - $(call runscript_if_exists,$(PRE_BUILD_HOOK)) + $(call runscript_if_exists,$(PRE_BUILD_HOOK)) # copied from arduino with start-group, end-group -$(TARGET_ELF): $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) -# sam devices need start and end group, and must be linked using C++ compiler -ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam) - $(CXX) $(LINKER_SCRIPTS) -Wl,-Map=$(OBJDIR)/$(TARGET).map -o $@ $(LOCAL_OBJS) $(OTHER_OBJS) $(OTHER_LIBS) $(LDFLAGS) $(CORE_LIB) -Wl,--end-group -# otherwise traditional -else - $(CC) $(LDFLAGS) -o $@ $(LOCAL_OBJS) $(OTHER_OBJS) $(OTHER_LIBS) $(CORE_LIB) -lc -lm $(LINKER_SCRIPTS) -endif +$(TARGET_ELF): $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) + $(CC) $(LDFLAGS) -o $@ $(LOCAL_OBJS) $(OTHER_OBJS) $(OTHER_LIBS) $(CORE_LIB) -lc -lm $(LINKER_SCRIPTS) -$(CORE_LIB): $(CORE_OBJS) $(LIB_OBJS) $(PLATFORM_LIB_OBJS) $(PROJ_LIB_OJS) - $(AR) rcs $@ $(CORE_OBJS) $(LIB_OBJS) $(PLATFORM_LIB_OBJS) $(PROJ_LIB_OJS) +$(CORE_LIB): $(CORE_OBJS) $(LIB_OBJS) $(PLATFORM_LIB_OBJS) $(PROJ_LIB_OJS) + $(AR) rcs $@ $(CORE_OBJS) $(LIB_OBJS) $(PLATFORM_LIB_OBJS) $(PROJ_LIB_OJS) error_on_caterina: - $(ERROR_ON_CATERINA) + $(ERROR_ON_CATERINA) # Use submake so we can guarantee the reset happens # before the upload, even with make -j -upload: $(TARGET_HEX) verify_size -ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam) -# do reset toggle at 1200 BAUD to enter bootloader if using avrdude or bossa -ifeq ($(strip $(UPLOAD_TOOL)), avrdude) - $(MAKE) reset -else ifeq ($(findstring bossac, $(strip $(UPLOAD_TOOL))), bossac) - $(MAKE) reset -endif - $(MAKE) do_sam_upload -else - $(MAKE) reset - $(MAKE) do_upload -endif +upload: $(TARGET_HEX) verify_size + $(MAKE) reset + $(MAKE) do_upload raw_upload: $(TARGET_HEX) verify_size -ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam) - $(MAKE) do_sam_upload -else - $(MAKE) error_on_caterina - $(MAKE) do_upload -endif + $(MAKE) error_on_caterina + $(MAKE) do_upload do_upload: - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \ - $(AVRDUDE_UPLOAD_HEX) - -do_sam_upload: $(TARGET_BIN) verify_size -ifeq ($(findstring openocd, $(strip $(UPLOAD_TOOL))), openocd) - $(OPENOCD) $(OPENOCD_OPTS) -c "telnet_port disabled; program {{$(TARGET_BIN)}} verify reset $(BOOTLOADER_SIZE); shutdown" -else ifeq ($(findstring bossac, $(strip $(UPLOAD_TOOL))), bossac) - $(BOSSA) $(BOSSA_OPTS) $(TARGET_BIN) -else ifeq ($(findstring gdb, $(strip $(UPLOAD_TOOL))), gdb) - $(GDB) $(GDB_UPLOAD_OPTS) -else ifeq ($(strip $(UPLOAD_TOOL)), avrdude) - $(MAKE) ispload -else - @$(ECHO) "$(BOOTLOADER_UPLOAD_TOOL) not currently supported!\n\n" -endif + $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) $(AVRDUDE_UPLOAD_HEX) -do_eeprom: $(TARGET_EEP) $(TARGET_HEX) - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \ - $(AVRDUDE_UPLOAD_EEP) +do_eeprom: $(TARGET_EEP) $(TARGET_HEX) + $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) $(AVRDUDE_UPLOAD_EEP) -eeprom: $(TARGET_HEX) verify_size - $(MAKE) reset - $(MAKE) do_eeprom +eeprom: $(TARGET_HEX) verify_size + $(MAKE) reset + $(MAKE) do_eeprom raw_eeprom: $(TARGET_HEX) verify_size - $(MAKE) error_on_caterina - $(MAKE) do_eeprom + $(MAKE) error_on_caterina + $(MAKE) do_eeprom reset: - $(call arduino_output,Resetting Arduino...) - $(RESET_CMD) + $(call arduino_output,Resetting Arduino...) + $(RESET_CMD) # 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: - for STTYF in 'stty -F' 'stty --file' 'stty -f' 'stty <' ; \ - do $$STTYF /dev/tty >/dev/null 2>&1 && break ; \ - done ; \ - $$STTYF $(call get_monitor_port) hupcl ; \ - (sleep 0.1 2>/dev/null || sleep 1) ; \ - $$STTYF $(call get_monitor_port) -hupcl - -ispload: $(TARGET_EEP) $(TARGET_HEX) verify_size - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e \ - $(AVRDUDE_ISPLOAD_OPTS) - -burn_bootloader: -ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam) - ifeq ($(strip $(BOOTLOADER_UPLOAD_TOOL)), openocd) - $(OPENOCD) $(OPENOCD_OPTS) -c "telnet_port disabled; init; halt; $(BOOTLOADER_UNPROTECT); program {{$(BOOTLOADER_PARENT)/$(BOOTLOADER_FILE)}} verify reset; shutdown" - else - @$(ECHO) "$(BOOTLOADER_UPLOAD_TOOL) not currently supported!\n\n" - endif -else - ifneq ($(strip $(AVRDUDE_ISP_FUSES_PRE)),) - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e $(AVRDUDE_ISP_FUSES_PRE) - endif - ifneq ($(strip $(AVRDUDE_ISP_BURN_BOOTLOADER)),) - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_BURN_BOOTLOADER) - endif - ifneq ($(strip $(AVRDUDE_ISP_FUSES_POST)),) - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_FUSES_POST) - endif -endif - -set_fuses: -ifneq ($(strip $(AVRDUDE_ISP_FUSES_PRE)),) - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_FUSES_PRE) -endif -ifneq ($(strip $(AVRDUDE_ISP_FUSES_POST)),) - $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_FUSES_POST) -endif + for STTYF in 'stty -F' 'stty --file' 'stty -f' 'stty <' ; \ + do $$STTYF /dev/tty >/dev/null 2>&1 && break ; \ + done ; \ + $$STTYF $(call get_monitor_port) hupcl ; \ + (sleep 0.1 2>/dev/null || sleep 1) ; \ + $$STTYF $(call get_monitor_port) -hupcl clean:: - $(REMOVE) $(OBJDIR) + $(REMOVE) $(OBJDIR) -size: $(TARGET_HEX) - $(call avr_size,$(TARGET_ELF),$(TARGET_HEX)) +size: $(TARGET_HEX) + $(call avr_size,$(TARGET_ELF),$(TARGET_HEX)) show_boards: - @$(CAT) $(BOARDS_TXT) | grep -E '^[a-zA-Z0-9_\-]+.name' | sort -uf | sed 's/.name=/:/' | column -s: -t + @$(CAT) $(BOARDS_TXT) | grep -E '^[a-zA-Z0-9_\-]+.name' | sort -uf | sed 's/.name=/:/' | column -s: -t show_submenu: @$(CAT) $(BOARDS_TXT) | grep -E '[a-zA-Z0-9_\-]+.menu.(cpu|chip).[a-zA-Z0-9_\-]+=' | sort -uf | sed 's/.menu.\(cpu\|chip\)./:/' | sed 's/=/:/' | column -s: -t @@ -1263,11 +749,11 @@ else $(MONITOR_CMD) -serial -sercfg $(MONITOR_BAUDRATE) $(call get_monitor_port) endif else ifeq ($(notdir $(MONITOR_CMD)), picocom) - $(MONITOR_CMD) -b $(MONITOR_BAUDRATE) $(MONITOR_PARAMS) $(call get_monitor_port) + $(MONITOR_CMD) -b $(MONITOR_BAUDRATE) $(MONITOR_PARAMS) $(call get_monitor_port) else ifeq ($(notdir $(MONITOR_CMD)), cu) - $(MONITOR_CMD) -l $(call get_monitor_port) -s $(MONITOR_BAUDRATE) + $(MONITOR_CMD) -l $(call get_monitor_port) -s $(MONITOR_BAUDRATE) else - $(MONITOR_CMD) $(call get_monitor_port) $(MONITOR_BAUDRATE) + $(MONITOR_CMD) $(call get_monitor_port) $(MONITOR_BAUDRATE) endif debug_init: @@ -1277,10 +763,10 @@ debug: $(GDB) $(GDB_OPTS) disasm: $(OBJDIR)/$(TARGET).lss - @$(ECHO) "The compiled ELF file has been disassembled to $(OBJDIR)/$(TARGET).lss\n\n" + @$(ECHO) "The compiled ELF file has been disassembled to $(OBJDIR)/$(TARGET).lss\n\n" symbol_sizes: $(OBJDIR)/$(TARGET).sym - @$(ECHO) "A symbol listing sorted by their size have been dumped to $(OBJDIR)/$(TARGET).sym\n\n" + @$(ECHO) "A symbol listing sorted by their size have been dumped to $(OBJDIR)/$(TARGET).sym\n\n" verify_size: ifeq ($(strip $(HEX_MAXIMUM_SIZE)),) @@ -1290,20 +776,18 @@ endif See http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it."; false; fi generate_assembly: $(OBJDIR)/$(TARGET).s - @$(ECHO) "Compiler-generated assembly for the main input source has been dumped to $(OBJDIR)/$(TARGET).s\n\n" + @$(ECHO) "Compiler-generated assembly for the main input source has been dumped to $(OBJDIR)/$(TARGET).s\n\n" generated_assembly: generate_assembly - @$(ECHO) "\"generated_assembly\" target is deprecated. Use \"generate_assembly\" target instead\n\n" + @$(ECHO) "\"generated_assembly\" target is deprecated. Use \"generate_assembly\" target instead\n\n" tags: ifneq ($(words $(wildcard $(TAGS_FILE))), 0) rm -f $(TAGS_FILE) endif - @$(ECHO) "Generating tags for local sources (INO an PDE files as C++): " - $(CTAGS_CMD) $(TAGS_FILE) --langmap=c++:+.ino.pde $(LOCAL_SRCS) ifneq ($(words $(ARDUINO_LIBS)), 0) - @$(ECHO) "Generating tags for project libraries: " - $(CTAGS_CMD) $(TAGS_FILE) $(foreach lib, $(ARDUINO_LIBS),$(PROJ_LIBS_PATH)/$(lib)/*) + @$(ECHO) "Generating tags for project libraries: " + $(CTAGS_CMD) $(TAGS_FILE) $(foreach lib, $(ARDUINO_LIBS),$(PROJ_LIBS_PATH)/$(lib)/*) endif @$(ECHO) "Generating tags for Arduino core: " $(CTAGS_CMD) $(TAGS_FILE) $(ARDUINO_CORE_PATH)/* @@ -1312,13 +796,12 @@ endif @$(ECHO) "Tag file generation complete, output: $(TAGS_FILE)\n" help_vars: - @$(CAT) $(ARDMK_DIR)/arduino-mk-vars.md + @$(CAT) $(ARDMK_DIR)/arduino-mk-vars.md help: - @$(ECHO) "\nAvailable targets:\n\ + @$(ECHO) "\nAvailable targets:\n\ make - compile the code\n\ make upload - upload\n\ - make ispload - upload using an ISP\n\ make raw_upload - upload without first resetting\n\ make eeprom - upload the eep file\n\ make raw_eeprom - upload the eep file without first resetting\n\ @@ -1342,17 +825,15 @@ help: original source code.\n\ make generate_assembly - generate a .s file containing the compiler\n\ generated assembly of the main sketch.\n\ - make burn_bootloader - burn bootloader and fuses\n\ - make set_fuses - set fuses without burning bootloader\n\ make tags - generate tags file including project libs and Arduino core\n\ make help_vars - print all variables that can be overridden\n\ make help - show this help\n\ " @$(ECHO) "Please refer to $(ARDMK_DIR)/Arduino.mk for more details.\n" -.PHONY: all upload raw_upload raw_eeprom error_on_caterina reset reset_stty ispload \ +.PHONY: all upload raw_upload raw_eeprom error_on_caterina reset reset_stty \ clean depends size show_boards monitor disasm symbol_sizes generated_assembly \ - generate_assembly verify_size burn_bootloader help pre-build tags debug debug_init + generate_assembly verify_size help pre-build tags debug debug_init # added - in the beginning, so that we don't get an error if the file is not present -include $(DEPS) -- cgit v1.2.3-18-g5258