/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: Tim Marston
  • Date: 2014-01-15 19:35:45 UTC
  • Revision ID: tim@ed.am-20140115193545-m52ejwu8zgnn7hcm
if perl is installed, do case-insensitive matching of BOARD name; increase
compatibility with 1.5 SDK (pass board and arch compiler directives; build with
-fpermissive cause the SDK includes an old compiler)

Show diffs side-by-side

added added

removed removed

42
42
#
43
43
#   $ ln -s ~/src/arduino.mk Makefile
44
44
#
45
 
# The Arduino software is required, version 1.0 or later, including version 1.5
46
 
# (which is in BETA at time of release of this makefile).  On GNU/Linux you can
47
 
# probably install the software from your package manager.  If you are using
48
 
# Debian (or a derivative), try `apt-get install arduino`.  Otherwise, you can
49
 
# download the latest Arduino software manually from http://arduino.cc/.  In
50
 
# case you're unsure, install it at ~/opt/arduino (or /Applications on OS X).
 
45
# The Arduino software (version 1.0 or later, including the new 1.5 BETA) is
 
46
# required.  On GNU/Linux you can probably install the software from your
 
47
# package manager.  If you are using Debian (or a derivative), try `apt-get
 
48
# install arduino`.  Otherwise, you can download the Arduino software manually
 
49
# from http://arduino.cc/.  It is suggested that you install it at
 
50
# ~/opt/arduino (or /Applications on OS X) if you are unsure.
51
51
#
52
52
# If you downloaded the Arduino software manually and unpacked it somewhere
53
53
# *other* than ~/opt/arduino (or /Applications), you will need to set up the
173
173
        $(HOME)/Applications/Arduino.app/Contents/Resources/Java))
174
174
endif
175
175
 
176
 
# check arduino software exists and determine available backends
 
176
# check ARDUINODIR (and determine which backends are available)
177
177
ifneq "" "$(wildcard $(ARDUINODIR)/hardware/arduino/boards.txt)"
178
178
ARDUINOBACKENDS := /
179
179
else ifneq "" "$(wildcard $(ARDUINODIR)/hardware/arduino/avr/boards.txt)"
194
194
# obtain board parameters from the arduino boards.txt file(s)
195
195
BOARDSFILES := $(foreach dir, $(ARDUINOBACKENDS), \
196
196
        $(ARDUINODIR)/hardware/arduino$(dir)/boards.txt)
 
197
ifeq "$(ARDUINOBACKENDS)" "/"
 
198
readboardsparam = $(shell sed -ne "s/^$(BOARD)\\.$(1)=\(.*\)/\1/p" \
 
199
        $(BOARDSFILES))
 
200
else
197
201
readboardsparam = $(firstword \
198
 
        $(shell sed -ne "s/^menu\\.cpu\\.$(BOARD)\\.$(1)=\(.*\)/\1/Ip" \
199
 
                $(BOARDSFILES)) \
200
 
        $(shell sed -ne "s/^$(basename $(BOARD))\\.$(1)=\(.*\)/\1/Ip" \
 
202
        $(call readboardsmenuparam,$(1),$(basename $(BOARD)),$(suffix $(BOARD))) \
 
203
        $(shell sed -ne "s/^$(basename $(BOARD))\\.$(1)=\(.*\)/\1/p" \
201
204
                $(BOARDSFILES)))
 
205
ifneq "$(wildcard /usr/bin/perl)" ""
 
206
readboardsmenuparam = $(shell perl -ne \
 
207
        '/^$(2)\.menu\.cpu/ && s/.*$(3)\.$(1)=(.*)/\1/i && print' $(BOARDSFILES))
 
208
else
 
209
readboardsmenuparam = $(shell sed -ne '/^$(2)\.menu\.cpu/ {' \
 
210
        -e 's/.*$(3)\.$(1)=\(.*\)/\1/p' -e '}' $(BOARDSFILES))
 
211
endif
 
212
endif
202
213
BOARD_BUILD_MCU := $(call readboardsparam,build.mcu)
203
214
BOARD_BUILD_FCPU := $(call readboardsparam,build.f_cpu)
204
215
BOARD_BUILD_VARIANT := $(call readboardsparam,build.variant)
205
216
BOARD_BUILD_CORE := $(call readboardsparam,build.core)
 
217
BOARD_BUILD_BOARD := $(call readboardsparam,build.board)
206
218
BOARD_UPLOAD_SPEED := $(call readboardsparam,upload.speed)
207
219
BOARD_UPLOAD_PROTOCOL := $(call readboardsparam,upload.protocol)
208
220
BOARD_USB_VID := $(call readboardsparam,build.vid)
237
249
        $(if $(shell grep ^$(basename $(BOARD))\\.name \
238
250
                $(ARDUINODIR)/hardware/arduino$(dir)/boards.txt), \
239
251
        $(ARDUINODIR)/hardware/arduino$(dir))))
 
252
ARDUINOBACKENDARCH=AVR
240
253
ARDUINOCOREDIR := $(ARDUINOBACKENDDIR)/cores/$(BOARD_BUILD_CORE)
241
254
 
242
255
# default library path (places to look for libraries)
258
271
        $(wildcard $(addprefix utility/, *.c *.cc *.cpp *.C *.s *.S))
259
272
 
260
273
# automatically determine library directories (to pull library sources in from)
261
 
# by matching included headers in poject sources to headers that exist in the
 
274
# by matching included headers in project sources to headers that exist in the
262
275
# roots of any library directories, giving priority to libraries in the order
263
276
# they're in LIBRARYPATH, and then to the alphabetically-greater named library
264
277
# (this is a really stupid way of doing it, but it's how the IDE works -- if
265
278
# it's causing problems, you can override it by setting LIBRARIES manually)
266
 
