/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-07-18 17:53:47 UTC
  • Revision ID: tim@ed.am-20130718175347-wdihzmwz3n8u1due
remove TODO and added README

Show diffs side-by-side

added added

removed removed

239
239
$(error There is more than one .pde or .ino file in this directory!)
240
240
endif
241
241
 
242
 
# automatically determine sources and target
 
242
# automatically determine sources and targeet
243
243
TARGET := $(basename $(INOFILE))
244
244
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)))))
 
245
        $(wildcard *.c *.cc *.cpp *.C) \
 
246
        $(wildcard $(addprefix util/, *.c *.cc *.cpp *.C)) \
 
247
        $(wildcard $(addprefix utility/, *.c *.cc *.cpp *.C))
 
248
 
 
249
# automatically determine included libraries
 
250
LIBRARIES := $(filter $(notdir $(wildcard $(addsuffix /*, $(LIBRARYPATH)))), \
 
251
        $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
 
252
 
272
253
endif
273
254
 
274
255
# software
277
258
CXX := $(call findsoftware,avr-g++)
278
259
LD := $(call findsoftware,avr-ld)
279
260
AR := $(call findsoftware,avr-ar)
280
 
AS := $(call findsoftware,avr-as)
281
261
OBJCOPY := $(call findsoftware,avr-objcopy)
282
262
AVRDUDE := $(call findsoftware,avrdude)
283
263
AVRSIZE := $(call findsoftware,avr-size)
284
264
 
285
265
# directories
286
266
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/$(BOARD_BUILD_CORE)
 
267
LIBRARYDIRS := $(foreach lib, $(LIBRARIES), \
 
268
        $(firstword $(wildcard $(addsuffix /$(lib), $(LIBRARYPATH)))))
287
269
LIBRARYDIRS += $(addsuffix /utility, $(LIBRARYDIRS))
288
270
 
289
271
# files
292
274
DEPFILES := $(patsubst %, .dep/%.dep, $(SOURCES))
293
275
ARDUINOLIB := .lib/arduino.a
294
276
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(LIBRARYDIRS), \
295
 
        $(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, \
296
 
                *.c *.cc *.cpp *.C *.s *.S))))
 
277
        $(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
297
278
BOOTLOADERHEX := $(addprefix \
298
279
        $(ARDUINODIR)/hardware/arduino/bootloaders/$(BOARD_BOOTLOADER_PATH)/, \
299
280
        $(BOARD_BOOTLOADER_FILE))
416
397
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
417
398
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -lm -o $@
418
399
 
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
400
%.o: %.c
428
401
        mkdir -p .dep/$(dir $<)
429
402
        $(COMPILE.c) $(CPPDEPFLAGS) -o $@ $<
440
413
        mkdir -p .dep/$(dir $<)
441
414
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
442
415
 
443
 
%.o: %.S
444
 
        mkdir -p .dep/$(dir $<)
445
 
        $(COMPILE.S) $(CPPDEPFLAGS) -o $@ $<
 
416
%.o: %.ino
 
417
        mkdir -p .dep/$(dir $<)
 
418
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
 
419
 
 
420
%.o: %.pde
 
421
        mkdir -p .dep/$(dir $<)
 
422
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
446
423
 
447
424
# building the arduino library
448
425
 
465
442
        mkdir -p $(dir $@)
466
443
        $(COMPILE.cpp) -o $@ $<
467
444
 
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
445
# Local Variables:
477
446
# mode: makefile
478
447
# tab-width: 4