/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-02-21 15:43:30 UTC
  • Revision ID: tim@ed.am-20120221154330-se8hali569whg99p
typos/spelling

Show diffs side-by-side

added added

removed removed

2
2
#
3
3
#                         edam's Arduino makefile
4
4
#_______________________________________________________________________________
5
 
#                                                                 version 0.3dev
 
5
#                                                                    version 0.3
6
6
#
7
7
# Copyright (C) 2011, 1012 Tim Marston <tim@ed.am>.
8
8
#
117
117
# when you run make:
118
118
#
119
119
# all          This is the default if no goal is specified.  It builds the
120
 
#              target.
 
120
#              target and uploads it.
121
121
#
122
122
# target       Builds the target.
123
123
#
131
131
# monitor      Start `screen` on the serial device.  This is meant to be an
132
132
#              equivalent to the Arduino serial monitor.
133
133
#
134
 
# size         Displays size information about the bulit target.
135
 
#
136
134
# <file>       Builds the specified file, either an object file or the target,
137
135
#              from those that that would be built for the project.
138
136
#_______________________________________________________________________________
171
169
        $(wildcard $(addprefix utility/, *.c *.cc *.cpp))
172
170
 
173
171
# automatically determine included libraries
174
 
LIBRARIES := $(filter $(notdir $(wildcard $(ARDUINODIR)/libraries/*)), \
 
172
ARDUINOLIBSAVAIL := $(notdir $(wildcard $(ARDUINODIR)/libraries/*))
 
173
LIBRARIES := $(filter $(ARDUINOLIBSAVAIL), \
175
174
        $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
176
175
 
177
176
endif
192
191
AR := $(call findsoftware,avr-ar)
193
192
OBJCOPY := $(call findsoftware,avr-objcopy)
194
193
AVRDUDE := $(call findsoftware,avrdude)
195
 
AVRSIZE := $(call findsoftware,avr-size)
196
194
 
197
195
# files
198
196
TARGET := $(if $(TARGET),$(TARGET),a.out)
199
197
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
200
 
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
201
 
ARDUINOLIB := .lib/arduino.a
202
 
ARDUINOLIBLIBSDIR := $(ARDUINODIR)/libraries
203
 
ARDUINOLIBLIBSPATH := $(foreach lib, $(LIBRARIES), \
204
 
        $(ARDUINODIR)/libraries/$(lib)/ $(ARDUINODIR)/libraries/$(lib)/utility/ )
205
 
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(ARDUINOLIBLIBSPATH), \
206
 
        $(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
 
198
ARDUINOSRCDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
 
199
ARDUINOLIBSDIR := $(ARDUINODIR)/libraries
 
200
ARDUINOLIB := _arduino.a
 
201
ARDUINOLIBTMP := $(ARDUINOLIB).tmp
 
202
ARDUINOLIBOBJS := $(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
 
203
        $(wildcard $(addprefix $(ARDUINOSRCDIR)/, *.c *.cpp)))))
 
204
ARDUINOLIBOBJS += $(foreach lib, $(LIBRARIES), \
 
205
        $(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
 
206
        $(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/, *.c *.cpp)) \
 
207
        $(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/utility/, *.c *.cpp)) ))))
207
208
ifeq "$(AVRDUDECONF)" ""
208
209
ifeq "$(AVRDUDE)" "$(ARDUINODIR)/hardware/tools/avr/bin/avrdude"
209
210
AVRDUDECONF := $(ARDUINODIR)/hardware/tools/avr/etc/avrdude.conf
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$(ARDUINOSRCDIR)
 
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
256
AVRDUDEFLAGS := $(addprefix -C , $(AVRDUDECONF)) -DV
257
257
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
258
258
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
267
267
#_______________________________________________________________________________
268
268
#                                                                          RULES
269
269
 
270
 
.PHONY: all target upload clean boards monitor size
 
270
.PHONY: all target upload clean boards monitor
271
271
 
272
 
all: target
 
272
all: target upload
273
273
 
274
274
target: $(TARGET).hex
275
275
 
287
287
clean:
288
288
        rm -f $(OBJECTS)
289
289
        rm -f $(TARGET).elf $(TARGET).hex $(ARDUINOLIB) *~
290
 
        rm -rf .lib
 
290
        rm -rf $(ARDUINOLIBTMP)
291
291
 
292
292
boards:
293
293
        @echo Available values for BOARD:
306
306
                echo; }
307
307
        screen $(SERIALDEV)
308
308
 
309
 
size: $(TARGET).elf
310
 
        echo && $(AVRSIZE) --format=avr --mcu=$(BOARD_BUILD_MCU) $(TARGET).elf
311
 
 
312
309
# building the target
313
310
 
314
311
$(TARGET).hex: $(TARGET).elf
319
316
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
320
317
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -o $@
321
318
 
322
 
#%.o: %.c
323
 
#       $(COMPILE.c) -o $@ $<
324
 
 
325
319
%.o: %.ino
326
 
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
 
320
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOSRCDIR)/Arduino.h $<
327
321
 
328
322
%.o: %.pde
329
 
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
 
323
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOSRCDIR)/Arduino.h $<
330
324
 
331
325
# building the arduino library
332
326
 
333
327
$(ARDUINOLIB): $(ARDUINOLIBOBJS)
334
328
        $(AR) rcs $@ $?
335
 
 
336
 
.lib/%.c.o: %.c
337
 
        mkdir -p $(dir $@)
338
 
        $(COMPILE.c) -o $@ $<
339
 
 
340
 
.lib/%.cpp.o: %.cpp
341
 
        mkdir -p $(dir $@)
342
 
        $(COMPILE.cpp) -o $@ $<
343
 
 
344
 
.lib/%.cc.o: %.cc
345
 
        mkdir -p $(dir $@)
346
 
        $(COMPILE.cpp) -o $@ $<
347
 
 
348
 
.lib/%.C.o: %.C
349
 
        mkdir -p $(dir $@)
 
329
        rm -rf $(ARDUINOLIBTMP)
 
330
 
 
331
.INTERMEDIATE: $(ARDUINOLIBOBJS)
 
332
 
 
333
$(ARDUINOLIBTMP)/%.o: $(ARDUINOSRCDIR)/%.c
 
334
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
 
335
        $(COMPILE.c) -o $@ $<
 
336
 
 
337
$(ARDUINOLIBTMP)/%.o: $(ARDUINOSRCDIR)/%.cpp
 
338
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
 
339
        $(COMPILE.cpp) -o $@ $<
 
340
 
 
341
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/%.c
 
342
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
 
343
        $(COMPILE.c) -o $@ $<
 
344
 
 
345
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/%.cpp
 
346
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
 
347
        $(COMPILE.cpp) -o $@ $<
 
348
 
 
349
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/utility/%.c
 
350
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
 
351
        $(COMPILE.c) -o $@ $<
 
352
 
 
353
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/utility/%.cpp
 
354
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
350
355
        $(COMPILE.cpp) -o $@ $<