Arduino Makefile

To develop with the Arduino platform without using the IDE I have chosen to setup my environment with a Makefile to compile and upload the code from the command line. This way I can develop my code in a text editor of my choosing and manage the git repository, code compilation and upload from a command line terminal.

My setup method (assumes some knowledge of GNU Make):


Download the Makefile from http://ed.am/dev/make/arduino-mk
This pre written Makefile does all the heavy lifting, it talks to all the individual programs behind the scenes, ensures the correct files are compiled and handles the settings used to upload the code. The website includes alot more information about using the file, its defaults and using it in more special cases.

Save the file in a convenient place. I have chosen a directory in my users home directory.

~/bin/arduino.mk

 
Install the Arduino IDE using your normal package manager or by downloading from http://arduino.cc. This allows all the required dependencies to be installed along with the the Arduino libraries.

The Makefile is still under active development. It can be used by copying it directly into each project directory and using it from there. The downside is future updates will need to be copied into each project directory. To get around this I am creating a project specific Makefile which includes the arduino.mk file. Changing the arduino.mk file later will mean that the changes are included automatically in each of the individual projects.

Makefile

1
2
3
4
5
6
# Project Variables
# ============
BOARD := diecimila
# Include Arduino Makefile
# ==================
include ~/bin/arduino.mk

It contains the type of board that I am using for the project, it means the code will be compiled and uploaded correctly. It also includes the link to the local copy of the pre written Makefile.


During my setting up of the environment I ran into a little problem. I had the correct board setting but when I tried to compile the code I was getting a message telling me I was using an invalid board . It turns out that I had a space character after the board name but before the carriage return. This space character was interpreted as part of the character string and didn't match. Removing the space and ending the board name with just a carriage return solved the problem.

 

Build Targets

  • all - Default; builds target
  • target - Builds the target
  • upload - Uploads the target to destination
  • clean - Remove target build files from working directory
  • boards - Display list of valid BOARD values
  • monitor - Start a serial monitor using screen
  • size - Display build target size information
  • bootloader - Burns bootloader to chip
  • file - Build specific file

 

Whilst it is possible to override the default build targets it does present a problem passing on variables. The easiest option is to create a new build target rather than tryng to override an existing one.

The default monitor build target uses screen. I am a fan of tmux rather than screen. To make an alternative I can add a new (and unique) build target to my Makefile.

Created: 16/02/2014