INCLUDEDHEADERS := \
267
 
        $(shell sed -nre "s/^\s*\#\s*include\s*[<\"](\S+\.h)[>\"].*/\1/p" \
268
 
        $(SOURCES))
 
279
INCLUDEDHEADERS := $(shell sed -ne '/^[ \t]*\#[ \t]*include[ \t<"]/ {' \
 
280
         -e 's/^.*[<"]\(.*\)[>"].*/\1/p' -e '}' $(SOURCES))
269
281
reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) \
270
282
        $(firstword $(1))
271
283
LIBRARYHEADERS := $(foreach dir, $(LIBRARYPATH), \
281
293
LIBRARYDIRS := $(foreach lib, $(LIBRARIES), \
282
294
        $(firstword $(wildcard $(addsuffix /$(lib), $(LIBRARYPATH)))))
283
295
endif
284
 
LIBRARYDIRS := $(LIBRARYDIRS) $(addsuffix /utility, $(LIBRARYDIRS))
 
296
LIBRARYDIRS := $(LIBRARYDIRS) \
 
297
        $(addsuffix /utility, $(LIBRARYDIRS)) \
 
298
        $(addsuffix /src, $(LIBRARYDIRS))
285
299
 
286
300
# files
287
301
TARGET := $(if $(TARGET),$(TARGET),a.out)
331
345
# flags
332
346
CPPFLAGS += -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
333
347
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
334
 
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
 
348
CPPFLAGS += -fpermissive -mmcu=$(BOARD_BUILD_MCU)
335
349
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
 
350
CPPFLAGS += -DARDUINO_$(BOARD_BUILD_BOARD) -DARDUINO_ARCH_$(ARDUINOBACKENDARCH)
336
351
CPPFLAGS += -DUSB_VID=$(BOARD_USB_VID) -DUSB_PID=$(BOARD_USB_PID)
337
352
CPPFLAGS += -I. -Iutil -Iutility -I $(ARDUINOCOREDIR)
338
353
CPPFLAGS += -I $(ARDUINOBACKENDDIR)/variants/$(BOARD_BUILD_VARIANT)/
376
391
ifeq "$(BOARD_BOOTLOADER_PATH)" "caterina"
377
392
        stty $(STTYFARG) $(SERIALDEV) speed 1200
378
393
        sleep 1
379
 
else ifeq "" "$(filter net:%,$(SERIALDEV))"
 
394
else ifeq "" "$(filter net:% usb:%,$(SERIALDEV))"
380
395
        stty $(STTYFARG) $(SERIALDEV) hupcl
381
396
endif
382
397
        $(AVRDUDE) $(AVRDUDEFLAGS) -U flash:w:$(TARGET).hex:i
388
403
 
389
404
boards:
390
405
        @echo "Available BOARD values:"
391
 
        @sed -nre '/^\w+\.name=/p; /^menu\.cpu\.\w+\.\w+=/p;' $(BOARDSFILES) | \
392
 
                sed -re 's/(\w+)\.name=(.*)/\1                   \2/' \
393
 
                        -e 's/menu.cpu.\w+(\.\w+)=(.*)/  \1                  --\2/' \
394
 
                        -e 's/(.{19}) *(.*)/  \1 \2/; s/--/  w\/ /;'
 
406
        @sed -ne '/[[:alnum:]]*\.name=/p' \
 
407
                -e '/^[[:alnum:]]*\.menu\.cpu\.[[:alnum:]]*=/p' $(BOARDSFILES) | \
 
408
                sed -e 's/\([[:alnum:]]*\)\.name=\(.*\)/\1                   \2/' \
 
409
                        -e 's/^.*\(\.[[:alnum:]]*\)=\(.*\)/  \1                  --\2/' \
 
410
                        -e 's/\(.\{19\}\) *\(.*\)/  \1 \2/' -e 's/--/  ...with /'
395
411
ifneq "$(ARDUINOBACKENDS)" "/"
396
412
        @echo
397
413
        @echo "NOTE: where a board supports multiple CPUs, you must specify" \
446
462
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -lm -o $@
447
463
 
448
464
%.o: %.ino
449
 
        mkdir -p .dep/$(dir $<)
 
465
        mkdir -p .dep/$(pathsubst ./%,%,$(dir $<))
450
466
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
451
467
 
452
468
%.o: %.pde
453
 
        mkdir -p .dep/$(dir $<)
 
469
        mkdir -p .dep/$(pathsubst ./%,%,$(dir $<))
454
470
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
455
471
 
456
472
%.o: %.c
457
 
        mkdir -p .dep/$(dir $<)
 
473
        mkdir -p .dep/$(pathsubst ./%,%,$(dir $<))
458
474
        $(COMPILE.c) $(CPPDEPFLAGS) -o $@ $<
459
475
 
460
476
%.o: %.cpp
461
 
        mkdir -p .dep/$(dir $<)
 
477
        mkdir -p .dep/$(pathsubst ./%,%,$(dir $<))
462
478
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
463
479
 
464
480
%.o: %.cc
465
 
        mkdir -p .dep/$(dir $<)
 
481
        mkdir -p .dep/$(pathsubst ./%,%,$(dir $<))
466
482
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
467
483
 
468
484
%.o: %.C
469
 
        mkdir -p .dep/$(dir $<)
 
485
        mkdir -p .dep/$(pathsubst ./%,%,$(dir $<))
470
486
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
471
487
 
472
488
%.o: %.S
473
 
        mkdir -p .dep/$(dir $<)
 
489
        mkdir -p .dep/$(pathsubst ./%,%,$(dir $<))
474
490
        $(COMPILE.S) $(CPPDEPFLAGS) -o $@ $<
475
491
 
476
492
# building the arduino library