Makefile for Arduino sketches. It defines the workflows for compiling code, flashing it to Arduino and even communicating through Serial. http://hardwarefun.com/tutorials/compiling-arduino-sketches-using-makefile
Find a file
Paul Brook 4fdd1765e6 Rewrite dependency code
Commit originally by: Paul Brook <paul@codesourcery.com>
Port to newer version and commit message by: Matthijs Kooijman <matthijs@stdin.nl>

Instead of generating a big list of dependencies at the start, now
dependency files are generated whenever a .o file is compiled. This
works, since if the .o file does not exist, it should be compiled and
make does not need to know about its dependencies. If the .o (and thus
the .d) file does exist, the .d file contains all the dependencies used
to compile the .o file. If none of those changed, the .o file does not
need a recompile, but also the .d file is still accurate (in particular,
the dependency list cannot change without one of the dependent .h files
or the .cpp file itself changing).

This helps to remove a lot of duplication in the code, since now only a
single commandline is needed for both compilation and dependency
generation. It will probably also run a bit faster now.

Note that this commit breaks the creation of $(OBJDIR) since this
"accidentally" always worked before because $(DEPFILE) was created
before anything else. That will be fixed next.
2013-05-30 21:21:54 +02:00
arduino-mk Rewrite dependency code 2013-05-30 21:21:54 +02:00
bin Check if ARDUINO_DIR Env variable is defined or not 2012-12-17 17:12:12 +05:30
examples removed unnecessary .DS_Store 2013-03-16 00:19:56 -07:00
.gitignore allow user to choose source files 2012-07-06 15:02:43 +05:30
README.md Updated readme to add information about change in maintainers 2013-05-19 16:33:59 +05:30

A Makefile for Arduino Sketches

This is a very simple Makefile which knows how to build Arduino sketches. It defines the entire workflows for compiling code, flashing it to Arduino and even communicating through Serial monitor. You don't need to change anything in the Arduino sketches.

If you're using Debian or Ubuntu, you can find this in the arduino-mk package.

Credits

This makefile was originally created by Martin Oldfield and he maintained it till v0.10.2. From May 2013, it is maintained by Sudar

Usage

Download a copy of this repo some where in your system.

On the Mac you might want to set:

ARDUINO_DIR   = /Applications/Arduino.app/Contents/Resources/Java
ARDMK_DIR     = /usr/local

On Linux, you might prefer:

ARDUINO_DIR   = /usr/share/arduino
ARDMK_DIR     = /usr/local
AVR_TOOLS_DIR = /usr

The Makefile also delegates resetting the board to a short Perl program. You'll need to install Device::SerialPort to use it though. You'll also need the YAML library to run ard-parse-boards.

On Debian or Ubuntu:

   apt-get install libdevice-serialport-perl
   apt-get install libyaml-perl

On Fedora:

   yum install perl-Device-SerialPort
   yum install perl-YAML

On Mac using MacPorts:

   sudo port install p5-device-serialport
   sudo port install p5-YAML

  and use /opt/local/bin/perl5 instead of /usr/bin/perl

On other systems:

   cpanm Device::SerialPort
   cpanm YAML

User Libraries

In order to use Arduino libraries installed in the user's sketchbook folder (the standard location for custom libraries when using the Arduino IDE), you need to set the ARDUINO_SKETCHBOOK variable to point to this directory. By default it is set to $HOME/sketchbook.

Changelog

The following is the rough list of changes that went into different versions. I tried to give credit whenever possible. If I have missed anyone, kindly add it to the list.

0.10.2 15.xii.2012 Sudar

0.10.1 15.xii.2012 Sudar

  • Merged all changes from Upstream and the following changes from https://github.com/rpavlik
  • Allow passing extra flags
  • Make listing files more useful
  • Add knowledge of device-specific assembler
  • Use variables instead of hardcoded commands
  • Make disasm more helpful
  • Change .sym output
  • Provide symbol_sizes and generated_assembly targets.
  • Be able to silence configuration output
  • Make everybody depend on the makefile, in case cflags are changed, etc.
  • Make the makefile error if the arduino port is not present.

0.10 17.ix.12 M J Oldfield

  • Merged all changes from Upstream

0.9.3.2 10.ix.2012 Sudar

0.9.3.1 18.viii.2012 jeffkowalski

  • Autodetect ARDUINO_LIBS from includes in LOCAL_SRCS
  • Autodetect ARDUINO_SKETCHBOOK from file set by Arduino IDE
  • Autodetect ARDMK_DIR based on location of this file
  • Added support for utility directory within SYS and USER libraries

0.9.3 13.vi.2012

0.9.2 06.vi.2012

0.9.1 06.vi.2012

  • Corrected the ubuntu package names
  • Prevent the file-not-found error if the depends.mk file is not needed
  • Delete the build-cli folder as well while doing make clean
  • Added support for compiling .pde files in Arduino 1.0 environment
  • Replaced = with += in CPPFLAGS assignment so that we can set CPPFLAGS per sketch if needed
  • Changed AVRDUDE_CONF so it can be defined in per-project makefile (https://github.com/WizenedEE)
  • Cleaner way to delete the build-cli directory when make clean is invoked
  • The package name in Debian and Ubuntu is arduino-mk (https://github.com/maqifrnswa)

2012-02-12, version 0.8

  • Patches for version 1.0 of the Arduino IDE. Older versions might still work, but Ive not tested it.
  • A change to the build process: rather than link all the system objects directly into the executable, bundle them in a library first. This should make the final executable smaller.
  • If TARGET isnt explicitly set, default to the current directory name. Thanks to Daniele Vergini for this patch.
  • Add support for .c files in system libraries: Dirk-Willem van Gulik and Evan Goldenberg both reported this and provided patches in the same spirit.
  • Added a size target as suggested by Alex Satrapa.

Unreleased, version 0.7

  • Added -lm to the linker options, and -F to stty.

2011-06-23, version 0.6

  • Added ard-parse-boards. Mark Sproul suggested doing something like this ages ago, but Ive only recently looked at it in detail.
  • Fabien Le Lez reported that one needs to link with -lc to avoid linker errors.

2011-06-23, version 0.5

  • Imported changes from Debian/Ubuntu, which incorporate a patch from Stefan Tomanek so that libraries would be compiled too.

Note: Many other people sent me similar patches, but I didnt get around to using them. In the end, I took the patch from Debian and Ubuntu: there seems merit in not forking the code and using a tested version. So, thanks and apologies to Nick Andrew, Leandro Coletto Biazon, Thibaud Chupin, Craig Hollabaugh, Johannes H. Jensen, Fabien Le Lez, Craig Leres, and Mark Sproul.

2010-05-24, version 0.4

Tweaked rules for the reset target on Philip Hands advice.

2010-05-21, version 0.3

  • Tidied up the licensing, making it clear that its released under LGPL 2.1.
  • Philip Hands sent me some code to reset the Arduino by dropping DTR for 100ms, and I added it.
  • Tweaked the Makefile to handle version 0018 of the Arduino software which now includes main.cpp. Accordingly we dont need to—and indeed must not—add main.cxx to the .pde sketch file. The paths seem to have changed a bit too.

Know Issues

Similar works

  • It's not a derivative of this, but Alan Burlison has written a similar thing.
  • Alan's Makefile was used in a Pragmatic Programmer's article.
  • Rei Vilo wrote to tell me that he's using the Makefile ina Xcode 4 template called embedXcode. Apparently it supports many platforms and boards, including AVR-based Arduino, AVR-based Wiring, PIC32-based chipKIT, MSP430-based LaunchPad and ARM3-based Maple.