/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:57:12 UTC
  • Revision ID: tim@ed.am-20130718175712-nxoqb246mfgfh811
updated regex that detects #included libraries

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