build Arduino sketches with
The file bsd.arduino.mk
is used to build
Arduino sketches from the command line using
The goal is to efficiently build potentially complicated projects with simple
Makefiles and completely bypass the Arduino graphical user interface.
Modules that are part of the standard Arduino distribution along with modules
that are part of referenced Arduino libraries (specified with the
variable) are compiled once and
stored in a library. Sketch modules are built as determined by
- Dump out the defines specific to
- Compile, link and run
to program the target board.
- An alias for flash.
on all of the source files.
- Create a build directory.
- Create a symlink to the build directory.
to report the fuse settings.
to list section sizes and total size.
- Create or update a tags file by running
on SRCS and
These variables must be set:
- The name of the sketch. If SRCS is not
defined then the sketch is built from
- The name of the board. This is important as the
arduino-boards script uses it to set
the defaults for ARDUINO_CORE,
MCU from the Arduino
- The path to the arduino-bsd-mk installation directory.
It's frequently useful to set these variables:
- A list of .ino, .cpp and .c sources. This is used when the name of the
module does not match TARGET and when
more than one source is used.
- A list of Arduino libraries. Since these are searched by first looking in
.CURDIR and then in the Arduino tree
possible to use local libraries and to override standard Arduino
programmer port when the programmer is "arduino". This is passed
programmer id string. The default this is set using
When AVRDUDE_PROGRAMMER is
"arduino" AVRDUDE_PORT must be
set using one of these methods:
When AVRDUDE_PROGRAMMER is one that uses
USB, AVRDUDE_PORT can optionally specify
the usb port. See the
- In your shell environment before running "make flash"
- With the make command line, e.g. "make flash
- In Makefile.inc, e.g. "AVRDUDE_PORT=/dev/ttyU3"
-P option in the
man page for more details.
programmer speed when the programmer is "arduino". This is
passed with the
These options for these variables default those found in the Arduino
file by the
- This is the location of the core to link sketches against when
- This is the variant of
- The the clock speed at which the microcontroller operates at. This is
useful when under or overclocking.
- The microcontroller on the board.
- Top level of Arduino installation. This defaults to
- Additional compile C flags.
- Top level of the avr-libc installation. This defaults to
flags to be used with "make lint"
- Specify include files that should also be processed by
for "make tags".
- When set, "make lint" runs
with XML output enabled using the
- When set, make lint" runs
It's important to do a "make clean" if
or any other
options are changed.
To allow use of the
flag, standard and local Arduino
library modules are compiled using the
flag which inhibits warning messages. This makes it possible to add the
(which is recommended).
- The Arduino boards database.
- The Arduino version file.
- The location of standard Arduino libraries.
- The default location of bsd.arduino.mk
and the scripts directory.
- Script used to parse boards.txt to
determine various hardware related options.
- Script used to parse version.txt
- Script used to determine the version of
- The default top level of the avr-libc installation.
Here's a sample Makefile:
ARDUINO_CFLAGS+= -Wall -Werror -Wstrict-prototypes
There is one source named blink2.ino
. The board is a atmega328.
Additional compiler flags are specified.
was inspired by a
makefile originally written by Martin Oldfield and described in his blog
titled, "Arduino from the command line."