/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock

« back to all changes in this revision

Viewing changes to arduino.mk

  • Committer: Tim Marston
  • Date: 2013-03-31 17:07:36 UTC
  • Revision ID: tim@ed.am-20130331170736-hphm2hg0y6l7w6z1
made rtc-test's DS1307 library a symlink to the main one in src/util

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.4dev
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 and uploads it.
 
120
#              target.
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
#
134
136
# <file>       Builds the specified file, either an object file or the target,
135
137
#              from those that that would be built for the project.
136
138
#_______________________________________________________________________________
169
171
        $(wildcard $(addprefix utility/, *.c *.cc *.cpp))
170
172
 
171
173
# automatically determine included libraries
172
 
ARDUINOLIBSAVAIL := $(notdir $(wildcard $(ARDUINODIR)/libraries/*))
173
 
LIBRARIES := $(filter $(ARDUINOLIBSAVAIL), \
 
174
LIBRARIES := $(filter $(notdir $(wildcard $(ARDUINODIR)/libraries/*)), \
174
175
        $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
175
176
 
176
177
endif
179
180
SERIALDEVGUESS := 0
180
181
ifeq "$(SERIALDEV)" ""
181
182
SERIALDEV := $(firstword $(wildcard \
182
 
        /dev/ttyACM? /dev/ttyUSB? /dev/tty.usbmodem*))
 
183
        /dev/ttyACM? /dev/ttyUSB? /dev/tty.usbserial* /dev/tty.usbmodem*))
183
184
SERIALDEVGUESS := 1
184
185
endif
185
186
 
191
192
AR := $(call findsoftware,avr-ar)
192
193
OBJCOPY := $(call findsoftware,avr-objcopy)
193
194
AVRDUDE := $(call findsoftware,avrdude)
 
195
AVRSIZE := $(call findsoftware,avr-size)
194
196
 
195
197
# files
196
198
TARGET := $(if $(TARGET),$(TARGET),a.out)
197
199
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
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)) ))))
 
200
DEPFILES := $(patsubst %, .dep/%.dep, $(SOURCES))
 
201
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
 
202
ARDUINOLIB := .lib/arduino.a
 
203
ARDUINOLIBLIBSDIR := $(ARDUINODIR)/libraries
 
204
ARDUINOLIBLIBSPATH := $(foreach lib, $(LIBRARIES), \
 
205
        $(ARDUINODIR)/libraries/$(lib)/ $(ARDUINODIR)/libraries/$(lib)/utility/ )
 
206
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(ARDUINOLIBLIBSPATH), \
 
207
        $(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
208
208
ifeq "$(AVRDUDECONF)" ""
209
209
ifeq "$(AVRDUDE)" "$(ARDUINODIR)/hardware/tools/avr/bin/avrdude"
210
210
AVRDUDECONF := $(ARDUINODIR)/hardware/tools/avr/etc/avrdude.conf
249
249
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
250
250
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
251
251
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
252
 
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOSRCDIR)
 
252
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOCOREDIR)
253
253
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
254
254
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/, $(LIBRARIES))
255
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
 
267
274
#_______________________________________________________________________________
268
275
#                                                                          RULES
269
276
 
270
 
.PHONY: all target upload clean boards monitor
 
277
.PHONY: all target upload clean boards monitor size
271
278
 
272
 
all: target upload
 
279
all: target
273
280
 
274
281
target: $(TARGET).hex
275
282
 
276
 
upload:
 
283
upload: target
277
284
        @echo "\nUploading to board..."
278
285
        @test -n "$(SERIALDEV)" || { \
279
286
                echo "error: SERIALDEV could not be determined automatically." >&2; \
287
294
clean:
288
295
        rm -f $(OBJECTS)
289
296
        rm -f $(TARGET).elf $(TARGET).hex $(ARDUINOLIB) *~
290
 
        rm -rf $(ARDUINOLIBTMP)
 
297
        rm -rf .lib .dep
291
298
 
292
299
boards:
293
300
        @echo Available values for BOARD:
294
 
        @sed -ne '/^#/d;s/^\(.*\).name=\(.*\)/\1            \2/;T' \
295
 
                -e 's/\(.\{12\}\) *\(.*\)/\1 \2/;p' $(BOARDS_FILE)
 
301
        @sed -ne '/^#/d; /^[^.]\+\.name=/p' $(BOARDS_FILE) | \
 
302
                sed -e 's/\([^.]\+\)\.name=\(.*\)/\1            \2/' \
 
303
                        -e 's/\(.\{12\}\) *\(.*\)/\1 \2/'
296
304
 
297
305
monitor:
298
306
        @test -n "$(SERIALDEV)" || { \
306
314
                echo; }
307
315
        screen $(SERIALDEV)
308
316
 
 
317
size: $(TARGET).elf
 
318
        echo && $(AVRSIZE) --format=avr --mcu=$(BOARD_BUILD_MCU) $(TARGET).elf
 
319
 
309
320
# building the target
310
321
 
311
322
$(TARGET).hex: $(TARGET).elf
316
327
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
317
328
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -o $@
318
329
 
 
330
%.o: %.c
 
331
        mkdir -p .dep/$(dir $<)
 
332
        $(COMPILE.c) $(CPPDEPFLAGS) -o $@ $<
 
333
 
 
334
%.o: %.cpp
 
335
        mkdir -p .dep/$(dir $<)
 
336
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
 
337
 
 
338
%.o: %.cc
 
339
        mkdir -p .dep/$(dir $<)
 
340
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
 
341
 
 
342
%.o: %.C
 
343
        mkdir -p .dep/$(dir $<)
 
344
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
 
345
 
319
346
%.o: %.ino
320
 
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOSRCDIR)/Arduino.h $<
 
347
        mkdir -p .dep/$(dir $<)
 
348
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
321
349
 
322
350
%.o: %.pde
323
 
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOSRCDIR)/Arduino.h $<
 
351
        mkdir -p .dep/$(dir $<)
 
352
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
324
353
 
325
354
# building the arduino library
326
355
 
327
356
$(ARDUINOLIB): $(ARDUINOLIBOBJS)
328
357
        $(AR) rcs $@ $?
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)
 
358
 
 
359
.lib/%.c.o: %.c
 
360
        mkdir -p $(dir $@)
 
361
        $(COMPILE.c) -o $@ $<
 
362
 
 
363
.lib/%.cpp.o: %.cpp
 
364
        mkdir -p $(dir $@)
 
365
        $(COMPILE.cpp) -o $@ $<
 
366
 
 
367
.lib/%.cc.o: %.cc
 
368
        mkdir -p $(dir $@)
 
369
        $(COMPILE.cpp) -o $@ $<
 
370
 
 
371
.lib/%.C.o: %.C
 
372
        mkdir -p $(dir $@)
355
373
        $(COMPILE.cpp) -o $@ $<