/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-13 15:44:24 UTC
  • Revision ID: edam@waxworlds.org-20120213154424-2wsncooiohmcn7oz
clarify number of permitted .ino files

Show diffs side-by-side

added added

removed removed

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 automatically
 
62
# The presence of a .ino or .pde file causes the arduino.mk to automatically
63
63
# determine values for SOURCES, TARGET and LIBRARIES.  Any .c, .cc and .cpp
64
64
# files in the project directory (or any "util" or "utility" subdirectories)
65
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.
 
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
69
# Makefile that defines SOURCES and LIBRARIES and then includes arduino.mk.
78
78
# ARDUINODIR   The path where you have installed/unpacked the arduino software
79
79
#              (from http://arduino.cc/)
80
80
#
81
 
# ARDUINOCONST The arduino software version, as an integer, used to define the
82
 
#              ARDUINO version constant. This defaults to 100 if unset.
83
 
#
84
 
# AVRTOOLSPATH A space-separated list of directories to search in order when
85
 
#              lookin for the avr build tools. This defaults to the system PATH
86
 
#              followed by subdirectories in ARDUINODIR if unset.
87
 
#
88
81
# BOARD        Specify a target board type.  Run `make boards` to see available
89
82
#              board types.
90
83
#
91
 
# LIBRARIES    A list of arduino libraries to build and include.  This is set
92
 
#              automatically if a .ino (or .pde) is found.
93
 
#
94
84
# SERIALDEV    The unix device name of the serial device that is the arduino.
95
85
#              If unspecified, an attempt is made to determine the name of a
96
86
#              connected arduino's serial device.
97
87
#
 
88
# TARGET       The name of the target file.  This is set automatically if a
 
89
#              .ino or .pde is found, but it is not necessary to set it
 
90
#              otherwise.
 
91
#
98
92
# SOURCES      A list of all source files of whatever language.  The language
99
93
#              type is determined by the file extension.  This is set
100
 
#              automatically if a .ino (or .pde) is found.
 
94
#              automatically if a .ino or .pde is found.
101
95
#
102
 
# TARGET       The name of the target file.  This is set automatically if a
103
 
#              .ino (or .pde) is found, but it is not necessary to set it
104
 
#              otherwise.
 
96
# LIBRARIES    A list of arduino libraries to build and include.  This is set
 
97
#              automatically if a .ino or .pde is found.
105
98
#
106
99
# This makefile also defines the following goals for use on the command line
107
100
# when you run make:
126
119
#_______________________________________________________________________________
127
120
#
128
121
 
129
 
# default arduino software directory, check software exists
 
122
# The full path to the arduino software, from arduino.cc
130
123
ifndef ARDUINODIR
131
124
ARDUINODIR := $(wildcard ~/opt/arduino)
132
125
endif
 
126
 
 
127
# check arduino software
133
128
ifeq ($(wildcard $(ARDUINODIR)/hardware/arduino/boards.txt), )
134
129
$(error ARDUINODIR is not set correctly; arduino software not found)
135
130
endif
136
131
 
137
 
# default arduino version
138
 
ARDUINOCONST ?= 100
139
 
 
140
 
# default path for avr tools
141
 
ifndef AVRTOOLSPATH
142
 
AVRTOOLSPATH := $(subst :, , $(PATH))
143
 
AVRTOOLSPATH += $(ARDUINODIR)/hardware/tools
144
 
AVRTOOLSPATH += $(ARDUINODIR)/hardware/tools/avr/bin
145
 
endif
146
 
 
147
132
# auto mode?
148
133
INOFILE := $(wildcard *.ino *.pde)
149
134
ifdef INOFILE
150
135
ifneq ($(words $(INOFILE)), 1)
151
136
$(error There is more than one .pde or .ino file in this directory!)
152
137
endif
153
 
 
154
 
# automatically determine sources and targeet
155
138
TARGET := $(basename $(INOFILE))
156
139
SOURCES := $(INOFILE) \
157
140
        $(wildcard *.c *.cc *.cpp) \
158
141
        $(wildcard $(addprefix util/, *.c *.cc *.cpp)) \
159
142
        $(wildcard $(addprefix utility/, *.c *.cc *.cpp))
