A generic, easy to configure makefile for use with Arduino development.
Features:
- Works with (and requires) arduino software version 1.0 (and automatically detects this on Debian)
- Easy configuration (documented below, reference in the makefile itself).
- Automatic mode: drop-in replacement for the Arduino IDE.
- Manual mode: specify all source files and build parameters manually.
- Can automatically detect
#included arduino libraries. - Simple (crap) detection of attached arduino.
- Reads board parameters from
boards.txt. - Lets you upload to and monitoring serial of an arduino.
- Generates dependency files.
- Tested on GNU/Linux and OS X.
Download
You can get it here…
Download Arduino Makefileversion 0.314K
Documentation
Initial set-up
You will need to download the arduino software, version 1.0, and unpack it. For example, you could unpack it to ~/opt/arduino.
There are a several environment variables that affect how the makefile works. You can look in the makefile its self for a complete reference, but I’ll mention a couple now that you might need to set to get started.
ARDUINODIRis the path to where you have installed the arduino software (it defaults to~/opt/arduinoor/usr/share/arduinoif you don’t set it)BOARDtells the script what type of arduino you want to build for and upload to
If you need to specify ARDUINODIR you could do this by adding something like the following to your .profile:
export ARDUINO=~/somewhere/arduino-1.0
But BOARD is probably better specified on the command-line (especially if you use more than one type of arduino):
$ make
(Note: for a complete list of available board names, type make boards)
Additional set-up
There are a few other variables you might need to know about.
SERIALDEV is the device that represents your connected arduino. The makefile can sometimes guess this, but if it can’t, or if the guess is wrong, you may also need to specify it.
AVRTOOLSPATH is a space-separated list of directories that the makefile will look in to find the avr build tools. It defaults to your environment’s PATH, followed by a couple of subdirectories in ARDUINODIR. If this is not sufficient, you can specify it yourself.
AVRDUDECONF is the fully-qualified filename of the avrdude.conf file for avrdude. Again, the makefile tries to make some sensible guesses about its value, but you can specify it yourself.
ARDUINOCONST specifies the value of the ARDUINO constant that is set at build-time. This defaults to 100 if unset, but you can override it.
Automatic Usage
There are two ways to use the makefile. If a project directory contains a .ino (or .pde) file, the makefile works in an “automatic” mode.
In this mode, you can simply copy arduino.mk to the project directory and rename it Makefile. Alternatively, you could copy arduino.mk somewhere in your home directory (I keep mine at ~/src/arduino.mk) and create a symlink to it called Makefile. This latter approach has the benefit that you can update it once for all projects. You would create the symlink by going:
Then, assuming ARDUINODIR and BOARD are set up correctly, you probably only need to type make to build your project and make upload to upload it to an attached arduino!
When in automatic mode, the following things happen:
SOURCESis determined automatically and is made up from: ** the main.ino(or.pde) file ** all.c,.ccand.cppfiles in the project directory ** all.c,.ccand.cppfiles in anyutilityorutilsubdirectoriesLIBRARIESis automatically determined (by scanning the source for#included libraries)TARGETis determined automatically (based on the.inofilename)
Note, there can be only one .ino (or .pde) file per project directory (more than one will cause an error). If you want to split development in to other files, make the other files .c, .cc or .cpp files (which are automatically included in the build).
Manual Usage
If your project directory doesn’t contain a .ino (or .pde) file, you must specify the build parameters yourself. In particular, you’ll need to specify SOURCES and any used LIBRARIES. You might do this, for example, in your own Makefile which then includes arduino.mk.
An example Makefile might look like this:
LIBRARIES := Wire
include ~/src/arduino.mk
Note that you would have to manually #include <Arduino.h> in main.cc in the above example. That header is not automatically included, as would be the case if it were a .ino file.
Make Goals
Here is a full list of goals that arduino.mk supports:
| all | the default; builds the target and tries to upload it |
| target | builds the target |
| upload | upload the previous built target (but doesn’t build it) |
| clean | removes intermediate build files for the target only |
| boards | Display a list of available board types (and valid valies for `BOARD`). |
| monitor | Serial monitor. Actually, it starts `screen` on the serial device. |
| size | Display size information about the built target |
| <file> | you can also specify any object files, or the target, as with most makefiles |
Development
Repository
Previous versions and a change log (revision history) can be obtained from the bazaar repository at:
http://bzr.ed.am/make/arduino-mk
Bugs
If you discover any bugs/issues, I would like to hear about them. Drop me an email with the details. I am also open to suggestions on how to improve this makefile.
Thank You!! Great job, it works like a charm on my gentoo distro!