aboutsummaryrefslogtreecommitdiff
path: root/Arduino.mk
diff options
context:
space:
mode:
authorSimon John <git@the-jedi.co.uk>2018-02-24 16:03:37 +0000
committerGitHub <noreply@github.com>2018-02-24 16:03:37 +0000
commit139b5dbc4919e118b0e18783fae8e51a2dbc258c (patch)
treecff8ea8bb5e6f63d7ada4eb85ad67a9b5237525a /Arduino.mk
parentb3c5127be244ef68f1f895155f3d8999f8800f83 (diff)
parentc10eaa4f480da35437d13fdc21df5d13e2d11866 (diff)
Merge branch 'master' into disable-prog-types-compat
Diffstat (limited to 'Arduino.mk')
-rw-r--r--Arduino.mk195
1 files changed, 142 insertions, 53 deletions
diff --git a/Arduino.mk b/Arduino.mk
index d245c36..a238fe6 100644
--- a/Arduino.mk
+++ b/Arduino.mk
@@ -261,7 +261,9 @@ else
endif
# include Common.mk now we know where it is
-include $(ARDMK_DIR)/Common.mk
+ifndef COMMON_INCLUDED
+ include $(ARDMK_DIR)/Common.mk
+endif
# show_config_variable macro is available now. So let's print config details for ARDMK_DIR
ifndef ARDMK_DIR_MSG
@@ -317,18 +319,19 @@ else
ifeq ($(ARCHITECTURE),avr)
ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_AVR
else
- ifeq ($(ARCHITECTURE),sam)
- ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_SAM
- else
- ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_$(shell echo $(ARCHITECTURE) | tr '[:lower:]' '[:upper:]')
- endif
+ ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_$(shell echo $(ARCHITECTURE) | tr '[:lower:]' '[:upper:]')
endif
endif
########################################################################
# 1.5.x vendor - defaults to arduino
ifndef ARDMK_VENDOR
- ARDMK_VENDOR = arduino
+ ARCH_LINUX := $(shell grep "Arch Linux" /etc/os-release 2>/dev/null)
+ ifdef ARCH_LINUX
+ ARDMK_VENDOR = archlinux-arduino
+ else
+ ARDMK_VENDOR = arduino
+ endif
$(call show_config_variable,ARDMK_VENDOR,[DEFAULT])
else
$(call show_config_variable,ARDMK_VENDOR,[USER])
@@ -454,7 +457,14 @@ ifndef 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)
+ # One last attempt using avr-gcc in case using arm
+ 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_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
@@ -644,6 +654,9 @@ ifeq ($(strip $(NO_CORE)),)
USB_PID := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.pid)
endif
endif
+
+ # add caterina flag to ARD_RESET_OPTS
+ ARD_RESET_OPTS += --caterina
endif
# normal programming info
@@ -745,34 +758,21 @@ endif
# Reset
ifndef RESET_CMD
- ARD_RESET_ARDUINO := $(shell which ard-reset-arduino 2> /dev/null)
- ifndef ARD_RESET_ARDUINO
- # same level as *.mk in bin directory when checked out from git
- # or in $PATH when packaged
- ARD_RESET_ARDUINO = $(ARDMK_DIR)/bin/ard-reset-arduino
- endif
- ifneq ($(CATERINA),)
- ifneq (,$(findstring CYGWIN,$(shell uname -s)))
- # confirm user is using default cygwin unix Python (which uses ttySx) and not Windows Python (which uses COMx)
- ifeq ($(shell which python),/usr/bin/python)
- RESET_CMD = $(ARD_RESET_ARDUINO) --caterina $(ARD_RESET_OPTS) $(DEVICE_PATH)
- else
- RESET_CMD = $(ARD_RESET_ARDUINO) --caterina $(ARD_RESET_OPTS) $(call get_monitor_port)
- endif
- else
- RESET_CMD = $(ARD_RESET_ARDUINO) --caterina $(ARD_RESET_OPTS) $(call get_monitor_port)
- endif
+ ARD_RESET_ARDUINO := $(shell which ard-reset-arduino 2> /dev/null)
+ ifndef ARD_RESET_ARDUINO
+ # same level as *.mk in bin directory when checked out from git
+ # or in $PATH when packaged
+ ARD_RESET_ARDUINO = $(ARDMK_DIR)/bin/ard-reset-arduino
+ endif
+ ifneq (,$(findstring CYGWIN,$(shell uname -s)))
+ # confirm user is using default cygwin unix Python (which uses ttySx) and not Windows Python (which uses COMx)
+ ifeq ($(shell which python),/usr/bin/python)
+ RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(DEVICE_PATH)
+ else
+ RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(call get_monitor_port)
+ endif
else
- ifneq (,$(findstring CYGWIN,$(shell uname -s)))
- # confirm user is using default cygwin unix Python (which uses ttySx) and not Windows Python (which uses COMx)
- ifeq ($(shell which python),/usr/bin/python)
- RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(DEVICE_PATH)
- else
- RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(call get_monitor_port)
- endif
- else
- RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(call get_monitor_port)
- endif
+ RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(call get_monitor_port)
endif
endif
@@ -815,7 +815,7 @@ ifeq ($(strip $(CHK_SOURCES)),)
$(call show_config_info,No .pde or .ino files found. If you are compiling .c or .cpp files then you need to explicitly include Arduino header files)
else
#TODO: Support more than one file. https://github.com/sudar/Arduino-Makefile/issues/49
- $(error Need exactly one .pde or .ino file. This makefile doesn't support multiple .ino/.pde files yet)
+ $(error Need exactly one .pde or .ino file. This makefile doesn\'t support multiple .ino/.pde files yet)
endif
endif
@@ -830,13 +830,26 @@ ifeq ($(strip $(NO_CORE)),)
CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp)
CORE_AS_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.S)
+ # USB Core if samd or sam
+ ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam)
+ 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
+ # Put alt core variant file for M0 devices in OTHER_OJBS
+ ifdef ALT_CORE_CPP_SRCS
+ ALT_CORE_OBJ_FILES = $(ALT_CORE_C_SRCS:.c=.c.o) $(ALT_CORE_CPP_SRCS:.cpp=.cpp.o) $(ALT_CORE_AS_SRCS:.S=.S.o)
+ OTHER_OBJS := $(patsubst $(ALTERNATE_CORE_PATH)/variants/$(VARIANT)/%, \
+ $(OBJDIR)/core/%,$(ALT_CORE_OBJ_FILES))
+ 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)/%, \
+ CORE_OBJS += $(patsubst $(ARDUINO_CORE_PATH)/%, \
$(OBJDIR)/core/%,$(CORE_OBJ_FILES))
endif
else
@@ -908,6 +921,7 @@ endif
TARGET_HEX = $(OBJDIR)/$(TARGET).hex
TARGET_ELF = $(OBJDIR)/$(TARGET).elf
TARGET_EEP = $(OBJDIR)/$(TARGET).eep
+TARGET_BIN = $(OBJDIR)/$(TARGET).bin
CORE_LIB = $(OBJDIR)/libcore.a
# Names of executables - chipKIT needs to override all to set paths to PIC32
@@ -1023,6 +1037,7 @@ endif
# 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
@@ -1100,7 +1115,7 @@ ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1)
endif
LDFLAGS += -$(MCU_FLAG_NAME)=$(MCU) -Wl,--gc-sections -O$(OPTIMIZATION_LEVEL)
ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1)
- LDFLAGS += -flto -fuse-linker-plugin
+ LDFLAGS += -flto -fuse-linker-plugin
endif
SIZEFLAGS ?= --mcu=$(MCU) -C
@@ -1308,7 +1323,24 @@ $(OBJDIR)/core/%.S.o: $(ARDUINO_CORE_PATH)/%.S $(COMMON_DEPS) | $(OBJDIR)
@$(MKDIR) $(dir $@)
$(CC) -MMD -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
+# alt core files
+$(OBJDIR)/core/%.c.o: $(ALTERNATE_CORE_PATH)/variants/$(VARIANT)/%.c $(COMMON_DEPS) | $(OBJDIR)
+ @$(MKDIR) $(dir $@)
+ $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@
+
+$(OBJDIR)/core/%.cpp.o: $(ALTERNATE_CORE_PATH)/variants/$(VARIANT)/%.cpp $(COMMON_DEPS) | $(OBJDIR)
+ @$(MKDIR) $(dir $@)
+ $(CXX) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
+
+$(OBJDIR)/core/%.S.o: $(ALTERNATE_CORE_PATH)/variants/$(VARIANT)/%.S $(COMMON_DEPS) | $(OBJDIR)
+ @$(MKDIR) $(dir $@)
+ $(CC) -MMD -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
+
# various object conversions
+$(OBJDIR)/%.bin: $(OBJDIR)/%.elf $(COMMON_DEPS)
+ @$(MKDIR) $(dir $@)
+ -$(OBJCOPY) -O binary $< $@
+
$(OBJDIR)/%.hex: $(OBJDIR)/%.elf $(COMMON_DEPS)
@$(MKDIR) $(dir $@)
$(OBJCOPY) -O ihex -R .eeprom $< $@
@@ -1448,12 +1480,21 @@ endif
# so we do not set it by default.
AVRDUDE_ISP_OPTS = -c $(ISP_PROG) -b $(AVRDUDE_ISP_BAUDRATE)
-ifndef $(ISP_PORT)
+ifndef ISP_PORT
ifneq ($(strip $(ISP_PROG)),$(filter $(ISP_PROG), atmelice_isp usbasp usbtiny gpio linuxgpio avrispmkii dragon_isp dragon_dw))
- AVRDUDE_ISP_OPTS += -P $(call get_isp_port)
+ # 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
- AVRDUDE_ISP_OPTS += -P $(call get_isp_port)
+ ifeq ($(CURRENT_OS), WINDOWS)
+ AVRDUDE_ISP_OPT += -P ISP_PORT
+ else
+ AVRDUDE_ISP_OPTS += -P $(call get_isp_port)
+ endif
endif
ifndef ISP_EEPROM
@@ -1471,7 +1512,7 @@ endif
########################################################################
# Explicit targets start here
-all: $(TARGET_EEP) $(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
@@ -1485,8 +1526,15 @@ $(OBJDIR): pre-build
pre-build:
$(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
+ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam)
+ $(CC) $(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) $(CORE_LIB) $(OTHER_OBJS) $(OTHER_LIBS) -lc -lm $(LINKER_SCRIPTS)
+endif
$(CORE_LIB): $(CORE_OBJS) $(LIB_OBJS) $(PLATFORM_LIB_OBJS) $(USER_LIB_OBJS)
$(AR) rcs $@ $(CORE_OBJS) $(LIB_OBJS) $(PLATFORM_LIB_OBJS) $(USER_LIB_OBJS)
@@ -1494,21 +1542,47 @@ $(CORE_LIB): $(CORE_OBJS) $(LIB_OBJS) $(PLATFORM_LIB_OBJS) $(USER_LIB_OBJS)
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
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
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
+
do_eeprom: $(TARGET_EEP) $(TARGET_HEX)
$(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \
$(AVRDUDE_UPLOAD_EEP)
@@ -1541,14 +1615,22 @@ ispload: $(TARGET_EEP) $(TARGET_HEX) verify_size
$(AVRDUDE_ISPLOAD_OPTS)
burn_bootloader:
-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)
+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:
@@ -1586,6 +1668,12 @@ else
$(MONITOR_CMD) $(call get_monitor_port) $(MONITOR_BAUDRATE)
endif
+debug_init:
+ $(OPENOCD)
+
+debug:
+ $(GDB) $(GDB_OPTS)
+
disasm: $(OBJDIR)/$(TARGET).lss
@$(ECHO) "The compiled ELF file has been disassembled to $(OBJDIR)/$(TARGET).lss\n\n"
@@ -1605,7 +1693,6 @@ generate_assembly: $(OBJDIR)/$(TARGET).s
generated_assembly: generate_assembly
@$(ECHO) "\"generated_assembly\" target is deprecated. Use \"generate_assembly\" target instead\n\n"
-.PHONY: tags
tags:
ifneq ($(words $(wildcard $(TAGS_FILE))), 0)
rm -f $(TAGS_FILE)
@@ -1640,6 +1727,8 @@ help:
make show_boards - list all the boards defined in boards.txt\n\
make show_submenu - list all board submenus defined in boards.txt\n\
make monitor - connect to the Arduino's serial port\n\
+ make debug_init - start openocd gdb server\n\
+ make debug - connect to gdb target and begin debugging\n\
make size - show the size of the compiled output (relative to\n\
resources, if you have a patched avr-size).\n\
make verify_size - verify that the size of the final file is less than\n\
@@ -1661,7 +1750,7 @@ help:
.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 \
- generate_assembly verify_size burn_bootloader help pre-build
+ generate_assembly verify_size burn_bootloader 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)