160
 
 
161
143
# automatically determine included libraries
162
144
ARDUINOLIBSAVAIL := $(notdir $(wildcard $(ARDUINODIR)/libraries/*))
163
145
LIBRARIES := $(filter $(ARDUINOLIBSAVAIL), \
164
146
        $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
165
 
 
 
147
endif
 
148
 
 
149
# no target? use default
 
150
ifeq ($(TARGET), )
 
151
TARGET := a.out
 
152
endif
 
153
 
 
154
# no serial device? attempt to detect an arduino
 
155
ifeq ($(SERIALDEV), )
 
156
SERIALDEV := $(firstword $(wildcard /dev/ttyACM? /dev/ttyUSB?))
166
157
endif
167
158
 
168
159
# no board? oh dear...
174
165
endif
175
166
endif
176
167
 
177
 
# no serial device? make a poor attempt to detect an arduino
178
 
ifeq ($(SERIALDEV), )
179
 
SERIALDEV := $(firstword $(wildcard /dev/ttyACM? /dev/ttyUSB?))
180
 
endif
181
 
 
182
 
# software
183
 
findsoftware = $(firstword $(wildcard $(addsuffix /$(1), $(AVRTOOLSPATH))))
184
 
CC := $(call findsoftware,avr-gcc)
185
 
CXX := $(call findsoftware,avr-g++)
186
 
LD := $(call findsoftware,avr-ld)
187
 
AR := $(call findsoftware,avr-ar)
188
 
OBJCOPY := $(call findsoftware,avr-objcopy)
189
 
AVRDUDE := $(call findsoftware,avrdude)
190
 
 
191
168
# files
192
 
TARGET := $(if $(TARGET), $(TARGET), a.out)
193
169
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
194
170
ARDUINOSRCDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
195
171
ARDUINOLIBSDIR := $(ARDUINODIR)/libraries
201
177
        $(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
202
178
        $(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/, *.c *.cpp)) \
203
179
        $(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/utility/, *.c *.cpp)) ))))
204
 
AVRDUDECONF := $(wildcard $(AVRDUDE).conf)
205
180
 
206
181
# obtain board parameters from the arduino boards.txt file
207
182
BOARDS_FILE := $(ARDUINODIR)/hardware/arduino/boards.txt
216
191
BOARD_UPLOAD_PROTOCOL := \
217
192
        $(shell sed -ne "s/$(BOARD).upload.protocol=\(.*\)/\1/p" $(BOARDS_FILE))
218
193
 
 
194
# software (prioritise binaries that came with arduino software)
 
195
FIND_SOFTWARE = $(firstword $(wildcard \
 
196
        $(ARDUINODIR)/hardware/tools/$(1) \
 
197
        $(ARDUINODIR)/hardware/tools/avr/bin/$(1) \
 
198
        ) $(1) )
 
199
CC := $(call FIND_SOFTWARE,avr-gcc)
 
200
CXX := $(call FIND_SOFTWARE,avr-g++)
 
201
LD := $(call FIND_SOFTWARE,avr-ld)
 
202
AR := $(call FIND_SOFTWARE,avr-ar)
 
203
OBJCOPY := $(call FIND_SOFTWARE,avr-objcopy)
 
204
AVRDUDE := $(call FIND_SOFTWARE,avrdude)
 
205
 
219
206
# flags
220
 
CPPFLAGS := -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
221
 
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
222
 
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
223
 
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
 
207
CPPFLAGS = -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
 
208
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU) -DF_CPU=$(BOARD_BUILD_FCPU)
224
209
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOSRCDIR)
225
210
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
226
211
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/, $(LIBRARIES))
227
212
CPPFLAGS += $(patsubst %, -I$(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
228
 
AVRDUDEFLAGS := $(addprefix -C , $(AVRDUDECONF)) -DV
 
213
AVRDUDEFLAGS = -C $(ARDUINODIR)/hardware/tools/avrdude.conf -DV
229
214
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
230
215
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
231
 
LINKFLAGS := -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
 
216
LINKFLAGS = -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
232
217
 
233
218
# default rule
234
219
.DEFAULT_GOAL := all