/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: 2013-03-04 17:13:03 UTC
  • Revision ID: tim@ed.am-20130304171303-oc4ufmezwvm1qxcd
bump version no. to 0.5

Show diffs side-by-side

added added

removed removed

2
2
#
3
3
#                         edam's Arduino makefile
4
4
#_______________________________________________________________________________
5
 
#                                                                 version 0.6dev
 
5
#                                                                    version 0.5
6
6
#
7
 
# Copyright (C) 2011, 2012, 2013 Tim Marston <tim@ed.am>.
 
7
# Copyright (C) 2011, 2012 Tim Marston <tim@ed.am>.
8
8
#
9
9
# Permission is hereby granted, free of charge, to any person obtaining a copy
10
10
# of this software and associated documentation files (the "Software"), to deal
198
198
 
199
199
# obtain board parameters from the arduino boards.txt file
200
200
BOARDSFILE := $(ARDUINODIR)/hardware/arduino/boards.txt
201
 
readboardsparam = $(shell sed -ne "s/^$(BOARD).$(1)=\(.*\)/\1/p" $(BOARDSFILE))
 
201
readboardsparam = $(shell sed -ne "s/$(BOARD).$(1)=\(.*\)/\1/p" $(BOARDSFILE))
202
202
BOARD_BUILD_MCU := $(call readboardsparam,build.mcu)
203
203
BOARD_BUILD_FCPU := $(call readboardsparam,build.f_cpu)
204
204
BOARD_BUILD_VARIANT := $(call readboardsparam,build.variant)
205
 
BOARD_BUILD_CORE := $(call readboardsparam,build.core)
206
205
BOARD_UPLOAD_SPEED := $(call readboardsparam,upload.speed)
207
206
BOARD_UPLOAD_PROTOCOL := $(call readboardsparam,upload.protocol)
208
207
BOARD_USB_VID := $(call readboardsparam,build.vid)
239
238
$(error There is more than one .pde or .ino file in this directory!)
240
239
endif
241
240
 
242
 
# automatically determine sources and target
 
241
# automatically determine sources and targeet
243
242
TARGET := $(basename $(INOFILE))
244
243
SOURCES := $(INOFILE) \
245
 
        $(wildcard *.c *.cc *.cpp *.C *.s *.S) \
246
 
        $(wildcard $(addprefix util/, *.c *.cc *.cpp *.C *.s *.S)) \
247
 
        $(wildcard $(addprefix utility/, *.c *.cc *.cpp *.C *.s *.S))
248
 
 
249
 
# automatically determine library directories (to pull library sources in from)
250
 
# by matching included headers in poject sources to headers that exist in the
251
 
# roots of any library directories, giving priority to libraries in the order
252
 
# they're in LIBRARYPATH, and then to the alphabetically-greater named library
253
 
# (this is a really stupid way of doing it, but it's how the IDE works -- if
254
 
# it's causing problems, you can override it by setting LIBRARIES manually)
255
 
INCLUDEDHEADERS := \
256
 
        $(shell sed -nre "s/^\s*\#\s*include\s*[<\"](\S+\.h)[>\"].*/\1/p" \
257
 
        $(SOURCES))
258
 
reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) \
259
 
        $(firstword $(1))
260
 
