/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-19 15:34:42 UTC
  • Revision ID: tim@ed.am-20130719153442-lxcq6bdvcojaveub
detect which libraries to pull in the same way as the IDE; fixes 3

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