/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: edam
  • Date: 2012-03-20 22:17:57 UTC
  • Revision ID: tim@ed.am-20120320221757-zjmg92gkr8ojiioj
added dependency generation to project files

Show diffs side-by-side

added added

removed removed

197
197
# files
198
198
TARGET := $(if $(TARGET),$(TARGET),a.out)
199
199
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
 
200
DEPFILES := $(patsubst %, .dep/%.dep, $(SOURCES))
200
201
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
201
202
ARDUINOLIB := .lib/arduino.a
202
203
ARDUINOLIBLIBSDIR := $(ARDUINODIR)/libraries
244
245
endif
245
246
 
246
247
# flags
247
 
CPPFLAGS_S := -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
248
 
CPPFLAGS_S += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
249
 
CPPFLAGS_S += -mmcu=$(BOARD_BUILD_MCU)
250
 
CPPFLAGS_S += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
251
 
CPPFLAGS_S += -I. -Iutil -Iutility -I$(ARDUINOCOREDIR)
252
 
CPPFLAGS_S += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
253
 
CPPFLAGS_S += $(addprefix -I$(ARDUINODIR)/libraries/, $(LIBRARIES))
254
 
CPPFLAGS_S += $(patsubst %, -I$(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
255
 
CPPFLAGS = $(CPPFLAGS_S)
 
248
CPPFLAGS := -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
 
249
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
 
250
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
 
251
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
 
252
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOCOREDIR)
 
253
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
 
254
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/, $(LIBRARIES))
 
255
CPPFLAGS += $(patsubst %, -I$(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
 
256
CPPDEPFLAGS = -MMD -MP -MF .dep/$<.dep
 
257
CPPINOFLAGS := -x c++ -include $(ARDUINOCOREDIR)/Arduino.h
256
258
AVRDUDEFLAGS := $(addprefix -C , $(AVRDUDECONF)) -DV
257
259
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
258
260
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
261
263
# figure out which arg to use with stty
262
264
STTYFARG := $(shell stty --help > /dev/null 2>&1 && echo -F || echo -f)
263
265
 
 
266
# include dependencies
 
267
ifneq "$(MAKECMDGOALS)" "clean"
 
268
-include $(DEPFILES)
 
269
endif
 
270
 
264
271
# default rule
265
272
.DEFAULT_GOAL := all
266
273
 
287
294
clean:
288
295
        rm -f $(OBJECTS)
289
296
        rm -f $(TARGET).elf $(TARGET).hex $(ARDUINOLIB) *~
290
 
        rm -rf .lib
 
297
        rm -rf .lib .dep
291
298
 
292
299
boards:
293
300
        @echo Available values for BOARD:
319
326
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
320
327
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -o $@
321
328
 
322
 
#%.o: %.c
323
 
#       $(COMPILE.c) -o $@ $<
 
329
%.o: %.c
 
330
        mkdir -p .dep/$(dir $<)
 
331
        $(COMPILE.c) $(CPPDEPFLAGS) -o $@ $<
 
332
 
 
333
%.o: %.cpp
 
334
        mkdir -p .dep/$(dir $<)
 
335
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
 
336
 
 
337
%.o: %.cc
 
338
        mkdir -p .dep/$(dir $<)
 
339
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
 
340
 
 
341
%.o: %.C
 
342
        mkdir -p .dep/$(dir $<)
 
343
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
324
344
 
325
345
%.o: %.ino
326
 
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
 
346
        mkdir -p .dep/$(dir $<)
 
347
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
327
348
 
328
349
%.o: %.pde
329
 
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
 
350
        mkdir -p .dep/$(dir $<)
 
351
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
330
352
 
331
353
# building the arduino library
332
354