/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-16 14:23:53 UTC
  • Revision ID: edam@waxworlds.org-20120216142353-3wnmw6k12l8m4qb4
added AVRDUDECONF variable; fixed some OS X issues; added SERIALDEV guess warning and invalid BOARD value error

Show diffs side-by-side

added added

removed removed

79
79
#              (from http://arduino.cc/)
80
80
#
81
81
# ARDUINOCONST The arduino software version, as an integer, used to define the
82
 
#              ARDUINO version constant. This defaults to 100 if unset.
 
82
#              ARDUINO version constant. This defaults to 100 if undefined.
 
83
#
 
84
# AVRDUDECONF  The avrdude.conf to use. If undefined, this defaults to a guess
 
85
#              based on where the avrdude in use is. If empty, no avrdude.conf
 
86
#              is passed to avrdude (to the system default is used).
83
87
#
84
88
# AVRTOOLSPATH A space-separated list of directories to search in order when
85
89
#              lookin for the avr build tools. This defaults to the system PATH
86
 
#              followed by subdirectories in ARDUINODIR if unset.
 
90
#              followed by subdirectories in ARDUINODIR if undefined.
87
91
#
88
92
# BOARD        Specify a target board type.  Run `make boards` to see available
89
93
#              board types.
130
134
ifndef ARDUINODIR
131
135
ARDUINODIR := $(wildcard ~/opt/arduino)
132
136
endif
133
 
ifeq ($(wildcard $(ARDUINODIR)/hardware/arduino/boards.txt), )
 
137
ifeq "$(wildcard $(ARDUINODIR)/hardware/arduino/boards.txt)" ""
134
138
$(error ARDUINODIR is not set correctly; arduino software not found)
135
139
endif
136
140
 
147
151
# auto mode?
148
152
INOFILE := $(wildcard *.ino *.pde)
149
153
ifdef INOFILE
150
 
ifneq ($(words $(INOFILE)), 1)
 
154
ifneq "$(words $(INOFILE))" "1"
151
155
$(error There is more than one .pde or .ino file in this directory!)
152
156
endif
153
157
 
165
169
 
166
170
endif
167
171
 
168
 
# no board? oh dear...
169
 
ifndef BOARD
170
 
ifneq "$(MAKECMDGOALS)" "boards"
171
 
ifneq "$(MAKECMDGOALS)" "clean"
172
 
$(error BOARD is unset.  Type 'make boards' to see possible values)
173
 
endif
174
 
endif
175
 
endif
176
 
 
177
172
# no serial device? make a poor attempt to detect an arduino
178
 
ifeq ($(SERIALDEV), )
179
 
SERIALDEV := $(firstword $(wildcard /dev/ttyACM? /dev/ttyUSB?))
 
173
SERIALDEVGUESS := 0
 
174
ifeq "$(SERIALDEV)" ""
 
175
SERIALDEV := $(firstword $(wildcard \
 
176
        /dev/ttyACM? /dev/ttyUSB? /dev/tty.usbmodem*))
 
177
SERIALDEVGUESS := 1
180
178
endif
181
179
 
182
180
# software
189
187
AVRDUDE := $(call findsoftware,avrdude)
190
188
 
191
189
# files
192
 
TARGET := $(if $(TARGET), $(TARGET), a.out)
 
190
TARGET := $(if $(TARGET),$(TARGET),a.out)
193
191
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
194
192
ARDUINOSRCDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
195
193
ARDUINOLIBSDIR := $(ARDUINODIR)/libraries
201
199
        $(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
202
200
        $(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/, *.c *.cpp)) \
203
201
        $(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/utility/, *.c *.cpp)) ))))
 
202
ifeq "$(AVRDUDECONF)" ""
 
203
ifeq "$(AVRDUDE)" "$(ARDUINODIR)/hardware/tools/avr/bin/avrdude"
 
204
AVRDUDECONF := $(ARDUINODIR)/hardware/tools/avr/etc/avrdude.conf
 
205
else
204
206
AVRDUDECONF := $(wildcard $(AVRDUDE).conf)
 
207
endif
 
208
endif
 
209
 
 
210
# no board?
 
211
ifndef BOARD
 
212
ifneq "$(MAKECMDGOALS)" "boards"
 
213
ifneq "$(MAKECMDGOALS)" "clean"
 
214
$(error BOARD is unset.  Type 'make boards' to see possible values)
 
215
endif
 
216
endif
 
217
endif
205
218
 
206
219
# obtain board parameters from the arduino boards.txt file
207
220
BOARDS_FILE := $(ARDUINODIR)/hardware/arduino/boards.txt
216
229
BOARD_UPLOAD_PROTOCOL := \
217
230
        $(shell sed -ne "s/$(BOARD).upload.protocol=\(.*\)/\1/p" $(BOARDS_FILE))
218
231
 
 
232
# invalid board?
 
233
ifeq "$(BOARD_BUILD_MCU)" ""
 
234
ifneq "$(MAKECMDGOALS)" "boards"
 
235
ifneq "$(MAKECMDGOALS)" "clean"
 
236
$(error BOARD is invalid.  Type 'make boards' to see possible values)
 
237
endif
 
238
endif
 
239
endif
 
240
 
219
241
# flags
220
242
CPPFLAGS := -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
221
243
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
230
252
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
231
253
LINKFLAGS := -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
232
254
 
 
255
# figure out which arg to use with stty
 
256
STTYFARG := $(shell stty --help > /dev/null 2>&1 && echo -F || echo -f)
 
257
 
233
258
# default rule
234
259
.DEFAULT_GOAL := all
235
260
 
247
272
        @test -n "$(SERIALDEV)" || { \
248
273
                echo "error: SERIALDEV could not be determined automatically." >&2; \
249
274
                exit 1; }
250
 
        stty -F $(SERIALDEV) hupcl
 
275
        @test 1 -eq $(SERIALDEVGUESS) && { \
 
276
                echo "*GUESSING* at serial device:" $(SERIALDEV); \
 
277
                echo; }
 
278
        stty $(STTYFARG) $(SERIALDEV) hupcl
251
279
        $(AVRDUDE) $(AVRDUDEFLAGS) -U flash:w:$(TARGET).hex:i
252
280
 
253
281
clean:
267
295
        @test -n `which screen` || { \
268
296
                echo "error: can't find GNU screen, you might need to install it." >&2 \
269
297
                ecit 1; }
 
298
        @test 1 -eq $(SERIALDEVGUESS) && { \
 
299
                echo "*GUESSING* at serial device:" $(SERIALDEV); \
 
300
                echo; }
270
301
        screen $(SERIALDEV)
271
302
 
272
303
# building the target