/make/arduino-mk

To get this branch, use:
bzr branch http://bzr.ed.am/make/arduino-mk

« back to all changes in this revision

Viewing changes to arduino.mk

  • Committer: edam
  • Date: 2012-02-14 12:43:59 UTC
  • Revision ID: edam@waxworlds.org-20120214124359-2hvso578fmquwbco
fixed dates in NEWS

Show diffs side-by-side

added added

removed removed

43
43
#
44
44
#   $ ln -s ~/src/arduino.mk Makefile
45
45
#
46
 
# You also need to set up a couple of environment varibales. ARDUINODIR should
 
46
# You also need to set up a couple of environment variables. ARDUINODIR should
47
47
# be set to the path where you unpacked the arduino software from arduino.cc
48
48
# (it defaults to ~/opt/arduino if unset).  You might be best to set this in
49
49
# your ~/.profile by adding something like this:
52
52
#
53
53
# You will also need to set BOARD to the type of arduino you're using.  This
54
54
# can be done when running make (or you could set a default in ~/.profile and
55
 
# iverride it as necessary).  For example:
 
55
# override it as necessary).  For example:
56
56
#
57
57
#   $ export BOARD=uno
58
58
#   $ make
59
59
#
60
60
# You may also need to set SERIALDEV if it is not detected correctly.
61
61
#
62
 
# The presence of a .ino or .pde file causes the arduino.mk to atuomatically
63
 
# determine va;ues for SOURCES, TARGET and LIBRARIES.  Any .c, .cc and .cpp
64
 
# files in the project directory (or any "util" or "utility" subdirectoried)
65
 
# are automatically included in the build and are scanned for Atduino libraries
66
 
# that have been #included.
 
62
# The presence of a .ino (or .pde) file causes the arduino.mk to automatically
 
63
# determine values for SOURCES, TARGET and LIBRARIES.  Any .c, .cc and .cpp
 
64
# files in the project directory (or any "util" or "utility" subdirectories)
 
65
# are automatically included in the build and are scanned for Arduino libraries
 
66
# that have been #included. Note, there can only be one .ino (or .pde) file.
67
67
#
68
68
# Alternatively, if you want to manually specify build variables, create a
69
 
# Makefile that defines SOURCES and LIBRARARIES and then includes arduino.mk.
 
69
# Makefile that defines SOURCES and LIBRARIES and then includes arduino.mk.
70
70
# (There is no need to define TARGET).  Here is an example Makefile:
71
71
#
72
72
#   SOURCES := main.cc other.cc
81
81
# BOARD        Specify a target board type.  Run `make boards` to see available
82
82
#              board types.
83
83
#
84
 
# SERIALDEV    The unix device of the device where the arduino can be found.
 
84
# SERIALDEV    The unix device name of the serial device that is the arduino.
85
85
#              If unspecified, an attempt is made to determine the name of a
86
86
#              connected arduino's serial device.
87
87
#
88
88
# TARGET       The name of the target file.  This is set automatically if a
89
 
#              .ino or .pde is found, but it is not neccesary to set it
 
89
#              .ino (or .pde) is found, but it is not necessary to set it
90
90
#              otherwise.
91
91
#
92
92
# SOURCES      A list of all source files of whatever language.  The language
93
93
#              type is determined by the file extension.  This is set
94
 
#              automatically if a .ino or .pde is found.
 
94
#              automatically if a .ino (or .pde) is found.
95
95
#
96
96
# LIBRARIES    A list of arduino libraries to build and include.  This is set
97
 
#              automatically if a .ino or .pde is found.
 
97
#              automatically if a .ino (or .pde) is found.
98
98
#
99
99
# This makefile also defines the following goals for use on the command line
100
100
# when you run make:
111
111
# boards       Display a list of available board names, so that you can set the
112
112
#              BOARD environment variable appropriately.
113
113
#
114
 
# monitor      Start `screen` on the serial device.  It is ment to be an
115
 
#              equivelant to the arduino serial monitor.
 
114
# monitor      Start `screen` on the serial device.  This is meant to be an
 
