2012-02-28 10:06:56 +01:00
########################################################################
#
2013-05-31 06:12:44 +02:00
# Makefile for compiling Arduino sketches from command line
2012-02-28 10:06:56 +01:00
# System part (i.e. project independent)
#
2012-07-06 08:42:43 +02:00
# Copyright (C) 2012 Sudar <http://sudarmuthu.com>, based on
2014-02-04 13:24:46 +01:00
# M J Oldfield work: https://github.com/mjoldfield/Arduino-Makefile
2012-07-06 08:42:43 +02:00
#
2012-02-28 10:06:56 +01:00
# Copyright (C) 2010,2011,2012 Martin Oldfield <m@mjo.tc>, based on
# work that is copyright Nicholas Zambetti, David A. Mellis & Hernando
# Barragan.
2012-07-05 19:45:52 +02:00
#
2012-02-28 10:06:56 +01:00
# 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
# License, or (at your option) any later version.
#
# Adapted from Arduino 0011 Makefile by M J Oldfield
#
# Original Arduino adaptation by mellis, eighthave, oli.keller
#
2017-01-11 12:18:33 +01:00
# Current version: 1.5.2
2013-05-31 05:59:36 +02:00
#
# Refer to HISTORY.md file for complete history of changes
2012-11-17 22:18:56 +01:00
#
2012-07-14 08:51:54 +02:00
########################################################################
#
# PATHS YOU NEED TO SET UP
#
2016-06-18 20:59:18 +02:00
# We need to worry about three different sorts of files:
2012-07-14 08:51:54 +02:00
#
2014-01-13 13:14:31 +01:00
# 1. The directory where the *.mk files are stored
# => ARDMK_DIR
2012-07-14 08:51:54 +02:00
#
# 2. Things which are always in the Arduino distribution e.g.
2016-06-18 20:59:18 +02:00
# boards.txt, libraries, etc.
2012-07-14 08:51:54 +02:00
# => 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:
2016-06-18 20:59:18 +02:00
# on Linux it is supplied by the system.
2012-07-14 08:51:54 +02:00
# => 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.
#
2015-09-21 20:41:44 +02:00
# On the Mac with IDE 1.0 you might want to set:
2012-07-14 08:51:54 +02:00
#
# ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
# ARDMK_DIR = /usr/local
#
2015-09-21 20:41:44 +02:00
# On the Mac with IDE 1.5+ you might want to set:
#
# ARDUINO_DIR = /Applications/Arduino.app/Contents/Java
# ARDMK_DIR = /usr/local
#
2012-07-14 08:51:54 +02:00
# On Linux, you might prefer:
#
# ARDUINO_DIR = /usr/share/arduino
2014-02-04 13:24:46 +01:00
# ARDMK_DIR = /usr/share/arduino
2012-07-14 08:51:54 +02:00
# AVR_TOOLS_DIR = /usr
#
2014-04-11 15:13:42 +02:00
# On Windows declare this environmental variables using the windows
# configuration options. Control Panel > System > Advanced system settings
# Also take into account that when you set them you have to add '\' on
# all spaces and special characters.
# ARDUINO_DIR and AVR_TOOLS_DIR have to be relative and not absolute.
# This are just examples, you have to adapt this variables accordingly to
# your system.
#
# ARDUINO_DIR =../../../../../Arduino
# AVR_TOOLS_DIR =../../../../../Arduino/hardware/tools/avr
# ARDMK_DIR = /cygdrive/c/Users/"YourUser"/Arduino-Makefile
#
# On Windows it is highly recommended that you create a symbolic link directory
# for avoiding using the normal directories name of windows such as
# c:\Program Files (x86)\Arduino
# For this use the command mklink on the console.
#
#
2012-07-14 08:51:54 +02:00
# 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.
#
2012-11-01 16:33:46 +01:00
# If you'd rather not see the configuration output, define ARDUINO_QUIET.
#
2012-04-29 19:55:17 +02:00
########################################################################
#
# DEPENDENCIES
#
2016-06-18 20:59:18 +02:00
# to reset a board the (python) pySerial program is used.
# please install it prior to continue.
2012-04-27 00:11:25 +02:00
#
2012-02-28 10:06:56 +01:00
########################################################################
#
# STANDARD ARDUINO WORKFLOW
#
# Given a normal sketch directory, all you need to do is to create
# a small Makefile which defines a few things, and then includes this one.
#
# For example:
#
2013-06-22 08:18:26 +02:00
# ARDUINO_LIBS = Ethernet SPI
2012-02-28 10:06:56 +01:00
# BOARD_TAG = uno
2013-07-10 01:34:08 +02:00
# MONITOR_PORT = /dev/cu.usb*
2012-02-28 10:06:56 +01:00
#
2013-07-11 17:40:40 +02:00
# include /usr/share/arduino/Arduino.mk
2012-02-28 10:06:56 +01:00
#
# Hopefully these will be self-explanatory but in case they're not:
#
# ARDUINO_LIBS - A list of any libraries used by the sketch (we
2012-07-05 19:58:05 +02:00
# assume these are in $(ARDUINO_DIR)/hardware/libraries
# or your sketchbook's libraries directory)
2012-02-28 10:06:56 +01:00
#
2013-07-10 01:34:08 +02:00
# MONITOR_PORT - The port where the Arduino can be found (only needed
2012-07-05 19:57:32 +02:00
# when uploading)
2012-02-28 10:06:56 +01:00
#
2013-07-02 23:57:57 +02:00
# BOARD_TAG - The tag for the board e.g. uno or mega
2012-02-28 10:06:56 +01:00
# 'make show_boards' shows a list
#
2012-07-05 19:58:32 +02:00
# 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)
2014-01-13 13:14:31 +01:00
# include $(ARDMK_DIR)/Arduino.mk
2012-07-05 19:58:32 +02:00
#
# In any case, once this file has been created the typical workflow is just
2012-02-28 10:06:56 +01:00
#
# $ make upload
#
2013-06-12 09:17:34 +02:00
# All of the object files are created in the build-{BOARD_TAG} subdirectory
2012-02-28 10:06:56 +01:00
# All sources should be in the current directory and can include:
# - at most one .pde or .ino file which will be treated as C++ after
# the standard Arduino header and footer have been affixed.
# - any number of .c, .cpp, .s and .h files
#
2013-06-12 09:17:34 +02:00
# Included libraries are built in the build-{BOARD_TAG}/libs subdirectory.
2012-02-28 10:06:56 +01:00
#
2013-09-18 13:08:58 +02:00
# Besides make upload, there are a couple of other targets that are available.
# Do make help to get the complete list of targets and their description
2012-04-29 13:06:41 +02:00
#
########################################################################
#
# SERIAL MONITOR
#
# The serial monitor just invokes the GNU screen program with suitable
2012-07-05 19:45:52 +02:00
# options. For more information see screen (1) and search for
2012-04-29 13:06:41 +02:00
# 'character special device'.
#
# The really useful thing to know is that ^A-k gets you out!
#
# The fairly useful thing to know is that you can bind another key to
# escape too, by creating $HOME{.screenrc} containing e.g.
#
# bindkey ^C kill
#
# If you want to change the baudrate, just set MONITOR_BAUDRATE. If you
2012-08-19 08:36:40 +02:00
# don't set it, it tries to read from the sketch. If it couldn't read
2012-07-15 09:55:45 +02:00
# from the sketch, then it defaults to 9600 baud.
2012-02-28 10:06:56 +01:00
#
########################################################################
#
# ARDUINO WITH ISP
#
# You need to specify some details of your ISP programmer and might
# also need to specify the fuse values:
#
2013-06-12 09:17:34 +02:00
# ISP_PROG = stk500v2
2012-02-28 10:06:56 +01:00
# ISP_PORT = /dev/ttyACM0
#
# You might also need to set the fuse bits, but typically they'll be
# read from boards.txt, based on the BOARD_TAG variable:
2012-07-05 19:45:52 +02:00
#
2012-02-28 10:06:56 +01:00
# ISP_LOCK_FUSE_PRE = 0x3f
# ISP_LOCK_FUSE_POST = 0xcf
# ISP_HIGH_FUSE = 0xdf
# ISP_LOW_FUSE = 0xff
# ISP_EXT_FUSE = 0x01
#
2012-12-16 17:06:23 +01:00
# You can specify to also upload the EEPROM file:
# ISP_EEPROM = 1
#
2012-02-28 10:06:56 +01:00
# I think the fuses here are fine for uploading to the ATmega168
# without bootloader.
2012-07-05 19:45:52 +02:00
#
2012-02-28 10:06:56 +01:00
# To actually do this upload use the ispload target:
#
# make ispload
#
#
########################################################################
2013-08-18 19:55:37 +02:00
#
# ALTERNATIVE CORES
#
# To use alternative cores for platforms such as ATtiny, you need to
# specify a few more variables, depending on the core in use.
#
# The HLT (attiny-master) core can be used just by specifying
# ALTERNATE_CORE, assuming your core is in your ~/sketchbook/hardware
# directory. For example:
#
2014-02-04 13:24:46 +01:00
# ISP_PORT = /dev/ttyACM0
# BOARD_TAG = attiny85
# ALTERNATE_CORE = attiny-master
2013-08-18 19:55:37 +02:00
#
# To use the more complex arduino-tiny and TinyCore2 cores, you must
# also set ARDUINO_CORE_PATH and ARDUINO_VAR_PATH to the core
# directory, as these cores essentially replace the main Arduino core.
# For example:
#
# ISP_PORT = /dev/ttyACM0
# BOARD_TAG = attiny85at8
# ALTERNATE_CORE = arduino-tiny
# ARDUINO_VAR_PATH = ~/sketchbook/hardware/arduino-tiny/cores/tiny
# ARDUINO_CORE_PATH = ~/sketchbook/hardware/arduino-tiny/cores/tiny
#
# or....
#
# ISP_PORT = /dev/ttyACM0
# BOARD_TAG = attiny861at8
# ALTERNATE_CORE = tiny2
# ARDUINO_VAR_PATH = ~/sketchbook/hardware/tiny2/cores/tiny
# ARDUINO_CORE_PATH = ~/sketchbook/hardware/tiny2/cores/tiny
#
########################################################################
2012-07-05 20:58:54 +02:00
2013-05-30 16:09:05 +02:00
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
# regenerating the dependency file), then output the configuration.
2012-11-01 16:33:46 +01:00
i f n d e f A R D U I N O _ Q U I E T
2013-05-30 16:09:05 +02:00
ifeq ( $( MAKE_RESTARTS) ,)
ifeq ( $( MAKELEVEL) ,0)
arduino_output = $( info $( 1) )
endif
endif
2012-11-01 16:33:46 +01:00
e n d i f
2013-07-02 23:28:54 +02:00
########################################################################
# Makefile distribution path
2012-07-05 22:01:11 +02:00
2013-07-02 23:28:54 +02:00
i f n d e f A R D M K _ D I R
2014-01-13 13:14:31 +01:00
# presume it's the same path to our own file
ARDMK_DIR := $( realpath $( dir $( realpath $( lastword $( MAKEFILE_LIST) ) ) ) )
2013-06-29 13:19:38 +02:00
e l s e
2014-01-13 13:14:31 +01:00
# show_config_variable macro is defined in Common.mk file and is not available yet.
2013-07-26 15:17:46 +02:00
# Let's define a variable to know that user specified ARDMK_DIR
ARDMK_DIR_MSG = USER
2013-06-29 13:19:38 +02:00
e n d i f
2013-07-02 23:28:54 +02:00
2014-01-13 13:14:31 +01:00
# include Common.mk now we know where it is
i n c l u d e $( ARDMK_DIR ) / C o m m o n . m k
2013-06-29 13:19:38 +02:00
2013-07-26 15:17:46 +02:00
# show_config_variable macro is available now. So let's print config details for ARDMK_DIR
i f n d e f A R D M K _ D I R _ M S G
$( call show_config_variable,ARDMK_DIR,[ COMPUTED] ,( relative to $( notdir $( lastword $( MAKEFILE_LIST) ) ) ) )
e l s e
$( call show_config_variable,ARDMK_DIR,[ USER] )
e n d i f
2012-02-28 10:06:56 +01:00
########################################################################
2013-06-06 04:26:08 +02:00
# Default TARGET to pwd (ex Daniele Vergini)
2013-09-18 13:00:16 +02:00
2012-02-28 10:06:56 +01:00
i f n d e f T A R G E T
2015-09-06 13:14:19 +02:00
space :=
space +=
TARGET = $( notdir $( subst $( space) ,_,$( CURDIR) ) )
2012-02-28 10:06:56 +01:00
e n d i f
########################################################################
# Arduino version number
2013-09-18 13:00:16 +02:00
2012-02-28 10:06:56 +01:00
i f n d e f A R D U I N O _ V E R S I O N
2016-07-29 17:13:36 +02:00
# Remove all the decimals, remove anything before/including ":", remove anything after/including "+" and finally grab the last 5 bytes.
# Works for 1.0 and 1.0.1 and 1.6.10 and debian-style 2:1.0.5+dfsg2-4
2013-05-30 16:23:32 +02:00
VERSION_FILE := $( ARDUINO_DIR) /lib/version.txt
2016-07-29 17:13:36 +02:00
AUTO_ARDUINO_VERSION := $( shell [ -e $( VERSION_FILE) ] && cat $( VERSION_FILE) | sed -e 's/^[0-9]://g' -e 's/[.]//g' -e 's/\+.*//g' | head -c5)
2012-07-05 21:04:35 +02:00
ifdef AUTO_ARDUINO_VERSION
ARDUINO_VERSION = $( AUTO_ARDUINO_VERSION)
2012-07-05 22:01:11 +02:00
$( call show_config_variable,ARDUINO_VERSION,[ AUTODETECTED] )
2012-07-05 21:04:35 +02:00
else
ARDUINO_VERSION = 100
2012-07-05 22:01:11 +02:00
$( call show_config_variable,ARDUINO_VERSION,[ DEFAULT] )
2012-07-05 21:04:35 +02:00
endif
2012-07-05 19:29:33 +02:00
e l s e
2013-06-09 13:43:04 +02:00
$( call show_config_variable,ARDUINO_VERSION,[ USER] )
2012-02-28 10:06:56 +01:00
e n d i f
2014-06-01 18:14:38 +02:00
########################################################################
# 1.5.x architecture - avr or sam for arduino vendor
i f n d e f A R C H I T E C T U R E
ifeq ( $( shell expr $( ARDUINO_VERSION) '>' 150) , 1)
2014-10-12 19:32:55 +02:00
# default to avr for 1.5
ARCHITECTURE = avr
2014-10-11 23:14:32 +02:00
ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_AVR
2014-10-12 19:32:55 +02:00
else
# unset for 1.0
ARCHITECTURE =
endif
2014-06-01 18:14:38 +02:00
$( call show_config_variable,ARCHITECTURE,[ DEFAULT] )
e l s e
$( call show_config_variable,ARCHITECTURE,[ USER] )
2014-10-11 23:14:32 +02:00
#avoid using shell for known architectures
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
endif
2014-06-01 18:14:38 +02:00
e n d i f
########################################################################
# 1.5.x vendor - defaults to arduino
2015-09-15 01:00:30 +02:00
i f n d e f A R D M K _ V E N D O R
ARDMK_VENDOR = arduino
$( call show_config_variable,ARDMK_VENDOR,[ DEFAULT] )
2014-06-01 18:14:38 +02:00
e l s e
2015-09-15 01:00:30 +02:00
$( call show_config_variable,ARDMK_VENDOR,[ USER] )
2014-06-01 18:14:38 +02:00
e n d i f
2013-06-23 09:38:06 +02:00
########################################################################
# Arduino Sketchbook folder
2013-07-02 23:28:54 +02:00
2013-07-09 22:50:19 +02:00
i f n d e f A R D U I N O _ S K E T C H B O O K
ifndef ARDUINO_PREFERENCES_PATH
2015-03-27 17:57:45 +01:00
ifeq ( $( shell expr $( ARDUINO_VERSION) '>' 150) , 1)
AUTO_ARDUINO_PREFERENCES := $( firstword \
2015-03-28 13:18:38 +01:00
$( call dir_if_exists,$( HOME) /.arduino15/preferences.txt) \
2015-03-28 12:56:30 +01:00
$( call dir_if_exists,$( HOME) /Library/Arduino15/preferences.txt) )
2015-03-27 17:57:45 +01:00
else
AUTO_ARDUINO_PREFERENCES := $( firstword \
$( call dir_if_exists,$( HOME) /.arduino/preferences.txt) \
$( call dir_if_exists,$( HOME) /Library/Arduino/preferences.txt) )
endif
2013-06-23 09:38:06 +02:00
2013-07-09 22:50:19 +02:00
ifdef AUTO_ARDUINO_PREFERENCES
ARDUINO_PREFERENCES_PATH = $( AUTO_ARDUINO_PREFERENCES)
$( call show_config_variable,ARDUINO_PREFERENCES_PATH,[ AUTODETECTED] )
endif
2013-07-02 23:28:54 +02:00
2013-07-09 22:50:19 +02:00
else
$( call show_config_variable,ARDUINO_PREFERENCES_PATH,[ USER] )
2013-06-23 09:38:06 +02:00
endif
2013-07-09 22:50:19 +02:00
ifneq ( $( ARDUINO_PREFERENCES_PATH) ,)
2014-11-29 23:31:49 +01:00
ARDUINO_SKETCHBOOK := $( shell grep --max-count= 1 --regexp= 'sketchbook.path=' \
$( ARDUINO_PREFERENCES_PATH) | \
2013-07-09 22:50:19 +02:00
sed -e 's/sketchbook.path=//' )
endif
2013-07-02 23:28:54 +02:00
2013-06-23 09:38:06 +02:00
ifneq ( $( ARDUINO_SKETCHBOOK) ,)
$( call show_config_variable,ARDUINO_SKETCHBOOK,[ AUTODETECTED] ,( from arduino preferences file) )
else
2015-04-04 01:58:30 +02:00
ARDUINO_SKETCHBOOK := $( firstword \
$( call dir_if_exists,$( HOME) /sketchbook) \
$( call dir_if_exists,$( HOME) /Documents/Arduino) )
2013-06-23 09:38:06 +02:00
$( call show_config_variable,ARDUINO_SKETCHBOOK,[ DEFAULT] )
endif
e l s e
2013-12-17 10:15:33 +01:00
$( call show_config_variable,ARDUINO_SKETCHBOOK,[ USER] )
2013-06-23 09:38:06 +02:00
e n d i f
2012-04-29 19:55:17 +02:00
########################################################################
# Arduino and system paths
2013-07-02 23:28:54 +02:00
i f n d e f C C _ N A M E
CC_NAME = avr-gcc
e n d i f
i f n d e f C X X _ N A M E
CXX_NAME = avr-g++
e n d i f
i f n d e f O B J C O P Y _ N A M E
OBJCOPY_NAME = avr-objcopy
e n d i f
i f n d e f O B J D U M P _ N A M E
OBJDUMP_NAME = avr-objdump
e n d i f
i f n d e f S I Z E _ N A M E
SIZE_NAME = avr-size
e n d i f
i f n d e f N M _ N A M E
NM_NAME = avr-nm
e n d i f
2013-06-23 09:46:37 +02:00
i f n d e f A V R _ T O O L S _ D I R
2012-02-28 10:06:56 +01:00
2014-02-01 01:41:00 +01:00
BUNDLED_AVR_TOOLS_DIR := $( call dir_if_exists,$( ARDUINO_DIR) /hardware/tools/avr)
2014-01-22 17:50:24 +01:00
2013-06-23 09:46:37 +02:00
ifdef BUNDLED_AVR_TOOLS_DIR
AVR_TOOLS_DIR = $( BUNDLED_AVR_TOOLS_DIR)
2013-06-29 13:13:52 +02:00
$( call show_config_variable,AVR_TOOLS_DIR,[ BUNDLED] ,( in Arduino distribution) )
2013-06-29 18:10:36 +02:00
# In Linux distribution of Arduino, the path to avrdude and avrdude.conf are different
2013-07-02 23:28:54 +02:00
# More details at https://github.com/sudar/Arduino-Makefile/issues/48 and
2013-06-29 18:10:36 +02:00
# https://groups.google.com/a/arduino.cc/d/msg/developers/D_m97jGr8Xs/uQTt28KO_8oJ
ifeq ( $( CURRENT_OS) ,LINUX)
ifndef AVRDUDE
2014-12-03 23:38:50 +01:00
ifeq ( $( shell expr $( ARDUINO_VERSION) '>' 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
2013-06-29 18:10:36 +02:00
endif
ifndef AVRDUDE_CONF
2014-12-03 23:38:50 +01:00
ifeq ( $( shell expr $( ARDUINO_VERSION) '>' 157) , 1)
AVRDUDE_CONF = $( AVR_TOOLS_DIR) /etc/avrdude.conf
else
AVRDUDE_CONF = $( AVR_TOOLS_DIR) /../avrdude.conf
endif
2013-06-29 18:10:36 +02:00
endif
2013-07-02 23:28:54 +02:00
2013-06-29 18:10:36 +02:00
else
ifndef AVRDUDE_CONF
AVRDUDE_CONF = $( AVR_TOOLS_DIR) /etc/avrdude.conf
endif
endif
2013-06-23 09:46:37 +02:00
else
2012-06-29 01:32:23 +02:00
2013-07-02 23:28:54 +02:00
SYSTEMPATH_AVR_TOOLS_DIR := $( call dir_if_exists,$( abspath $( dir $( shell which $( CC_NAME) ) ) /..) )
2013-06-23 09:46:37 +02:00
ifdef SYSTEMPATH_AVR_TOOLS_DIR
2013-07-02 23:28:54 +02:00
AVR_TOOLS_DIR = $( SYSTEMPATH_AVR_TOOLS_DIR)
2013-06-23 09:46:37 +02:00
$( call show_config_variable,AVR_TOOLS_DIR,[ AUTODETECTED] ,( found in $$ PATH) )
2013-07-02 23:28:54 +02:00
else
echo $( error No AVR tools directory found)
2013-06-23 09:46:37 +02:00
endif # SYSTEMPATH_AVR_TOOLS_DIR
2012-02-28 10:06:56 +01:00
2013-06-23 09:46:37 +02:00
endif # BUNDLED_AVR_TOOLS_DIR
2012-06-29 01:32:23 +02:00
2013-06-23 09:46:37 +02:00
e l s e
$( call show_config_variable,AVR_TOOLS_DIR,[ USER] )
2014-04-11 15:13:42 +02:00
2015-09-13 10:49:53 +02:00
# ensure we can still find avrdude.conf
ifndef AVRDUDE_CONF
ifeq ( $( shell expr $( ARDUINO_VERSION) '>' 157) , 1)
AVRDUDE_CONF = $( AVR_TOOLS_DIR) /etc/avrdude.conf
else
AVRDUDE_CONF = $( AVR_TOOLS_DIR) /../avrdude.conf
2014-04-11 15:13:42 +02:00
endif
endif
2013-06-23 09:46:37 +02:00
e n d i f #ndef AVR_TOOLS_DIR
2012-02-28 10:06:56 +01:00
2013-06-29 18:10:36 +02:00
i f n d e f A V R _ T O O L S _ P A T H
AVR_TOOLS_PATH = $( AVR_TOOLS_DIR) /bin
e n d i f
2016-07-25 14:13:02 +02:00
i f n d e f A R D U I N O _ L I B _ P A T H
ARDUINO_LIB_PATH = $( ARDUINO_DIR) /libraries
$( call show_config_variable,ARDUINO_LIB_PATH,[ COMPUTED] ,( from ARDUINO_DIR) )
e l s e
$( call show_config_variable,ARDUINO_LIB_PATH,[ USER] )
e n d i f
2012-04-29 19:55:17 +02:00
2014-10-11 23:14:32 +02:00
# 1.5.x platform dependent libs path
i f n d e f A R D U I N O _ P L A T F O R M _ L I B _ P A T H
ifeq ( $( shell expr $( ARDUINO_VERSION) '>' 150) , 1)
2014-10-12 19:32:55 +02:00
# only for 1.5
2015-09-15 01:00:30 +02:00
ARDUINO_PLATFORM_LIB_PATH = $( ARDUINO_DIR) /hardware/$( ARDMK_VENDOR) /$( ARCHITECTURE) /libraries
2014-10-13 21:36:29 +02:00
$( call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[ COMPUTED] ,( from ARDUINO_DIR) )
2014-10-12 19:32:55 +02:00
endif
2014-10-11 23:14:32 +02:00
e l s e
$( call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[ USER] )
e n d i f
2013-06-23 09:46:37 +02:00
# Third party hardware and core like ATtiny or ATmega 16
i f d e f A L T E R N A T E _ C O R E
$( call show_config_variable,ALTERNATE_CORE,[ USER] )
2013-06-23 09:38:06 +02:00
2013-06-23 09:46:37 +02:00
ifndef ALTERNATE_CORE_PATH
2015-03-25 20:29:21 +01:00
ALTERNATE_CORE_PATH = $( ARDUINO_SKETCHBOOK) /hardware/$( ALTERNATE_CORE) /$( ARCHITECTURE)
2013-06-23 09:38:06 +02:00
endif
2013-06-23 09:46:37 +02:00
e n d i f
2013-06-23 09:38:06 +02:00
2013-06-23 09:46:37 +02:00
i f d e f A L T E R N A T E _ C O R E _ P A T H
2013-06-23 09:38:06 +02:00
2013-06-23 09:46:37 +02:00
ifdef ALTERNATE_CORE
$( call show_config_variable,ALTERNATE_CORE_PATH,[ COMPUTED] , ( from ARDUINO_SKETCHBOOK and ALTERNATE_CORE) )
else
$( call show_config_variable,ALTERNATE_CORE_PATH,[ USER] )
endif
2013-06-23 09:38:06 +02:00
2013-06-23 09:46:37 +02:00
ifndef ARDUINO_VAR_PATH
ARDUINO_VAR_PATH = $( ALTERNATE_CORE_PATH) /variants
$( call show_config_variable,ARDUINO_VAR_PATH,[ COMPUTED] ,( from ALTERNATE_CORE_PATH) )
endif
2013-06-23 09:38:06 +02:00
2013-06-23 09:46:37 +02:00
ifndef BOARDS_TXT
BOARDS_TXT = $( ALTERNATE_CORE_PATH) /boards.txt
$( call show_config_variable,BOARDS_TXT,[ COMPUTED] ,( from ALTERNATE_CORE_PATH) )
endif
2013-06-23 09:38:06 +02:00
2013-06-23 09:46:37 +02:00
e l s e
2013-06-23 09:38:06 +02:00
2013-06-23 09:46:37 +02:00
ifndef ARDUINO_VAR_PATH
2015-09-15 01:00:30 +02:00
ARDUINO_VAR_PATH = $( ARDUINO_DIR) /hardware/$( ARDMK_VENDOR) /$( ARCHITECTURE) /variants
2013-06-23 09:46:37 +02:00
$( call show_config_variable,ARDUINO_VAR_PATH,[ COMPUTED] ,( from ARDUINO_DIR) )
else
$( call show_config_variable,ARDUINO_VAR_PATH,[ USER] )
endif
2013-06-23 09:38:06 +02:00
2013-06-23 09:46:37 +02:00
ifndef BOARDS_TXT
2015-09-15 01:00:30 +02:00
BOARDS_TXT = $( ARDUINO_DIR) /hardware/$( ARDMK_VENDOR) /$( ARCHITECTURE) /boards.txt
2013-06-23 09:46:37 +02:00
$( call show_config_variable,BOARDS_TXT,[ COMPUTED] ,( from ARDUINO_DIR) )
else
$( call show_config_variable,BOARDS_TXT,[ USER] )
2013-06-02 18:03:42 +02:00
endif
2012-04-29 19:55:17 +02:00
2012-02-28 10:06:56 +01:00
e n d i f
2012-04-29 19:55:17 +02:00
########################################################################
2013-05-31 14:13:00 +02:00
# Miscellaneous
2013-09-18 13:00:16 +02:00
2012-03-26 05:54:21 +02:00
i f n d e f U S E R _ L I B _ P A T H
2012-07-05 21:04:35 +02:00
USER_LIB_PATH = $( ARDUINO_SKETCHBOOK) /libraries
2012-07-05 22:01:11 +02:00
$( call show_config_variable,USER_LIB_PATH,[ DEFAULT] ,( in user sketchbook) )
2012-07-05 20:58:54 +02:00
e l s e
2013-06-09 13:43:04 +02:00
$( call show_config_variable,USER_LIB_PATH,[ USER] )
2012-03-26 05:54:21 +02:00
e n d i f
2014-03-14 00:42:35 +01:00
i f n d e f P R E _ B U I L D _ H O O K
PRE_BUILD_HOOK = pre-build-hook.sh
$( call show_config_variable,PRE_BUILD_HOOK,[ DEFAULT] )
e l s e
$( call show_config_variable,PRE_BUILD_HOOK,[ USER] )
e n d i f
2012-02-28 10:06:56 +01:00
########################################################################
# boards.txt parsing
2013-09-18 13:00:16 +02:00
2014-06-01 18:14:38 +02:00
i f d e f B O A R D _ S U B
BOARD_SUB := $( strip $( BOARD_SUB) )
$( call show_config_variable,BOARD_SUB,[ USER] )
e n d i f
2012-02-28 10:06:56 +01:00
i f n d e f B O A R D _ T A G
2012-07-05 21:04:35 +02:00
BOARD_TAG = uno
2012-07-05 22:01:11 +02:00
$( call show_config_variable,BOARD_TAG,[ DEFAULT] )
2012-07-05 20:58:54 +02:00
e l s e
2013-06-15 12:02:27 +02:00
# Strip the board tag of any extra whitespace, since it was causing the makefile to fail
# https://github.com/sudar/Arduino-Makefile/issues/57
BOARD_TAG := $( strip $( BOARD_TAG) )
2013-06-09 13:43:04 +02:00
$( call show_config_variable,BOARD_TAG,[ USER] )
2012-02-28 10:06:56 +01:00
e n d i f
i f n d e f P A R S E _ B O A R D
2013-07-02 23:57:57 +02:00
# result = $(call READ_BOARD_TXT, 'boardname', 'parameter')
2016-10-11 20:59:35 +02:00
PARSE_BOARD = $( shell grep -Ev '^\#' $( BOARDS_TXT) | grep -E " ^[ \t]* $( 1) . $( 2) = " | cut -d = -f 2 | cut -d : -f 2)
2012-04-27 00:11:25 +02:00
e n d i f
2013-06-15 16:00:39 +02:00
# 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
i f e q ( $( strip $ ( NO_CORE ) ) , )
2012-02-28 10:06:56 +01:00
2014-12-28 23:24:51 +01:00
# 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
2016-10-11 20:59:35 +02:00
CORE = $( call PARSE_BOARD,$( BOARD_TAG) ,build.core)
2014-12-30 16:40:15 +01:00
$( call show_config_variable,CORE,[ COMPUTED] ,( from build.core) )
else
$( call show_config_variable,CORE,[ USER] )
2014-12-28 23:24:51 +01:00
endif
2013-06-15 16:00:39 +02:00
# Which variant ? This affects the include path
ifndef VARIANT
2016-06-22 10:55:43 +02:00
VARIANT := $( call PARSE_BOARD,$( BOARD_TAG) ,menu.( chip| cpu) .$( BOARD_SUB) .build.variant)
2015-03-28 17:10:06 +01:00
ifndef VARIANT
2015-04-12 20:46:58 +02:00
VARIANT := $( call PARSE_BOARD,$( BOARD_TAG) ,build.variant)
2015-03-28 17:10:06 +01:00
endif
$( call show_config_variable,VARIANT,[ COMPUTED] ,( from build.variant) )
else
$( call show_config_variable,VARIANT,[ USER] )
2013-06-15 16:00:39 +02:00
endif
2012-02-28 10:06:56 +01:00
2013-07-03 00:18:29 +02:00
# see if we are a caterina device like leonardo or micro
2016-06-22 10:55:43 +02:00
CATERINA := $( findstring caterina,$( call PARSE_BOARD,$( BOARD_TAG) ,menu.( chip| cpu) .$( BOARD_SUB) .bootloader.file) )
2014-06-01 18:14:38 +02:00
ifndef CATERINA
2015-04-12 20:46:58 +02:00
# 1.5+ method if not a submenu
2014-06-01 18:14:38 +02:00
CATERINA := $( findstring caterina,$( call PARSE_BOARD,$( BOARD_TAG) ,bootloader.file) )
endif
ifndef CATERINA
2015-04-12 20:46:58 +02:00
# 1.0 method uses deprecated bootloader.path
CATERINA := $( findstring caterina,$( call PARSE_BOARD,$( BOARD_TAG) ,bootloader.path) )
2014-06-01 18:14:38 +02:00
endif
2013-07-03 00:18:29 +02:00
2013-06-15 16:00:39 +02:00
# processor stuff
ifndef MCU
2016-06-22 10:55:43 +02:00
MCU := $( call PARSE_BOARD,$( BOARD_TAG) ,menu.( chip| cpu) .$( BOARD_SUB) .build.mcu)
2014-06-01 18:14:38 +02:00
ifndef MCU
2015-04-12 20:46:58 +02:00
MCU := $( call PARSE_BOARD,$( BOARD_TAG) ,build.mcu)
2014-06-01 18:14:38 +02:00
endif
2013-06-15 16:00:39 +02:00
endif
2012-02-28 10:06:56 +01:00
2013-06-15 16:00:39 +02:00
ifndef F_CPU
2016-06-22 10:55:43 +02:00
F_CPU := $( call PARSE_BOARD,$( BOARD_TAG) ,menu.( chip| cpu) .$( BOARD_SUB) .build.f_cpu)
2014-06-01 18:14:38 +02:00
ifndef F_CPU
2015-04-12 20:46:58 +02:00
F_CPU := $( call PARSE_BOARD,$( BOARD_TAG) ,build.f_cpu)
2014-06-01 18:14:38 +02:00
endif
2013-06-02 18:03:42 +02:00
endif
2012-09-17 18:06:48 +02:00
2013-07-03 00:18:29 +02:00
ifneq ( $( CATERINA) ,)
2013-07-09 18:40:46 +02:00
# USB IDs for the caterina devices like leonardo or micro
2013-06-15 16:00:39 +02:00
ifndef USB_VID
2013-07-02 23:57:57 +02:00
USB_VID = $( call PARSE_BOARD,$( BOARD_TAG) ,build.vid)
2013-06-15 16:00:39 +02:00
endif
2017-06-01 20:22:28 +02:00
# coping with 2-3 methods sparkfun use for usb.pid
2013-06-15 16:00:39 +02:00
ifndef USB_PID
2017-06-01 20:22:28 +02:00
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
2013-06-15 16:00:39 +02:00
endif
2013-06-02 18:03:42 +02:00
endif
2012-09-17 18:06:48 +02:00
2013-06-15 16:00:39 +02:00
# normal programming info
ifndef AVRDUDE_ARD_PROGRAMMER
2016-06-22 10:55:43 +02:00
AVRDUDE_ARD_PROGRAMMER := $( call PARSE_BOARD,$( BOARD_TAG) ,menu.( chip| cpu) .$( BOARD_SUB) .upload.protocol)
2014-06-01 18:14:38 +02:00
ifndef AVRDUDE_ARD_PROGRAMMER
2015-04-12 20:46:58 +02:00
AVRDUDE_ARD_PROGRAMMER := $( call PARSE_BOARD,$( BOARD_TAG) ,upload.protocol)
2014-06-01 18:14:38 +02:00
endif
2013-06-15 16:00:39 +02:00
endif
2012-02-28 10:06:56 +01:00
2013-06-15 16:00:39 +02:00
ifndef AVRDUDE_ARD_BAUDRATE
2016-06-22 10:55:43 +02:00
AVRDUDE_ARD_BAUDRATE := $( call PARSE_BOARD,$( BOARD_TAG) ,menu.( chip| cpu) .$( BOARD_SUB) .upload.speed)
2014-06-01 18:14:38 +02:00
ifndef AVRDUDE_ARD_BAUDRATE
2015-04-12 20:46:58 +02:00
AVRDUDE_ARD_BAUDRATE := $( call PARSE_BOARD,$( BOARD_TAG) ,upload.speed)
2014-06-01 18:14:38 +02:00
endif
2013-06-15 16:00:39 +02:00
endif
2012-02-28 10:06:56 +01:00
2013-06-15 16:00:39 +02:00
# fuses if you're using e.g. ISP
ifndef ISP_LOCK_FUSE_PRE
2013-07-02 23:57:57 +02:00
ISP_LOCK_FUSE_PRE = $( call PARSE_BOARD,$( BOARD_TAG) ,bootloader.unlock_bits)
2013-06-15 16:00:39 +02:00
endif
2012-02-28 10:06:56 +01:00
2013-06-15 16:00:39 +02:00
ifndef ISP_HIGH_FUSE
2016-06-22 10:55:43 +02:00
ISP_HIGH_FUSE := $( call PARSE_BOARD,$( BOARD_TAG) ,menu.( chip| cpu) .$( BOARD_SUB) .bootloader.high_fuses)
2014-06-01 18:14:38 +02:00
ifndef ISP_HIGH_FUSE
2015-04-12 20:46:58 +02:00
ISP_HIGH_FUSE := $( call PARSE_BOARD,$( BOARD_TAG) ,bootloader.high_fuses)
2014-06-01 18:14:38 +02:00
endif
2013-06-15 16:00:39 +02:00
endif
2012-02-28 10:06:56 +01:00
2013-06-15 16:00:39 +02:00
ifndef ISP_LOW_FUSE
2016-06-22 10:55:43 +02:00
ISP_LOW_FUSE := $( call PARSE_BOARD,$( BOARD_TAG) ,menu.( chip| cpu) .$( BOARD_SUB) .bootloader.low_fuses)
2014-06-01 18:14:38 +02:00
ifndef ISP_LOW_FUSE
2015-04-12 20:46:58 +02:00
ISP_LOW_FUSE := $( call PARSE_BOARD,$( BOARD_TAG) ,bootloader.low_fuses)
2014-06-01 18:14:38 +02:00
endif
2013-06-15 16:00:39 +02:00
endif
2012-02-28 10:06:56 +01:00
2013-06-15 16:00:39 +02:00
ifndef ISP_EXT_FUSE
2016-06-22 10:55:43 +02:00
ISP_EXT_FUSE := $( call PARSE_BOARD,$( BOARD_TAG) ,menu.( chip| cpu) .$( BOARD_SUB) .bootloader.extended_fuses)
2014-06-01 18:14:38 +02:00
ifndef ISP_EXT_FUSE
2015-04-12 20:46:58 +02:00
ISP_EXT_FUSE := $( call PARSE_BOARD,$( BOARD_TAG) ,bootloader.extended_fuses)
2014-06-01 18:14:38 +02:00
endif
2013-06-15 16:00:39 +02:00
endif
2013-10-06 15:40:29 +02:00
ifndef BOOTLOADER_PATH
BOOTLOADER_PATH = $( call PARSE_BOARD,$( BOARD_TAG) ,bootloader.path)
endif
ifndef BOOTLOADER_FILE
2016-06-22 10:55:43 +02:00
BOOTLOADER_FILE := $( call PARSE_BOARD,$( BOARD_TAG) ,menu.( chip| cpu) .$( BOARD_SUB) .bootloader.file)
2014-06-01 18:14:38 +02:00
ifndef BOOTLOADER_FILE
2015-04-12 20:46:58 +02:00
BOOTLOADER_FILE := $( call PARSE_BOARD,$( BOARD_TAG) ,bootloader.file)
2014-06-01 18:14:38 +02:00
endif
2013-10-06 15:40:29 +02:00
endif
2013-06-15 16:00:39 +02:00
ifndef ISP_LOCK_FUSE_POST
2013-07-02 23:57:57 +02:00
ISP_LOCK_FUSE_POST = $( call PARSE_BOARD,$( BOARD_TAG) ,bootloader.lock_bits)
2013-06-15 16:00:39 +02:00
endif
ifndef HEX_MAXIMUM_SIZE
2016-06-22 10:55:43 +02:00
HEX_MAXIMUM_SIZE := $( call PARSE_BOARD,$( BOARD_TAG) ,menu.( chip| cpu) .$( BOARD_SUB) .upload.maximum_size)
2014-06-01 18:14:38 +02:00
ifndef HEX_MAXIMUM_SIZE
2015-04-12 20:46:58 +02:00
HEX_MAXIMUM_SIZE := $( call PARSE_BOARD,$( BOARD_TAG) ,upload.maximum_size)
2014-06-01 18:14:38 +02:00
endif
2013-06-15 16:00:39 +02:00
endif
2012-02-28 10:06:56 +01:00
e n d i f
2012-09-17 17:29:31 +02:00
# Everything gets built in here (include BOARD_TAG now)
2012-09-17 17:25:21 +02:00
i f n d e f O B J D I R
2013-06-15 16:00:39 +02:00
OBJDIR = build-$( BOARD_TAG)
2015-03-27 00:17:05 +01:00
ifdef BOARD_SUB
OBJDIR = build-$( BOARD_TAG) -$( BOARD_SUB)
endif
2013-06-20 18:02:35 +02:00
$( call show_config_variable,OBJDIR,[ COMPUTED] ,( from BOARD_TAG) )
e l s e
$( call show_config_variable,OBJDIR,[ USER] )
2012-11-13 00:34:51 +01:00
e n d i f
2012-02-28 10:06:56 +01:00
2015-09-15 01:00:30 +02:00
# Now that we have ARDUINO_DIR, ARDMK_VENDOR, ARCHITECTURE and CORE,
2014-12-28 23:24:51 +01:00
# we can set ARDUINO_CORE_PATH.
i f n d e f A R D U I N O _ C O R E _ P A T H
ifeq ( $( strip $( CORE) ) ,)
2015-09-15 01:00:30 +02:00
ARDUINO_CORE_PATH = $( ARDUINO_DIR) /hardware/$( ARDMK_VENDOR) /$( ARCHITECTURE) /cores/arduino
2014-12-28 23:24:51 +01:00
$( call show_config_variable,ARDUINO_CORE_PATH,[ DEFAULT] )
else
ARDUINO_CORE_PATH = $( ALTERNATE_CORE_PATH) /cores/$( CORE)
ifeq ( $( wildcard $( ARDUINO_CORE_PATH) ) ,)
2015-09-15 01:00:30 +02:00
ARDUINO_CORE_PATH = $( ARDUINO_DIR) /hardware/$( ARDMK_VENDOR) /$( ARCHITECTURE) /cores/$( CORE)
2014-12-28 23:24:51 +01:00
$( 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
endif
e l s e
$( call show_config_variable,ARDUINO_CORE_PATH,[ USER] )
e n d i f
2013-07-03 09:29:34 +02:00
########################################################################
# Reset
2013-09-18 13:00:16 +02:00
2013-07-03 09:29:34 +02:00
i f n d e f R E S E T _ C M D
2014-01-28 15:27:49 +01:00
ARD_RESET_ARDUINO := $( shell which ard-reset-arduino 2> /dev/null)
2014-01-13 13:14:31 +01:00
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
2013-07-03 09:29:34 +02:00
ifneq ( $( CATERINA) ,)
2014-11-23 05:44:22 +01:00
ifneq ( ,$( findstring CYGWIN,$( shell uname -s) ) )
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
2013-07-03 09:29:34 +02:00
else
2014-11-23 05:44:22 +01:00
ifneq ( ,$( findstring CYGWIN,$( shell uname -s) ) )
RESET_CMD = $( ARD_RESET_ARDUINO) $( ARD_RESET_OPTS) $( DEVICE_PATH)
else
RESET_CMD = $( ARD_RESET_ARDUINO) $( ARD_RESET_OPTS) $( call get_monitor_port)
endif
2013-07-03 09:29:34 +02:00
endif
e n d i f
i f n e q ( $( CATERINA ) , )
2013-07-09 18:40:46 +02:00
ERROR_ON_CATERINA = $( error On $( BOARD_TAG) , raw_xxx operation is not supported)
2013-07-03 09:29:34 +02:00
e l s e
2013-07-09 18:40:46 +02:00
ERROR_ON_CATERINA =
2013-07-03 09:29:34 +02:00
e n d i f
2012-02-28 10:06:56 +01:00
########################################################################
# Local sources
2013-09-18 13:00:16 +02:00
2012-07-01 12:52:36 +02:00
LOCAL_C_SRCS ?= $( wildcard *.c)
LOCAL_CPP_SRCS ?= $( wildcard *.cpp)
LOCAL_CC_SRCS ?= $( wildcard *.cc)
LOCAL_PDE_SRCS ?= $( wildcard *.pde)
LOCAL_INO_SRCS ?= $( wildcard *.ino)
LOCAL_AS_SRCS ?= $( wildcard *.S)
2012-08-19 03:16:44 +02:00
LOCAL_SRCS = $( LOCAL_C_SRCS) $( LOCAL_CPP_SRCS) \
$( LOCAL_CC_SRCS) $( LOCAL_PDE_SRCS) \
$( LOCAL_INO_SRCS) $( LOCAL_AS_SRCS)
2015-07-09 18:05:28 +02:00
LOCAL_OBJ_FILES = $( LOCAL_C_SRCS:.c= .c.o) $( LOCAL_CPP_SRCS:.cpp= .cpp.o) \
$( LOCAL_CC_SRCS:.cc= .cc.o) $( LOCAL_PDE_SRCS:.pde= .pde.o) \
$( LOCAL_INO_SRCS:.ino= .ino.o) $( LOCAL_AS_SRCS:.S= .S.o)
2012-02-28 10:06:56 +01:00
LOCAL_OBJS = $( patsubst %,$( OBJDIR) /%,$( LOCAL_OBJ_FILES) )
2013-08-09 18:27:52 +02:00
i f e q ( $( words $ ( LOCAL_SRCS ) ) , 0 )
2014-05-21 01:14:46 +02:00
$( error At least one source file ( *.ino, *.pde, *.cpp, *c, *cc, *.S) is needed)
2013-08-09 18:27:52 +02:00
e n d i f
2013-06-15 16:00:39 +02:00
2014-06-05 22:56:17 +02:00
# CHK_SOURCES is used by flymake
# flymake creates a tmp file in the same directory as the file under edition
# we must skip the verification in this particular case
i f e q ( $( strip $ ( CHK_SOURCES ) ) , )
ifeq ( $( strip $( NO_CORE) ) ,)
# Ideally, this should just check if there are more than one file
ifneq ( $( words $( LOCAL_PDE_SRCS) $( LOCAL_INO_SRCS) ) , 1)
ifeq ( $( words $( LOCAL_PDE_SRCS) $( LOCAL_INO_SRCS) ) , 0)
$( 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)
endif
2013-08-09 18:27:52 +02:00
endif
2013-06-15 16:00:39 +02:00
2014-06-05 22:56:17 +02:00
endif
2013-05-30 13:14:20 +02:00
e n d i f
2012-02-28 10:06:56 +01:00
# core sources
i f e q ( $( strip $ ( NO_CORE ) ) , )
2012-07-05 21:04:35 +02:00
ifdef ARDUINO_CORE_PATH
CORE_C_SRCS = $( wildcard $( ARDUINO_CORE_PATH) /*.c)
2014-02-06 00:31:12 +01:00
CORE_C_SRCS += $( wildcard $( ARDUINO_CORE_PATH) /avr-libc/*.c)
2012-07-05 21:04:35 +02:00
CORE_CPP_SRCS = $( wildcard $( ARDUINO_CORE_PATH) /*.cpp)
2015-07-09 18:05:28 +02:00
CORE_AS_SRCS = $( wildcard $( ARDUINO_CORE_PATH) /*.S)
2012-07-05 21:04:35 +02:00
ifneq ( $( strip $( NO_CORE_MAIN_CPP) ) ,)
CORE_CPP_SRCS := $( filter-out %main.cpp, $( CORE_CPP_SRCS) )
2012-07-05 22:01:11 +02:00
$( call show_config_info,NO_CORE_MAIN_CPP set so core library will not include main.cpp,[ MANUAL] )
2012-07-05 21:04:35 +02:00
endif
2015-07-09 18:05:28 +02:00
CORE_OBJ_FILES = $( CORE_C_SRCS:.c= .c.o) $( CORE_CPP_SRCS:.cpp= .cpp.o) $( CORE_AS_SRCS:.S= .S.o)
2012-07-05 21:04:35 +02:00
CORE_OBJS = $( patsubst $( ARDUINO_CORE_PATH) /%, \
2014-06-30 09:03:15 +02:00
$( OBJDIR) /core/%,$( CORE_OBJ_FILES) )
2012-07-05 21:04:35 +02:00
endif
2012-07-05 20:58:54 +02:00
e l s e
2012-07-05 22:01:11 +02:00
$( call show_config_info,NO_CORE set so core library will not be built,[ MANUAL] )
2012-02-28 10:06:56 +01:00
e n d i f
2015-07-09 18:05:28 +02:00
2012-08-19 03:16:44 +02:00
########################################################################
# Determine ARDUINO_LIBS automatically
2013-09-18 13:00:16 +02:00
2012-08-19 03:16:44 +02:00
i f n d e f A R D U I N O _ L I B S
# automatically determine included libraries
ARDUINO_LIBS += $( filter $( notdir $( wildcard $( ARDUINO_DIR) /libraries/*) ) , \
2014-11-29 23:31:49 +01:00
$( shell sed -ne 's/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p' $( LOCAL_SRCS) ) )
2012-08-19 03:16:44 +02:00
ARDUINO_LIBS += $( filter $( notdir $( wildcard $( ARDUINO_SKETCHBOOK) /libraries/*) ) , \
2014-11-29 23:31:49 +01:00
$( shell sed -ne 's/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p' $( LOCAL_SRCS) ) )
2013-12-02 14:45:54 +01:00
ARDUINO_LIBS += $( filter $( notdir $( wildcard $( USER_LIB_PATH) /*) ) , \
2014-11-29 23:31:49 +01:00
$( shell sed -ne 's/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p' $( LOCAL_SRCS) ) )
2015-03-25 12:58:19 +01:00
ARDUINO_LIBS += $( filter $( notdir $( wildcard $( ARDUINO_PLATFORM_LIB_PATH) /*) ) , \
$( shell sed -ne 's/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p' $( LOCAL_SRCS) ) )
2012-08-19 03:16:44 +02:00
e n d i f
2012-02-28 10:06:56 +01:00
2013-05-30 12:55:10 +02:00
########################################################################
# Serial monitor (just a screen wrapper)
2013-09-18 13:00:16 +02:00
2013-05-30 12:55:10 +02:00
# 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').
2013-09-18 13:00:16 +02:00
2013-06-15 16:00:39 +02:00
i f e q ( $( strip $ ( NO_CORE ) ) , )
ifndef MONITOR_BAUDRATE
2013-08-09 18:06:22 +02:00
ifeq ( $( words $( LOCAL_PDE_SRCS) $( LOCAL_INO_SRCS) ) , 1)
2014-04-14 08:39:46 +02:00
SPEED = $( shell egrep -h 'Serial.begin *\([0-9]+\)' $( LOCAL_PDE_SRCS) $( LOCAL_INO_SRCS) | sed -e 's/[^0-9]//g' | head -n1)
2013-08-09 18:06:22 +02:00
MONITOR_BAUDRATE = $( findstring $( SPEED) ,300 1200 2400 4800 9600 14400 19200 28800 38400 57600 115200)
endif
2013-06-02 18:03:42 +02:00
2013-06-15 16:00:39 +02:00
ifeq ( $( MONITOR_BAUDRATE) ,)
MONITOR_BAUDRATE = 9600
$( call show_config_variable,MONITOR_BAUDRATE,[ ASSUMED] )
else
$( call show_config_variable,MONITOR_BAUDRATE,[ DETECTED] , ( in sketch) )
endif
2013-06-02 18:03:42 +02:00
else
2013-06-15 16:00:39 +02:00
$( call show_config_variable,MONITOR_BAUDRATE, [ USER] )
2013-06-02 18:03:42 +02:00
endif
2013-05-30 12:55:10 +02:00
2013-06-15 16:00:39 +02:00
ifndef MONITOR_CMD
MONITOR_CMD = screen
endif
2013-05-30 12:55:10 +02:00
e n d i f
2013-05-30 13:29:25 +02:00
########################################################################
2013-12-26 11:30:08 +01:00
# Include Arduino Header file
2013-09-18 13:00:16 +02:00
2013-05-31 14:13:00 +02:00
i f n d e f A R D U I N O _ H E A D E R
2013-12-26 11:30:08 +01:00
# We should check for Arduino version, not just the file extension
# because, a .pde file can be used in Arduino 1.0 as well
2013-06-02 18:03:42 +02:00
ifeq ( $( shell expr $( ARDUINO_VERSION) '<' 100) , 1)
ARDUINO_HEADER = WProgram.h
else
ARDUINO_HEADER = Arduino.h
endif
2013-05-30 13:29:25 +02:00
e n d i f
2012-02-28 10:06:56 +01:00
########################################################################
# Rules for making stuff
# The name of the main targets
TARGET_HEX = $( OBJDIR) /$( TARGET) .hex
TARGET_ELF = $( OBJDIR) /$( TARGET) .elf
2012-11-17 22:18:56 +01:00
TARGET_EEP = $( OBJDIR) /$( TARGET) .eep
2012-02-28 10:06:56 +01:00
CORE_LIB = $( OBJDIR) /libcore.a
2014-01-22 17:50:24 +01:00
# Names of executables - chipKIT needs to override all to set paths to PIC32
# tools, and we can't use "?=" assignment because these are already implicitly
# defined by Make (e.g. $(CC) == cc).
i f n d e f O V E R R I D E _ E X E C U T A B L E S
CC = $( AVR_TOOLS_PATH) /$( CC_NAME)
CXX = $( AVR_TOOLS_PATH) /$( CXX_NAME)
AS = $( AVR_TOOLS_PATH) /$( AS_NAME)
OBJCOPY = $( AVR_TOOLS_PATH) /$( OBJCOPY_NAME)
OBJDUMP = $( AVR_TOOLS_PATH) /$( OBJDUMP_NAME)
AR = $( AVR_TOOLS_PATH) /$( AR_NAME)
SIZE = $( AVR_TOOLS_PATH) /$( SIZE_NAME)
NM = $( AVR_TOOLS_PATH) /$( NM_NAME)
e n d i f
2013-09-19 12:50:30 +02:00
REMOVE = rm -rf
MV = mv -f
CAT = cat
2013-11-21 10:46:09 +01:00
ECHO = printf
2013-09-19 12:50:30 +02:00
MKDIR = mkdir -p
2012-02-28 10:06:56 +01:00
2014-10-11 23:14:32 +02:00
# recursive wildcard function, call with params:
# - start directory (finished with /) or empty string for current dir
# - glob pattern
# (taken from http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html)
rwildcard = $( foreach d,$( wildcard $1 *) ,$( call rwildcard,$d /,$2 ) $( filter $( subst *,%,$2 ) ,$d ) )
# functions used to determine various properties of library
# called with library path. Needed because of differences between library
# layouts in arduino 1.0.x and 1.5.x.
# Assuming new 1.5.x layout when there is "src" subdirectory in main directory
# and library.properties file
# Gets include flags for library
get_library_includes = $( if $( and $( wildcard $( 1) /src) , $( wildcard $( 1) /library.properties) ) , \
-I$( 1) /src, \
$( addprefix -I,$( 1) $( wildcard $( 1) /utility) ) )
# Gets all sources with given extension (param2) for library (path = param1)
# for old (1.0.x) layout looks in . and "utility" directories
# for new (1.5.x) layout looks in src and recursively its subdirectories
get_library_files = $( if $( and $( wildcard $( 1) /src) , $( wildcard $( 1) /library.properties) ) , \
$( call rwildcard,$( 1) /src/,*.$( 2) ) , \
$( wildcard $( 1) /*.$( 2) $( 1) /utility/*.$( 2) ) )
2012-02-28 10:06:56 +01:00
# General arguments
2015-03-25 12:58:19 +01:00
USER_LIBS := $( sort $( wildcard $( patsubst %,$( USER_LIB_PATH) /%,$( ARDUINO_LIBS) ) ) )
2014-11-11 00:19:00 +01:00
USER_LIB_NAMES := $( patsubst $( USER_LIB_PATH) /%,%,$( USER_LIBS) )
2012-07-05 22:02:24 +02:00
# Let user libraries override system ones.
2015-03-25 12:58:19 +01:00
SYS_LIBS := $( sort $( wildcard $( patsubst %,$( ARDUINO_LIB_PATH) /%,$( filter-out $( USER_LIB_NAMES) ,$( ARDUINO_LIBS) ) ) ) )
2014-11-11 00:19:00 +01:00
SYS_LIB_NAMES := $( patsubst $( ARDUINO_LIB_PATH) /%,%,$( SYS_LIBS) )
2012-07-05 22:02:24 +02:00
2014-10-11 23:14:32 +02:00
i f d e f A R D U I N O _ P L A T F O R M _ L I B _ P A T H
2015-03-25 12:58:19 +01:00
PLATFORM_LIBS := $( sort $( wildcard $( patsubst %,$( ARDUINO_PLATFORM_LIB_PATH) /%,$( filter-out $( USER_LIB_NAMES) ,$( ARDUINO_LIBS) ) ) ) )
2014-11-11 00:19:00 +01:00
PLATFORM_LIB_NAMES := $( patsubst $( ARDUINO_PLATFORM_LIB_PATH) /%,%,$( PLATFORM_LIBS) )
2014-10-11 23:14:32 +02:00
e n d i f
2012-07-05 22:02:24 +02:00
# Error here if any are missing.
2014-10-11 23:14:32 +02:00
LIBS_NOT_FOUND = $( filter-out $( USER_LIB_NAMES) $( SYS_LIB_NAMES) $( PLATFORM_LIB_NAMES) ,$( ARDUINO_LIBS) )
2012-07-05 22:02:24 +02:00
i f n e q ( , $( strip $ ( LIBS_NOT_FOUND ) ) )
2014-10-11 23:14:32 +02:00
ifdef ARDUINO_PLATFORM_LIB_PATH
$( error The following libraries specified in ARDUINO_LIBS could not be found ( searched USER_LIB_PATH, ARDUINO_LIB_PATH and ARDUINO_PLATFORM_LIB_PATH) : $( LIBS_NOT_FOUND) )
else
$( error The following libraries specified in ARDUINO_LIBS could not be found ( searched USER_LIB_PATH and ARDUINO_LIB_PATH) : $( LIBS_NOT_FOUND) )
endif
e n d i f
2014-11-11 00:19:00 +01:00
SYS_INCLUDES := $( foreach lib, $( SYS_LIBS) , $( call get_library_includes,$( lib) ) )
USER_INCLUDES := $( foreach lib, $( USER_LIBS) , $( call get_library_includes,$( lib) ) )
LIB_C_SRCS := $( foreach lib, $( SYS_LIBS) , $( call get_library_files,$( lib) ,c) )
LIB_CPP_SRCS := $( foreach lib, $( SYS_LIBS) , $( call get_library_files,$( lib) ,cpp) )
LIB_AS_SRCS := $( foreach lib, $( SYS_LIBS) , $( call get_library_files,$( lib) ,S) )
USER_LIB_CPP_SRCS := $( foreach lib, $( USER_LIBS) , $( call get_library_files,$( lib) ,cpp) )
USER_LIB_C_SRCS := $( foreach lib, $( USER_LIBS) , $( call get_library_files,$( lib) ,c) )
USER_LIB_AS_SRCS := $( foreach lib, $( USER_LIBS) , $( call get_library_files,$( lib) ,S) )
2015-07-09 18:05:28 +02:00
LIB_OBJS = $( patsubst $( ARDUINO_LIB_PATH) /%.c,$( OBJDIR) /libs/%.c.o,$( LIB_C_SRCS) ) \
$( patsubst $( ARDUINO_LIB_PATH) /%.cpp,$( OBJDIR) /libs/%.cpp.o,$( LIB_CPP_SRCS) ) \
$( patsubst $( ARDUINO_LIB_PATH) /%.S,$( OBJDIR) /libs/%.S.o,$( LIB_AS_SRCS) )
USER_LIB_OBJS = $( patsubst $( USER_LIB_PATH) /%.cpp,$( OBJDIR) /userlibs/%.cpp.o,$( USER_LIB_CPP_SRCS) ) \
$( patsubst $( USER_LIB_PATH) /%.c,$( OBJDIR) /userlibs/%.c.o,$( USER_LIB_C_SRCS) ) \
$( patsubst $( USER_LIB_PATH) /%.S,$( OBJDIR) /userlibs/%.S.o,$( USER_LIB_AS_SRCS) )
2012-02-28 10:06:56 +01:00
2014-10-11 23:14:32 +02:00
i f d e f A R D U I N O _ P L A T F O R M _ L I B _ P A T H
2014-11-11 00:19:00 +01:00
PLATFORM_INCLUDES := $( foreach lib, $( PLATFORM_LIBS) , $( call get_library_includes,$( lib) ) )
PLATFORM_LIB_CPP_SRCS := $( foreach lib, $( PLATFORM_LIBS) , $( call get_library_files,$( lib) ,cpp) )
PLATFORM_LIB_C_SRCS := $( foreach lib, $( PLATFORM_LIBS) , $( call get_library_files,$( lib) ,c) )
PLATFORM_LIB_AS_SRCS := $( foreach lib, $( PLATFORM_LIBS) , $( call get_library_files,$( lib) ,S) )
2015-07-09 18:05:28 +02:00
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) )
2014-10-11 23:14:32 +02:00
e n d i f
2013-02-20 17:30:44 +01:00
# Dependency files
2014-10-11 23:14:32 +02:00
DEPS = $( LOCAL_OBJS:.o= .d) $( LIB_OBJS:.o= .d) $( PLATFORM_OBJS:.o= .d) $( USER_LIB_OBJS:.o= .d) $( CORE_OBJS:.o= .d)
2013-02-20 17:30:44 +01:00
2013-06-20 18:26:54 +02:00
# Optimization level for the compiler.
# You can get the list of options at http://www.nongnu.org/avr-libc/user-manual/using_tools.html#gcc_optO
# Also read http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_optflags
i f n d e f O P T I M I Z A T I O N _ L E V E L
OPTIMIZATION_LEVEL = s
$( call show_config_variable,OPTIMIZATION_LEVEL,[ DEFAULT] )
e l s e
$( call show_config_variable,OPTIMIZATION_LEVEL,[ USER] )
e n d i f
2013-12-20 01:11:13 +01:00
i f n d e f D E B U G _ F L A G S
DEBUG_FLAGS = -O0 -g
e n d i f
# SoftwareSerial requires -Os (some delays are tuned for this optimization level)
2015-07-09 18:05:28 +02:00
%SoftwareSerial.cpp.o : OPTIMIZATION_FLAGS = -Os
2013-12-20 01:11:13 +01:00
2013-07-02 23:28:54 +02:00
i f n d e f M C U _ F L A G _ N A M E
MCU_FLAG_NAME = mmcu
$( call show_config_variable,MCU_FLAG_NAME,[ DEFAULT] )
e l s e
$( call show_config_variable,MCU_FLAG_NAME,[ USER] )
e n d i f
2012-06-09 07:29:02 +02:00
# Using += instead of =, so that CPPFLAGS can be set per sketch level
2014-10-11 23:14:32 +02:00
CPPFLAGS += -$( MCU_FLAG_NAME) = $( MCU) -DF_CPU= $( F_CPU) -DARDUINO= $( ARDUINO_VERSION) $( ARDUINO_ARCH_FLAG) -D__PROG_TYPES_COMPAT__ \
2017-06-19 02:42:34 +02:00
-I$( ARDUINO_CORE_PATH) -I$( ARDUINO_SKETCHBOOK) -I$( ARDUINO_VAR_PATH) /$( VARIANT) \
2014-10-11 23:14:32 +02:00
$( SYS_INCLUDES) $( PLATFORM_INCLUDES) $( USER_INCLUDES) -Wall -ffunction-sections \
2013-07-03 00:07:23 +02:00
-fdata-sections
i f d e f D E B U G
2013-12-20 01:11:13 +01:00
OPTIMIZATION_FLAGS = $( DEBUG_FLAGS)
2013-07-03 00:07:23 +02:00
e l s e
2013-12-20 01:11:13 +01:00
OPTIMIZATION_FLAGS = -O$( OPTIMIZATION_LEVEL)
2013-07-03 00:07:23 +02:00
e n d i f
2013-05-31 13:35:47 +02:00
2013-12-20 01:11:13 +01:00
CPPFLAGS += $( OPTIMIZATION_FLAGS)
2013-07-09 18:40:46 +02:00
# USB IDs for the Caterina devices like leonardo or micro
2013-07-03 00:18:29 +02:00
i f n e q ( $( CATERINA ) , )
2013-06-02 18:03:42 +02:00
CPPFLAGS += -DUSB_VID= $( USB_VID) -DUSB_PID= $( USB_PID)
2013-05-31 13:35:47 +02:00
e n d i f
2016-09-08 15:49:36 +02:00
# avr-gcc version that we can do maths on
CC_VERNUM = $( shell $( CC) -dumpversion | sed 's/\.//g' )
# moved from above so we can find version-dependant ar
i f n d e f A R _ N A M E
2016-10-11 16:23:36 +02:00
ifeq ( $( shell expr $( CC_VERNUM) '>' 490) , 1)
2016-09-08 15:49:36 +02:00
AR_NAME = avr-gcc-ar
else
AR_NAME = avr-ar
endif
e n d i f
2013-07-02 23:28:54 +02:00
i f n d e f C F L A G S _ S T D
2016-10-11 16:23:36 +02:00
ifeq ( $( shell expr $( CC_VERNUM) '>' 490) , 1)
2016-09-08 15:49:36 +02:00
CFLAGS_STD = -std= gnu11 -flto -fno-fat-lto-objects
else
CFLAGS_STD =
endif
2013-07-02 23:28:54 +02:00
$( call show_config_variable,CFLAGS_STD,[ DEFAULT] )
e l s e
$( call show_config_variable,CFLAGS_STD,[ USER] )
e n d i f
2014-08-13 11:16:16 +02:00
i f n d e f C X X F L A G S _ S T D
2016-10-11 16:23:36 +02:00
ifeq ( $( shell expr $( CC_VERNUM) '>' 490) , 1)
2016-09-08 15:49:36 +02:00
CXXFLAGS_STD = -std= gnu++11 -fno-threadsafe-statics -flto
2016-07-25 14:13:02 +02:00
else
CXXFLAGS_STD =
endif
2014-08-13 11:16:16 +02:00
$( call show_config_variable,CXXFLAGS_STD,[ DEFAULT] )
e l s e
$( call show_config_variable,CXXFLAGS_STD,[ USER] )
e n d i f
CFLAGS += $( CFLAGS_STD)
2016-09-08 15:49:36 +02:00
CXXFLAGS += -fpermissive -fno-exceptions $( CXXFLAGS_STD)
2013-12-03 17:24:19 +01:00
ASFLAGS += -x assembler-with-cpp
2016-10-11 16:23:36 +02:00
i f e q ( $( shell expr $ ( CC_VERNUM ) '>' 490) , 1 )
2016-09-08 15:49:36 +02:00
ASFLAGS += -flto
e n d i f
2014-08-13 11:16:16 +02:00
LDFLAGS += -$( MCU_FLAG_NAME) = $( MCU) -Wl,--gc-sections -O$( OPTIMIZATION_LEVEL)
2016-10-11 16:23:36 +02:00
i f e q ( $( shell expr $ ( CC_VERNUM ) '>' 490) , 1 )
2016-09-08 15:49:36 +02:00
LDFLAGS += -flto -fuse-linker-plugin
e n d i f
2012-07-01 13:04:39 +02:00
SIZEFLAGS ?= --mcu= $( MCU) -C
2012-02-28 10:06:56 +01:00
2013-07-10 01:34:08 +02:00
# for backwards compatibility, grab ARDUINO_PORT if the user has it set
2014-06-21 12:32:34 +02:00
# instead of MONITOR_PORT
2013-07-10 01:34:08 +02:00
MONITOR_PORT ?= $( ARDUINO_PORT)
2014-06-21 12:32:34 +02:00
i f n e q ( $( strip $ ( MONITOR_PORT ) ) , )
2014-11-23 05:44:22 +01:00
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
2014-06-21 12:32:34 +02:00
$( call show_config_variable,DEVICE_PATH,[ COMPUTED] ,( from MONITOR_PORT) )
2014-05-03 02:36:42 +02:00
e l s e
# If no port is specified, try to guess it from wildcards.
2014-06-21 12:32:34 +02:00
# Will only work if the Arduino is the only/first device matched.
2014-05-03 02:36:42 +02:00
DEVICE_PATH = $( firstword $( wildcard \
2015-06-11 19:58:49 +02:00
/dev/ttyACM? /dev/ttyUSB? /dev/tty.usbserial* /dev/tty.usbmodem* /dev/tty.wchusbserial*) )
2014-06-21 12:32:34 +02:00
$( call show_config_variable,DEVICE_PATH,[ AUTODETECTED] )
2014-01-22 17:54:32 +01:00
e n d i f
2014-12-29 18:34:45 +01:00
i f n d e f F O R C E _ M O N I T O R _ P O R T
$( call show_config_variable,FORCE_MONITOR_PORT,[ DEFAULT] )
e l s e
$( call show_config_variable,FORCE_MONITOR_PORT,[ USER] )
e n d i f
2014-12-28 22:13:56 +01:00
i f d e f F O R C E _ M O N I T O R _ P O R T
# Skips the DEVICE_PATH existance check.
get_monitor_port = $( DEVICE_PATH)
2014-11-23 05:44:22 +01:00
e l s e
2014-12-28 22:13:56 +01:00
# 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
2014-11-23 05:44:22 +01:00
e n d i f
2012-02-28 10:06:56 +01:00
2013-06-09 13:48:12 +02:00
# Returns the ISP port (first wildcard expansion) if it exists, otherwise it errors.
2014-03-14 19:40:18 +01:00
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!) ) )
2013-06-09 13:48:12 +02:00
2012-07-05 22:01:11 +02:00
# Command for avr_size: do $(call avr_size,elffile,hexfile)
i f n e q ( , $( 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.
2012-07-13 19:06:54 +02:00
avr_size = $( SIZE) $( SIZEFLAGS) --format= avr $( 1)
2012-07-05 22:01:11 +02:00
$( call show_config_info,Size utility: AVR-aware for enhanced output,[ AUTODETECTED] )
2012-07-05 19:45:05 +02:00
e l s e
2012-07-05 21:04:35 +02:00
# We have a plain-old binutils version - just give it the hex.
avr_size = $( SIZE) $( 2)
2012-07-05 22:01:11 +02:00
$( call show_config_info,Size utility: Basic ( not AVR-aware) ,[ AUTODETECTED] )
2012-07-05 19:45:05 +02:00
e n d i f
2012-07-05 22:01:11 +02:00
i f n e q ( , $( strip $ ( ARDUINO_LIBS ) ) )
2012-11-01 16:33:46 +01:00
$( call arduino_output,-)
2012-07-05 22:01:11 +02:00
$( call show_config_info,ARDUINO_LIBS = )
e n d i f
2013-05-31 14:13:00 +02:00
2012-07-05 22:01:11 +02:00
i f n e q ( , $( strip $ ( USER_LIB_NAMES ) ) )
$( foreach lib,$( USER_LIB_NAMES) ,$( call show_config_info, $( lib) ,[ USER] ) )
2012-07-05 20:58:54 +02:00
e n d i f
2015-03-25 12:58:19 +01:00
i f n e q ( , $( strip $ ( SYS_LIB_NAMES ) ) )
2012-07-05 22:01:11 +02:00
$( foreach lib,$( SYS_LIB_NAMES) ,$( call show_config_info, $( lib) ,[ SYSTEM] ) )
2012-07-05 20:58:54 +02:00
e n d i f
2015-03-25 12:58:19 +01:00
i f n e q ( , $( strip $ ( PLATFORM_LIB_NAMES ) ) )
$( foreach lib,$( PLATFORM_LIB_NAMES) ,$( call show_config_info, $( lib) ,[ PLATFORM] ) )
e n d i f
2013-12-17 10:15:33 +01:00
# either calculate parent dir from arduino dir, or user-defined path
i f n d e f B O O T L O A D E R _ P A R E N T
2015-09-15 01:00:30 +02:00
BOOTLOADER_PARENT = $( ARDUINO_DIR) /hardware/$( ARDMK_VENDOR) /$( ARCHITECTURE) /bootloaders
2013-12-17 10:15:33 +01:00
$( call show_config_variable,BOOTLOADER_PARENT,[ COMPUTED] ,( from ARDUINO_DIR) )
e l s e
$( call show_config_variable,BOOTLOADER_PARENT,[ USER] )
e n d i f
2014-09-21 19:23:06 +02:00
########################################################################
# Tools version info
2015-04-07 18:07:12 +02:00
ARDMK_VERSION = 1.5
2014-09-21 19:23:06 +02:00
$( call show_config_variable ,ARDMK_VERSION ,[COMPUTED ])
2014-11-11 00:19:00 +01:00
CC_VERSION := $( shell $( CC) -dumpversion)
2014-09-21 19:23:06 +02:00
$( call show_config_variable ,CC_VERSION ,[COMPUTED ],( $ ( CC_NAME ) ) )
2012-07-05 20:58:54 +02:00
# end of config output
$( call show_separator )
2012-02-28 10:06:56 +01:00
# Implicit rules for building everything (needed to get everything in
# the right directory)
#
# Rather than mess around with VPATH there are quasi-duplicate rules
# here for building e.g. a system C++ file and a local C++
# file. Besides making things simpler now, this would also make it
# easy to change the build options in future
# library sources
2015-07-09 18:05:28 +02:00
$(OBJDIR)/libs/%.c.o : $( ARDUINO_LIB_PATH ) /%.c
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2013-02-20 17:30:44 +01:00
$( CC) -MMD -c $( CPPFLAGS) $( CFLAGS) $< -o $@
2012-02-28 10:06:56 +01:00
2015-07-09 18:05:28 +02:00
$(OBJDIR)/libs/%.cpp.o : $( ARDUINO_LIB_PATH ) /%.cpp
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2014-11-05 16:09:43 +01:00
$( CXX) -MMD -c $( CPPFLAGS) $( CXXFLAGS) $< -o $@
2012-02-28 10:06:56 +01:00
2015-07-09 18:05:28 +02:00
$(OBJDIR)/libs/%.S.o : $( ARDUINO_LIB_PATH ) /%.S
2014-04-25 08:53:50 +02:00
@$( MKDIR) $( dir $@ )
$( CC) -MMD -c $( CPPFLAGS) $( ASFLAGS) $< -o $@
2015-07-09 18:05:28 +02:00
$(OBJDIR)/platformlibs/%.c.o : $( ARDUINO_PLATFORM_LIB_PATH ) /%.c
2014-10-11 23:14:32 +02:00
@$( MKDIR) $( dir $@ )
$( CC) -MMD -c $( CPPFLAGS) $( CFLAGS) $< -o $@
2015-07-09 18:05:28 +02:00
$(OBJDIR)/platformlibs/%.cpp.o : $( ARDUINO_PLATFORM_LIB_PATH ) /%.cpp
2014-10-11 23:14:32 +02:00
@$( MKDIR) $( dir $@ )
2014-11-05 16:09:43 +01:00
$( CXX) -MMD -c $( CPPFLAGS) $( CXXFLAGS) $< -o $@
2014-10-11 23:14:32 +02:00
2015-07-09 18:05:28 +02:00
$(OBJDIR)/platformlibs/%.S.o : $( ARDUINO_PLATFORM_LIB_PATH ) /%.S
2014-10-11 23:14:32 +02:00
@$( MKDIR) $( dir $@ )
$( CC) -MMD -c $( CPPFLAGS) $( ASFLAGS) $< -o $@
2015-07-09 18:05:28 +02:00
$(OBJDIR)/userlibs/%.cpp.o : $( USER_LIB_PATH ) /%.cpp
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2014-11-05 16:09:43 +01:00
$( CXX) -MMD -c $( CPPFLAGS) $( CXXFLAGS) $< -o $@
2012-03-26 05:54:21 +02:00
2015-07-09 18:05:28 +02:00
$(OBJDIR)/userlibs/%.c.o : $( USER_LIB_PATH ) /%.c
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2013-02-20 17:30:44 +01:00
$( CC) -MMD -c $( CPPFLAGS) $( CFLAGS) $< -o $@
2012-03-26 05:54:21 +02:00
2015-07-09 18:05:28 +02:00
$(OBJDIR)/userlibs/%.S.o : $( USER_LIB_PATH ) /%.S
2014-04-25 08:53:50 +02:00
@$( MKDIR) $( dir $@ )
$( CC) -MMD -c $( CPPFLAGS) $( ASFLAGS) $< -o $@
2013-01-31 22:14:07 +01:00
i f d e f C O M M O N _ D E P S
2013-11-22 02:53:36 +01:00
COMMON_DEPS := $( COMMON_DEPS) $( MAKEFILE_LIST)
2013-01-31 22:14:07 +01:00
e l s e
2013-11-22 02:53:36 +01:00
COMMON_DEPS := $( MAKEFILE_LIST)
2013-01-31 22:14:07 +01:00
e n d i f
2012-02-28 10:06:56 +01:00
# normal local sources
2015-07-09 18:05:28 +02:00
$(OBJDIR)/%.c.o : %.c $( COMMON_DEPS ) | $( OBJDIR )
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2012-07-05 05:30:47 +02:00
$( CC) -MMD -c $( CPPFLAGS) $( CFLAGS) $< -o $@
2012-02-28 10:06:56 +01:00
2015-07-09 18:05:28 +02:00
$(OBJDIR)/%.cc.o : %.cc $( COMMON_DEPS ) | $( OBJDIR )
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2012-07-05 05:30:47 +02:00
$( CXX) -MMD -c $( CPPFLAGS) $( CXXFLAGS) $< -o $@
2012-02-28 10:06:56 +01:00
2015-07-09 18:05:28 +02:00
$(OBJDIR)/%.cpp.o : %.cpp $( COMMON_DEPS ) | $( OBJDIR )
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2012-07-05 05:30:47 +02:00
$( CXX) -MMD -c $( CPPFLAGS) $( CXXFLAGS) $< -o $@
2012-02-28 10:06:56 +01:00
2015-07-09 18:05:28 +02:00
$(OBJDIR)/%.S.o : %.S $( COMMON_DEPS ) | $( OBJDIR )
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2012-07-05 05:30:47 +02:00
$( CC) -MMD -c $( CPPFLAGS) $( ASFLAGS) $< -o $@
2012-02-28 10:06:56 +01:00
2015-07-09 18:05:28 +02:00
$(OBJDIR)/%.s.o : %.s $( COMMON_DEPS ) | $( OBJDIR )
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2012-02-28 10:06:56 +01:00
$( CC) -c $( CPPFLAGS) $( ASFLAGS) $< -o $@
2013-05-30 13:35:37 +02:00
# the pde -> o file
2015-07-09 18:05:28 +02:00
$(OBJDIR)/%.pde.o : %.pde $( COMMON_DEPS ) | $( OBJDIR )
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2013-05-31 14:13:00 +02:00
$( CXX) -x c++ -include $( ARDUINO_HEADER) -MMD -c $( CPPFLAGS) $( CXXFLAGS) $< -o $@
2012-02-28 10:06:56 +01:00
2013-05-30 13:35:37 +02:00
# the ino -> o file
2015-07-09 18:05:28 +02:00
$(OBJDIR)/%.ino.o : %.ino $( COMMON_DEPS ) | $( OBJDIR )
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2013-12-26 11:30:08 +01:00
$( CXX) -x c++ -include $( ARDUINO_HEADER) -MMD -c $( CPPFLAGS) $( CXXFLAGS) $< -o $@
2012-02-28 10:06:56 +01:00
2012-09-20 18:30:46 +02:00
# generated assembly
2013-06-19 23:41:01 +02:00
$(OBJDIR)/%.s : %.pde $( COMMON_DEPS ) | $( OBJDIR )
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2013-06-19 23:41:01 +02:00
$( CXX) -x c++ -include $( ARDUINO_HEADER) -MMD -S -fverbose-asm $( CPPFLAGS) $( CXXFLAGS) $< -o $@
$(OBJDIR)/%.s : %.ino $( COMMON_DEPS ) | $( OBJDIR )
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2013-12-26 11:30:08 +01:00
$( CXX) -x c++ -include $( ARDUINO_HEADER) -MMD -S -fverbose-asm $( CPPFLAGS) $( CXXFLAGS) $< -o $@
2012-09-20 18:30:46 +02:00
2014-08-22 17:57:30 +02:00
$(OBJDIR)/%.s : %.cpp $( COMMON_DEPS ) | $( OBJDIR )
@$( MKDIR) $( dir $@ )
2017-01-21 12:22:45 +01:00
$( CXX) -x c++ -MMD -S -fverbose-asm $( CPPFLAGS) $( CXXFLAGS) $< -o $@
2012-09-20 18:30:46 +02:00
2012-02-28 10:06:56 +01:00
# core files
2015-07-09 18:05:28 +02:00
$(OBJDIR)/core/%.c.o : $( ARDUINO_CORE_PATH ) /%.c $( COMMON_DEPS ) | $( OBJDIR )
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2013-02-20 17:30:44 +01:00
$( CC) -MMD -c $( CPPFLAGS) $( CFLAGS) $< -o $@
2012-02-28 10:06:56 +01:00
2015-07-09 18:05:28 +02:00
$(OBJDIR)/core/%.cpp.o : $( ARDUINO_CORE_PATH ) /%.cpp $( COMMON_DEPS ) | $( OBJDIR )
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2013-02-20 17:30:44 +01:00
$( CXX) -MMD -c $( CPPFLAGS) $( CXXFLAGS) $< -o $@
2012-02-28 10:06:56 +01:00
2015-07-09 18:05:28 +02:00
$(OBJDIR)/core/%.S.o : $( ARDUINO_CORE_PATH ) /%.S $( COMMON_DEPS ) | $( OBJDIR )
2013-12-03 17:24:19 +01:00
@$( MKDIR) $( dir $@ )
$( CC) -MMD -c $( CPPFLAGS) $( ASFLAGS) $< -o $@
2012-02-28 10:06:56 +01:00
# various object conversions
2012-11-01 16:34:09 +01:00
$(OBJDIR)/%.hex : $( OBJDIR ) /%.elf $( COMMON_DEPS )
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2012-02-28 10:06:56 +01:00
$( OBJCOPY) -O ihex -R .eeprom $< $@
2013-11-21 10:46:09 +01:00
@$( ECHO) '\n'
2012-07-05 19:45:19 +02:00
$( call avr_size,$<,$@ )
2013-07-01 18:24:56 +02:00
i f n e q ( $( strip $ ( HEX_MAXIMUM_SIZE ) ) , )
@if [ ` $( SIZE) $@ | awk 'FNR == 2 {print $$2}' ` -le $( HEX_MAXIMUM_SIZE) ] ; then touch $@ .sizeok; fi
e l s e
2013-11-21 10:46:09 +01:00
@$( ECHO) " Maximum flash memory of $( BOARD_TAG) is not specified. Make sure the size of $@ is less than $( BOARD_TAG) \'s flash memory "
2013-07-01 18:24:56 +02:00
@touch $@ .sizeok
e n d i f
2012-02-28 10:06:56 +01:00
2012-11-01 16:34:09 +01:00
$(OBJDIR)/%.eep : $( OBJDIR ) /%.elf $( COMMON_DEPS )
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2014-10-12 10:04:57 +02:00
-$( OBJCOPY) -j .eeprom --set-section-flags= .eeprom= 'alloc,load' \
2016-11-04 19:21:02 +01:00
--no-change-warnings --change-section-lma .eeprom= 0 -O ihex $< $@
2012-02-28 10:06:56 +01:00
2012-11-01 16:34:09 +01:00
$(OBJDIR)/%.lss : $( OBJDIR ) /%.elf $( COMMON_DEPS )
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2012-08-23 19:39:42 +02:00
$( OBJDUMP) -h --source --demangle --wide $< > $@
2012-02-28 10:06:56 +01:00
2012-11-01 16:34:09 +01:00
$(OBJDIR)/%.sym : $( OBJDIR ) /%.elf $( COMMON_DEPS )
2013-07-12 14:37:31 +02:00
@$( MKDIR) $( dir $@ )
2012-09-20 18:29:36 +02:00
$( NM) --size-sort --demangle --reverse-sort --line-numbers $< > $@
2012-02-28 10:06:56 +01:00
########################################################################
# Avrdude
2013-09-18 13:00:16 +02:00
2013-06-29 18:10:36 +02:00
# If avrdude is installed separately, it can find its own config file
2012-02-28 10:06:56 +01:00
i f n d e f A V R D U D E
2012-07-05 21:04:35 +02:00
AVRDUDE = $( AVR_TOOLS_PATH) /avrdude
2012-02-28 10:06:56 +01:00
e n d i f
2013-09-25 11:48:14 +02:00
# Default avrdude options
# -V Do not verify
# -q - suppress progress output
2013-06-15 15:47:13 +02:00
i f n d e f A V R D U D E _ O P T S
2014-11-07 23:59:30 +01:00
AVRDUDE_OPTS = -q -V
2013-06-15 15:47:13 +02:00
e n d i f
2015-06-01 23:58:58 +02:00
# Decouple the mcu between the compiler options (-mmcu) and the avrdude options (-p).
# This is needed to be able to compile for attiny84a but specify the upload mcu as attiny84.
# We default to picking the -mmcu flag, but you can override this by setting
# AVRDUDE_MCU in your makefile.
i f n d e f A V R D U D E _ M C U
AVRDUDE_MCU = $( MCU)
e n d i f
AVRDUDE_COM_OPTS = $( AVRDUDE_OPTS) -p $( AVRDUDE_MCU)
2012-02-28 10:06:56 +01:00
i f d e f A V R D U D E _ C O N F
2012-07-05 21:04:35 +02:00
AVRDUDE_COM_OPTS += -C $( AVRDUDE_CONF)
2012-02-28 10:06:56 +01:00
e n d i f
2014-11-07 23:59:30 +01:00
# -D - Disable auto erase for flash memory
2015-06-01 23:58:58 +02:00
# Note: -D is needed for Mega boards.
# (See https://github.com/sudar/Arduino-Makefile/issues/114#issuecomment-25011005)
2014-11-07 23:59:30 +01:00
AVRDUDE_ARD_OPTS = -D -c $( AVRDUDE_ARD_PROGRAMMER) -b $( AVRDUDE_ARD_BAUDRATE) -P
2014-01-22 17:54:32 +01:00
i f e q ( $( CURRENT_OS ) , W I N D O W S )
# 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)
e l s e
AVRDUDE_ARD_OPTS += $( call get_monitor_port)
e n d i f
2012-02-28 10:06:56 +01:00
i f n d e f I S P _ P R O G
2013-10-06 14:44:58 +02:00
ifneq ( $( strip $( AVRDUDE_ARD_PROGRAMMER) ) ,)
ISP_PROG = $( AVRDUDE_ARD_PROGRAMMER)
else
ISP_PROG = stk500v1
endif
2012-02-28 10:06:56 +01:00
e n d i f
2013-06-09 13:48:12 +02:00
i f n d e f A V R D U D E _ I S P _ B A U D R A T E
2013-10-06 14:44:58 +02:00
ifneq ( $( strip $( AVRDUDE_ARD_BAUDRATE) ) ,)
AVRDUDE_ISP_BAUDRATE = $( AVRDUDE_ARD_BAUDRATE)
else
AVRDUDE_ISP_BAUDRATE = 19200
endif
2012-11-17 22:18:56 +01:00
e n d i f
2013-10-06 15:40:29 +02:00
# Fuse settings copied from Arduino IDE.
# https://github.com/arduino/Arduino/blob/master/app/src/processing/app/debug/AvrdudeUploader.java#L254
2013-06-15 15:53:26 +02:00
# Pre fuse settings
i f n d e f A V R D U D E _ I S P _ F U S E S _ P R E
ifneq ( $( strip $( ISP_LOCK_FUSE_PRE) ) ,)
AVRDUDE_ISP_FUSES_PRE += -U lock:w:$( ISP_LOCK_FUSE_PRE) :m
endif
2013-10-06 15:40:29 +02:00
ifneq ( $( strip $( ISP_EXT_FUSE) ) ,)
AVRDUDE_ISP_FUSES_PRE += -U efuse:w:$( ISP_EXT_FUSE) :m
endif
2013-06-15 15:53:26 +02:00
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
2013-10-06 15:40:29 +02:00
e n d i f
2013-06-15 15:53:26 +02:00
2013-10-06 15:40:29 +02:00
# Bootloader file settings
i f n d e f A V R D U D E _ I S P _ B U R N _ B O O T L O A D E R
2015-12-28 11:05:53 +01:00
ifneq ( $( strip $( BOOTLOADER_FILE) ) ,)
AVRDUDE_ISP_BURN_BOOTLOADER += -U flash:w:$( BOOTLOADER_PARENT) /$( BOOTLOADER_PATH) /$( BOOTLOADER_FILE) :i
2013-06-15 15:53:26 +02:00
endif
e n d i f
# Post fuse settings
i f n d e f A V R D U D E _ I S P _ F U S E S _ P O S T
ifneq ( $( strip $( ISP_LOCK_FUSE_POST) ) ,)
AVRDUDE_ISP_FUSES_POST += -U lock:w:$( ISP_LOCK_FUSE_POST) :m
endif
e n d i f
2015-06-01 23:58:58 +02:00
# 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.
2013-10-05 04:49:58 +02:00
AVRDUDE_ISP_OPTS = -c $( ISP_PROG) -b $( AVRDUDE_ISP_BAUDRATE)
2014-03-14 19:40:18 +01:00
i f n d e f $( ISP_PORT )
2015-07-14 08:19:52 +02:00
ifneq ( $( strip $( ISP_PROG) ) ,$( filter $( ISP_PROG) , usbasp usbtiny gpio linuxgpio avrispmkii dragon_isp dragon_dw) )
2014-03-14 19:40:18 +01:00
AVRDUDE_ISP_OPTS += -P $( call get_isp_port)
endif
e l s e
AVRDUDE_ISP_OPTS += -P $( call get_isp_port)
2013-10-05 04:49:58 +02:00
e n d i f
2012-02-28 10:06:56 +01:00
2012-11-17 22:18:56 +01:00
i f n d e f I S P _ E E P R O M
2013-06-02 18:03:42 +02:00
ISP_EEPROM = 0
2012-11-17 22:18:56 +01:00
e n d i f
2012-12-16 17:06:23 +01:00
AVRDUDE_UPLOAD_HEX = -U flash:w:$( TARGET_HEX) :i
AVRDUDE_UPLOAD_EEP = -U eeprom:w:$( TARGET_EEP) :i
AVRDUDE_ISPLOAD_OPTS = $( AVRDUDE_UPLOAD_HEX)
2013-06-02 18:03:42 +02:00
2012-11-17 22:18:56 +01:00
i f n e q ( $( ISP_EEPROM ) , 0 )
2013-06-02 18:03:42 +02:00
AVRDUDE_ISPLOAD_OPTS += $( AVRDUDE_UPLOAD_EEP)
2012-11-17 22:18:56 +01:00
e n d i f
2012-02-28 10:06:56 +01:00
########################################################################
# Explicit targets start here
2013-07-01 18:24:56 +02:00
all : $( TARGET_EEP ) $( TARGET_HEX )
2012-02-28 10:06:56 +01:00
2013-06-06 04:26:08 +02:00
# Rule to create $(OBJDIR) automatically. All rules with recipes that
2013-05-30 19:44:39 +02:00
# create a file within it, but do not already depend on a file within it
# should depend on this rule. They should use a "order-only
2013-06-06 04:26:08 +02:00
# prerequisite" (e.g., put "| $(OBJDIR)" at the end of the prerequisite
# list) to prevent remaking the target when any file in the directory
2013-05-30 19:44:39 +02:00
# changes.
2014-03-14 00:42:35 +01:00
$(OBJDIR) : pre -build
2013-06-15 11:59:49 +02:00
$( MKDIR) $( OBJDIR)
2012-02-28 10:06:56 +01:00
2014-03-14 00:42:35 +01:00
pre-build :
$( call runscript_if_exists,$( PRE_BUILD_HOOK) )
2012-02-28 10:06:56 +01:00
$(TARGET_ELF) : $( LOCAL_OBJS ) $( CORE_LIB ) $( OTHER_OBJS )
2016-11-04 19:21:02 +01:00
$( CC) $( LDFLAGS) -o $@ $( LOCAL_OBJS) $( CORE_LIB) $( OTHER_OBJS) $( OTHER_LIBS) -lc -lm $( LINKER_SCRIPTS)
2012-02-28 10:06:56 +01:00
2014-10-11 23:14:32 +02:00
$(CORE_LIB) : $( CORE_OBJS ) $( LIB_OBJS ) $( PLATFORM_LIB_OBJS ) $( USER_LIB_OBJS )
$( AR) rcs $@ $( CORE_OBJS) $( LIB_OBJS) $( PLATFORM_LIB_OBJS) $( USER_LIB_OBJS)
2012-02-28 10:06:56 +01:00
2013-07-09 18:40:46 +02:00
error_on_caterina :
$( ERROR_ON_CATERINA)
2013-06-08 13:56:24 +02:00
2014-03-14 00:42:35 +01:00
2013-06-08 13:02:43 +02:00
# Use submake so we can guarantee the reset happens
# before the upload, even with make -j
2013-05-30 15:01:07 +02:00
upload : $( TARGET_HEX ) verify_size
$( MAKE) reset
$( MAKE) do_upload
2012-02-28 10:06:56 +01:00
2013-05-30 15:01:07 +02:00
raw_upload : $( TARGET_HEX ) verify_size
2013-07-09 18:40:46 +02:00
$( MAKE) error_on_caterina
2013-05-30 15:01:07 +02:00
$( MAKE) do_upload
do_upload :
2012-02-28 10:06:56 +01:00
$( AVRDUDE) $( AVRDUDE_COM_OPTS) $( AVRDUDE_ARD_OPTS) \
2012-12-16 17:06:23 +01:00
$( AVRDUDE_UPLOAD_HEX)
2012-02-28 10:06:56 +01:00
2013-06-08 13:56:24 +02:00
do_eeprom : $( TARGET_EEP ) $( TARGET_HEX )
2012-12-16 17:06:23 +01:00
$( AVRDUDE) $( AVRDUDE_COM_OPTS) $( AVRDUDE_ARD_OPTS) \
$( AVRDUDE_UPLOAD_EEP)
2012-11-17 22:18:56 +01:00
2013-06-08 13:56:24 +02:00
eeprom : $( TARGET_HEX ) verify_size
$( MAKE) reset
$( MAKE) do_eeprom
raw_eeprom : $( TARGET_HEX ) verify_size
2013-07-09 18:40:46 +02:00
$( MAKE) error_on_caterina
2013-06-08 13:56:24 +02:00
$( MAKE) do_eeprom
2012-07-05 19:45:52 +02:00
reset :
2013-06-08 13:56:24 +02:00
$( call arduino_output,Resetting Arduino...)
$( RESET_CMD)
2012-04-29 19:55:17 +02:00
2012-02-28 10:06:56 +01:00
# 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 ?
2012-07-05 19:45:52 +02:00
reset_stty :
2012-02-28 10:06:56 +01:00
for STTYF in 'stty -F' 'stty --file' 'stty -f' 'stty <' ; \
2013-06-13 09:38:27 +02:00
do $$ STTYF /dev/tty >/dev/null 2>& 1 && break ; \
done ; \
2013-07-10 01:34:08 +02:00
$$ STTYF $( call get_monitor_port) hupcl ; \
2013-06-13 09:38:27 +02:00
( sleep 0.1 2>/dev/null || sleep 1) ; \
2013-07-10 01:34:08 +02:00
$$ STTYF $( call get_monitor_port) -hupcl
2012-02-28 10:06:56 +01:00
2012-12-16 17:06:23 +01:00
ispload : $( TARGET_EEP ) $( TARGET_HEX ) verify_size
2012-02-28 10:06:56 +01:00
$( AVRDUDE) $( AVRDUDE_COM_OPTS) $( AVRDUDE_ISP_OPTS) \
2013-06-15 15:53:26 +02:00
$( AVRDUDE_ISPLOAD_OPTS)
2013-10-06 15:40:29 +02:00
burn_bootloader :
i f n e q ( $( strip $ ( AVRDUDE_ISP_FUSES_PRE ) ) , )
$( AVRDUDE) $( AVRDUDE_COM_OPTS) $( AVRDUDE_ISP_OPTS) -e $( AVRDUDE_ISP_FUSES_PRE)
e n d i f
i f n e q ( $( strip $ ( AVRDUDE_ISP_BURN_BOOTLOADER ) ) , )
$( AVRDUDE) $( AVRDUDE_COM_OPTS) $( AVRDUDE_ISP_OPTS) $( AVRDUDE_ISP_BURN_BOOTLOADER)
e n d i f
i f n e q ( $( strip $ ( AVRDUDE_ISP_FUSES_POST ) ) , )
2013-06-15 15:53:26 +02:00
$( AVRDUDE) $( AVRDUDE_COM_OPTS) $( AVRDUDE_ISP_OPTS) $( AVRDUDE_ISP_FUSES_POST)
e n d i f
2012-02-28 10:06:56 +01:00
2013-12-15 22:10:58 +01:00
set_fuses :
i f n e q ( $( strip $ ( AVRDUDE_ISP_FUSES_PRE ) ) , )
$( AVRDUDE) $( AVRDUDE_COM_OPTS) $( AVRDUDE_ISP_OPTS) -e $( AVRDUDE_ISP_FUSES_PRE)
e n d i f
i f n e q ( $( strip $ ( AVRDUDE_ISP_FUSES_POST ) ) , )
$( AVRDUDE) $( AVRDUDE_COM_OPTS) $( AVRDUDE_ISP_OPTS) $( AVRDUDE_ISP_FUSES_POST)
e n d i f
2014-08-16 19:31:07 +02:00
clean ::
2014-07-14 12:30:31 +02:00
$( REMOVE) $( OBJDIR)
2012-02-28 10:06:56 +01:00
2013-09-18 13:00:16 +02:00
size : $( TARGET_HEX )
2012-07-05 19:45:05 +02:00
$( call avr_size,$( TARGET_ELF) ,$( TARGET_HEX) )
2012-02-28 10:06:56 +01:00
2012-07-05 19:45:52 +02:00
show_boards :
2015-12-16 19:27:31 +01:00
@$( CAT) $( BOARDS_TXT) | grep -E '^[a-zA-Z0-9_\-]+.name' | sort -uf | sed 's/.name=/:/' | column -s: -t
2012-02-28 10:06:56 +01:00
2016-02-19 23:01:15 +01:00
show_submenu :
2017-03-13 14:38:52 +01:00
@$( 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
2016-02-19 23:01:15 +01:00
2012-04-29 13:06:41 +02:00
monitor :
2015-06-11 19:56:06 +02:00
i f e q ( $( MONITOR_CMD ) , 'putty' )
2017-03-12 22:30:29 +01:00
ifneq ( $( strip $( MONITOR_PARAMS) ) ,)
$( MONITOR_CMD) -serial -sercfg $( MONITOR_BAUDRATE) ,$( MONITOR_PARAMS) $( call get_monitor_port)
2015-06-11 19:56:06 +02:00
else
$( MONITOR_CMD) -serial -sercfg $( MONITOR_BAUDRATE) $( call get_monitor_port)
endif
e l s e i f e q ( $( MONITOR_CMD ) , p i c o c o m )
$( MONITOR_CMD) -b $( MONITOR_BAUDRATE) $( MONITOR_PARAMS) $( call get_monitor_port)
2017-04-02 00:06:28 +02:00
e l s e i f e q ( $( MONITOR_CMD ) , c u )
$( MONITOR_CMD) -l $( call get_monitor_port) -s $( MONITOR_BAUDRATE)
2014-11-23 11:38:38 +01:00
e l s e
2015-06-11 19:56:06 +02:00
$( MONITOR_CMD) $( call get_monitor_port) $( MONITOR_BAUDRATE)
2014-11-23 11:38:38 +01:00
e n d i f
2012-04-29 13:06:41 +02:00
2012-09-20 18:29:26 +02:00
disasm : $( OBJDIR ) /$( TARGET ) .lss
2014-05-27 12:25:23 +02:00
@$( ECHO) " The compiled ELF file has been disassembled to $( OBJDIR) / $( TARGET) .lss\n\n "
2012-07-03 19:36:00 +02:00
2012-09-20 18:30:46 +02:00
symbol_sizes : $( OBJDIR ) /$( TARGET ) .sym
2014-05-27 12:25:23 +02:00
@$( ECHO) " A symbol listing sorted by their size have been dumped to $( OBJDIR) / $( TARGET) .sym\n\n "
2012-04-29 13:06:41 +02:00
2013-07-01 18:24:56 +02:00
verify_size :
i f e q ( $( strip $ ( HEX_MAXIMUM_SIZE ) ) , )
2013-11-21 10:46:09 +01:00
@$( ECHO) " \nMaximum flash memory of $( BOARD_TAG) is not specified. Make sure the size of $( TARGET_HEX) is less than $( BOARD_TAG) \'s flash memory\n\n "
2013-06-15 12:04:10 +02:00
e n d i f
2013-07-01 18:24:56 +02:00
@if [ ! -f $( TARGET_HEX) .sizeok ] ; then echo >& 2 " \nThe size of the compiled binary file is greater than the $( BOARD_TAG) 's flash memory. \
See http : //www .arduino .cc /en /Guide /Troubleshooting #size for tips on reducing it."; false; fi
2012-04-29 13:06:41 +02:00
2013-06-20 09:21:56 +02:00
generate_assembly : $( OBJDIR ) /$( TARGET ) .s
2014-05-27 12:25:23 +02:00
@$( ECHO) " Compiler-generated assembly for the main input source has been dumped to $( OBJDIR) / $( TARGET) .s\n\n "
2012-07-03 19:36:00 +02:00
2013-06-20 09:21:56 +02:00
generated_assembly : generate_assembly
2014-05-27 12:25:23 +02:00
@$( ECHO) "\"generated_assembly\" target is deprecated. Use \"generate_assembly\" target instead\n\n"
2013-06-25 15:29:49 +02:00
2014-02-04 13:57:46 +01:00
help_vars :
2014-11-29 23:31:49 +01:00
@$( CAT) $( ARDMK_DIR) /arduino-mk-vars.md
2014-02-04 13:57:46 +01:00
2013-09-15 09:00:22 +02:00
help :
2013-09-18 13:00:16 +02:00
@$( ECHO) " \nAvailable targets:\n\
2014-05-27 12:25:23 +02:00
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 \
make clean - remove all our dependencies\n \
make depends - update dependencies\n \
make reset - reset the Arduino by tickling DTR or changing baud\n \
rate on the serial port.\n \
make show_boards - list all the boards defined in boards.txt\n \
2016-02-19 23:01:15 +01:00
make show_submenu - list all board submenus defined in boards.txt\n \
2014-05-27 12:25:23 +02:00
make monitor - connect to the Arduino' s serial port\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 \
the capacity of the micro controller.\n \
make symbol_sizes - generate a .sym file containing symbols and their\n \
sizes.\n \
make disasm - generate a .lss file that contains disassembly\n \
of the compiled file interspersed with your\n \
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 help_vars - print all variables that can be overridden\n \
make help - show this help\n \
2013-09-15 09:00:22 +02:00
"
2014-01-13 13:14:31 +01:00
@$( ECHO) " Please refer to $( ARDMK_DIR) /Arduino.mk for more details.\n "
2013-09-15 09:00:22 +02:00
.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 \
2014-03-14 00:42:35 +01:00
generate_assembly verify_size burn_bootloader help pre-build
2012-02-28 10:06:56 +01:00
2012-05-05 12:33:40 +02:00
# added - in the beginning, so that we don't get an error if the file is not present
2012-07-05 05:30:47 +02:00
- i n c l u d e $( DEPS )