LIBRARYHEADERS := $(foreach dir, $(LIBRARYPATH), \
261
 
        $(call reverse, $(sort $(wildcard $(dir)/*))))
262
 
LIBRARYHEADERS := $(foreach dir, $(LIBRARYHEADERS), $(wildcard $(dir)/*.h))
263
 
LIBRARYDIRS := $(foreach hdr, $(INCLUDEDHEADERS), $(patsubst %/$(hdr), %, \
264
 
        $(firstword $(filter %/$(hdr), $(LIBRARYHEADERS)))))
265
 
 
266
 
endif
267
 
 
268
 
# if LIBRARIES is specified, use it
269
 
ifneq "$(LIBRARIES)" ""
270
 
LIBRARYDIRS := $(foreach lib, $(LIBRARIES), \
271
 
        $(firstword $(wildcard $(addsuffix /$(lib), $(LIBRARYPATH)))))
 
244
        $(wildcard *.c *.cc *.cpp *.C) \
 
245
        $(wildcard $(addprefix util/, *.c *.cc *.cpp *.C)) \
 
246
        $(wildcard $(addprefix utility/, *.c *.cc *.cpp *.C))
 
247
 
 
248
# automatically determine included libraries
 
249
LIBRARIES := $(filter $(notdir $(wildcard $(addsuffix /*, $(LIBRARYPATH)))), \
 
250
        $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
 
251
 
272
252
endif
273
253
 
274
254
# software
277
257
CXX := $(call findsoftware,avr-g++)
278
258
LD := $(call findsoftware,avr-ld)
279
259
AR := $(call findsoftware,avr-ar)
280
 
AS := $(call findsoftware,avr-as)
281
260
OBJCOPY := $(call findsoftware,avr-objcopy)
282
261
AVRDUDE := $(call findsoftware,avrdude)
283
262
AVRSIZE := $(call findsoftware,avr-size)
284
263
 
285
264
# directories
286
 
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/$(BOARD_BUILD_CORE)
 
265
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
 
266
LIBRARYDIRS := $(foreach lib, $(LIBRARIES), \
 
267
        $(firstword $(wildcard $(addsuffix /$(lib), $(LIBRARYPATH)))))
287
268
LIBRARYDIRS += $(addsuffix /utility, $(LIBRARYDIRS))
288
269
 
289
270
# files
292
273
DEPFILES := $(patsubst %, .dep/%.dep, $(SOURCES))
293
274
ARDUINOLIB := .lib/arduino.a
294
275
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(LIBRARYDIRS), \
295
 
        $(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, \
296
 
                *.c *.cc *.cpp *.C *.s *.S))))
 
276
        $(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
297
277
BOOTLOADERHEX := $(addprefix \
298
278
        $(ARDUINODIR)/hardware/arduino/bootloaders/$(BOARD_BOOTLOADER_PATH)/, \
299
279
        $(BOARD_BOOTLOADER_FILE))
319
299
CPPDEPFLAGS = -MMD -MP -MF .dep/$<.dep
320
300
CPPINOFLAGS := -x c++ -include $(ARDUINOCOREDIR)/Arduino.h
321
301
AVRDUDEFLAGS += $(addprefix -C , $(AVRDUDECONF)) -DV
322
 
AVRDUDEFLAGS += -p$(BOARD_BUILD_MCU) -P$(SERIALDEV) -c$(BOARD_UPLOAD_PROTOCOL)
323
 
AVRDUDEFLAGS += $(addprefix -b, $(BOARD_UPLOAD_SPEED))
 
302
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
 
303
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
324
304
LINKFLAGS += -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
325
305
 
326
306
# figure out which arg to use with stty (for OS X, GNU and busybox stty)
416
396
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
417
397
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -lm -o $@
418
398
 
419
 
%.o: %.ino
420
 
        mkdir -p .dep/$(dir $<)
421
 
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
422
 
 
423
 
%.o: %.pde
424
 
        mkdir -p .dep/$(dir $<)
425
 
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
426
 
 
427
399
%.o: %.c
428
400
        mkdir -p .dep/$(dir $<)
429
401
        $(COMPILE.c) $(CPPDEPFLAGS) -o $@ $<
440
412
        mkdir -p .dep/$(dir $<)
441
413
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
442
414
 
443
 
%.o: %.S
444
 
        mkdir -p .dep/$(dir $<)
445
 
        $(COMPILE.S) $(CPPDEPFLAGS) -o $@ $<
 
415
%.o: %.ino
 
416
        mkdir -p .dep/$(dir $<)
 
417
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
 
418
 
 
419
%.o: %.pde
 
420
        mkdir -p .dep/$(dir $<)
 
421
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
446
422
 
447
423
# building the arduino library
448
424
 
465
441
        mkdir -p $(dir $@)
466
442
        $(COMPILE.cpp) -o $@ $<
467
443
 
468
 
.lib/%.s.o: %.s
469
 
        mkdir -p $(dir $@)
470
 
        $(COMPILE.s) -o $@ $<
471
 
 
472
 
.lib/%.S.o: %.S
473
 
        mkdir -p $(dir $@)
474
 
        $(COMPILE.S) -o $@ $<
475
 
 
476
444
# Local Variables:
477
445
# mode: makefile
478
446
# tab-width: 4