/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-10-19 16:35:44 UTC
  • Revision ID: tim@ed.am-20121019163544-zqt3v12zwuaivccr
fixed check for stty switch, so that it works with busybox

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
#
180
180
SERIALDEVGUESS := 0
181
181
ifeq "$(SERIALDEV)" ""
182
182
SERIALDEV := $(firstword $(wildcard \
183
 
        /dev/ttyACM? /dev/ttyUSB? /dev/tty.usbmodem*))
 
183
        /dev/ttyACM? /dev/ttyUSB? /dev/tty.usbserial* /dev/tty.usbmodem*))
184
184
SERIALDEVGUESS := 1
185
185
endif
186
186
 
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)
259
261
LINKFLAGS := -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
260
262
 
261
 
# figure out which arg to use with stty
262
 
STTYFARG := $(shell stty --help > /dev/null 2>&1 && echo -F || echo -f)
 
263
# figure out which arg to use with stty (for OS X, GNU and busybox stty)
 
264
STTYFARG := $(shell stty --help 2>&1 | \
 
265
        grep -q 'illegal option' && echo -f || echo -F)
 
266
 
 
267
# include dependencies
 
268
ifneq "$(MAKECMDGOALS)" "clean"
 
269
-include $(DEPFILES)
 
270
endif
263
271
 
264
272
# default rule
265
273
.DEFAULT_GOAL := all
273
281
 
274
282
target: $(TARGET).hex
275
283
 
276
 
upload:
 
284
upload: target
277
285
        @echo "\nUploading to board..."
278
286
        @test -n "$(SERIALDEV)" || { \
279
287
                echo "error: SERIALDEV could not be determined automatically." >&2; \
287
295
clean:
288
296
        rm -f $(OBJECTS)
289
297
        rm -f $(TARGET).elf $(TARGET).hex $(ARDUINOLIB) *~
290
 
        rm -rf .lib
 
298
        rm -rf .lib .dep
291
299
 
292
300
boards:
293
301
        @echo Available values for BOARD:
294
 
        @sed -ne '/^#/d;s/^\(.*\).name=\(.*\)/\1            \2/;T' \
295
 
                -e 's/\(.\{12\}\) *\(.*\)/\1 \2/;p' $(BOARDS_FILE)
 
302
        @sed -nEe '/^#/d; /^[^.]+\.name=/p' $(BOARDS_FILE) | \
 
303
                sed -Ee 's/([^.]+)\.name=(.*)/\1            \2/' \
 
304
                        -e 's/(.{12}) *(.*)/\1 \2/'
296
305
 
297
306
monitor:
298
307
        @test -n "$(SERIALDEV)" || { \
319
328
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
320
329
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -o $@
321
330
 
322
 
#%.o: %.c
323
 
#       $(COMPILE.c) -o $@ $<
 
331
%.o: %.c
 
332
        mkdir -p .dep/$(dir $<)
 
333
        $(COMPILE.c) $(CPPDEPFLAGS) -o $@ $<
 
334
 
 
335
%.o: %.cpp
 
336
        mkdir -p .dep/$(dir $<)
 
337
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
 
338
 
 
339
%.o: %.cc
 
340
        mkdir -p .dep/$(dir $<)
 
341
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
 
342
 
 
343
%.o: %.C
 
344
        mkdir -p .dep/$(dir $<)
 
345
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
324
346
 
325
347
%.o: %.ino
326
 
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
 
348
        mkdir -p .dep/$(dir $<)
 
349
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
327
350
 
328
351
%.o: %.pde
329
 
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
 
352
        mkdir -p .dep/$(dir $<)
 
353
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
330
354
 
331
355
# building the arduino library
332
356