115
#              equivalent to the arduino serial monitor.
116
116
#
117
117
# <file>       Builds the specified file, either an object file or the target,
118
118
#              from those that that would be built for the project.
147
147
endif
148
148
 
149
149
# no target? use default
150
 
ifndef TARGET
 
150
ifeq ($(TARGET), )
151
151
TARGET := a.out
152
152
endif
153
153
 
154
154
# no serial device? attempt to detect an arduino
155
 
ifndef SERIALDEV
 
155
ifeq ($(SERIALDEV), )
156
156
SERIALDEV := $(firstword $(wildcard /dev/ttyACM? /dev/ttyUSB?))
157
157
endif
158
158
 
168
168
# files
169
169
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
170
170
ARDUINOSRCDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
 
171
ARDUINOLIBSDIR := $(ARDUINODIR)/libraries
171
172
ARDUINOLIB := _arduino.a
172
 
ARDUINOLIBTMP := _arduino.a.tmp
 
173
ARDUINOLIBTMP := $(ARDUINOLIB).tmp
173
174
ARDUINOLIBOBJS := $(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
174
175
        $(wildcard $(addprefix $(ARDUINOSRCDIR)/, *.c *.cpp)))))
175
176
ARDUINOLIBOBJS += $(foreach lib, $(LIBRARIES), \
176
177
        $(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
177
 
        $(wildcard $(addprefix $(ARDUINODIR)/libraries/$(lib)/, *.c *.cpp))))))
 
178
        $(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/, *.c *.cpp)) \
 
179
        $(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/utility/, *.c *.cpp)) ))))
178
180
 
179
181
# obtain board parameters from the arduino boards.txt file
180
182
BOARDS_FILE := $(ARDUINODIR)/hardware/arduino/boards.txt
189
191
BOARD_UPLOAD_PROTOCOL := \
190
192
        $(shell sed -ne "s/$(BOARD).upload.protocol=\(.*\)/\1/p" $(BOARDS_FILE))
191
193
 
192
 
# software
193
 
CC := avr-gcc
194
 
CXX := avr-g++
195
 
LD := avr-ld
196
 
AR := avr-ar
197
 
OBJCOPY := avr-objcopy
198
 
AVRDUDE := avrdude
 
194
# arduino version (currently fixed)
 
195
ARDUINOVER := 100
 
196
 
 
197
# software (prioritise binaries that came with arduino software)
 
198
FIND_SOFTWARE = $(firstword $(wildcard \
 
199
        $(ARDUINODIR)/hardware/tools/$(1) \
 
200
        $(ARDUINODIR)/hardware/tools/avr/bin/$(1) \
 
201
        ) $(1) )
 
202
CC := $(call FIND_SOFTWARE,avr-gcc)
 
203
CXX := $(call FIND_SOFTWARE,avr-g++)
 
204
LD := $(call FIND_SOFTWARE,avr-ld)
 
205
AR := $(call FIND_SOFTWARE,avr-ar)
 
206
OBJCOPY := $(call FIND_SOFTWARE,avr-objcopy)
 
207
AVRDUDE := $(call FIND_SOFTWARE,avrdude)
199
208
 
200
209
# flags
201
210
CPPFLAGS = -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
202
 
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU) -DF_CPU=$(BOARD_BUILD_FCPU)
 
211
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
 
212
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
 
213
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOVER)
203
214
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOSRCDIR)
204
215
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
205
216
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/, $(LIBRARIES))
243
254
        @test -n "$(SERIALDEV)" || { \
244
255
                echo "error: SERIALDEV could not be determined automatically." >&2; \
245
256
                exit 1; }
 
257
        @test -n `which screen` || { \
 
258
                echo "error: can't find GNU screen, you might need to install it." >&2 \
 
259
                ecit 1; }
246
260
        screen $(SERIALDEV)
247
261
 
248
262
# building the target
284
298
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/%.cpp
285
299
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
286
300
        $(COMPILE.cpp) -o $@ $<
 
301
 
 
302
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/utility/%.c
 
303
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
 
304
        $(COMPILE.c) -o $@ $<
 
305
 
 
306
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/utility/%.cpp
 
307
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
 
308
        $(COMPILE.cpp) -o $@ $<