/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-15 17:06:28 UTC
  • Revision ID: edam@waxworlds.org-20120215170628-2bhzt1gd30i9b731
added ARDUINOCONST, AVRTOOLSPATH, detection of avrdude.conf and cleaned up make variable types

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