/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-11-23 17:30:45 UTC
  • Revision ID: tim@ed.am-20121123173045-2i2wk8ey4i6408z7
added packaging Makefile

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.4
6
6
#
7
 
# Copyright (C) 2011, 1012 Tim Marston <tim@ed.am>.
 
7
# Copyright (C) 2011, 2012 Tim Marston <tim@ed.am>.
8
8
#
9
9
# Permission is hereby granted, free of charge, to any person obtaining a copy
10
10
# of this software and associated documentation files (the "Software"), to deal
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
233
234
        $(shell sed -ne "s/$(BOARD).upload.speed=\(.*\)/\1/p" $(BOARDS_FILE))
234
235
BOARD_UPLOAD_PROTOCOL := \
235
236
        $(shell sed -ne "s/$(BOARD).upload.protocol=\(.*\)/\1/p" $(BOARDS_FILE))
 
237
BOARD_USB_VID := \
 
238
        $(shell sed -ne "s/$(BOARD).build.vid=\(.*\)/\1/p" $(BOARDS_FILE))
 
239
BOARD_USB_PID := \
 
240
        $(shell sed -ne "s/$(BOARD).build.pid=\(.*\)/\1/p" $(BOARDS_FILE))
236
241
 
237
242
# invalid board?
238
243
ifeq "$(BOARD_BUILD_MCU)" ""
244
249
endif
245
250
 
246
251
# 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)
 
252
CPPFLAGS := -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
 
253
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
 
254
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
 
255
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
 
256
CPPFLAGS += -DUSB_VID=$(BOARD_USB_VID) -DUSB_PID=$(BOARD_USB_PID)
 
257
CPPFLAGS += -I. -Iutil -Iutility -I $(ARDUINOCOREDIR)
 
258
CPPFLAGS += -I $(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
 
259
CPPFLAGS += $(addprefix -I $(ARDUINODIR)/libraries/, $(LIBRARIES))
 
260
CPPFLAGS += $(patsubst %, -I $(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
 
261
CPPDEPFLAGS = -MMD -MP -MF .dep/$<.dep
 
262
CPPINOFLAGS := -x c++ -include $(ARDUINOCOREDIR)/Arduino.h
256
263
AVRDUDEFLAGS := $(addprefix -C , $(AVRDUDECONF)) -DV
257
264
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
258
265
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
259
266
LINKFLAGS := -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
260
267
 
261
 
# figure out which arg to use with stty
262
 
STTYFARG := $(shell stty --help > /dev/null 2>&1 && echo -F || echo -f)
 
268
# figure out which arg to use with stty (for OS X, GNU and busybox stty)
 
269
STTYFARG := $(shell stty --help 2>&1 | \
 
270
        grep -q 'illegal option' && echo -f || echo -F)
 
271
 
 
272
# include dependencies
 
273
ifneq "$(MAKECMDGOALS)" "clean"
 
274
-include $(DEPFILES)
 
275
endif
263
276
 
264
277
# default rule
265
278
.DEFAULT_GOAL := all
273
286
 
274
287
target: $(TARGET).hex
275
288
 
276
 
upload:
 
289
upload: target
277
290
        @echo "\nUploading to board..."
278
291
        @test -n "$(SERIALDEV)" || { \
279
292
                echo "error: SERIALDEV could not be determined automatically." >&2; \
287
300
clean:
288
301
        rm -f $(OBJECTS)
289
302
        rm -f $(TARGET).elf $(TARGET).hex $(ARDUINOLIB) *~
290
 
        rm -rf .lib
 
303
        rm -rf .lib .dep
291
304
 
292
305
boards:
293
306
        @echo Available values for BOARD:
294
 
        @sed -ne '/^#/d;s/^\(.*\).name=\(.*\)/\1            \2/;T' \
295
 
                -e 's/\(.\{12\}\) *\(.*\)/\1 \2/;p' $(BOARDS_FILE)
 
307
        @sed -nEe '/^#/d; /^[^.]+\.name=/p' $(BOARDS_FILE) | \
 
308
                sed -Ee 's/([^.]+)\.name=(.*)/\1            \2/' \
 
309
                        -e 's/(.{12}) *(.*)/\1 \2/'
296
310
 
297
311
monitor:
298
312
        @test -n "$(SERIALDEV)" || { \
317
331
.INTERMEDIATE: $(TARGET).elf
318
332
 
319
333
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
320
 
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -o $@
321
 
 
322
 
#%.o: %.c
323
 
#       $(COMPILE.c) -o $@ $<
 
334
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -lm -o $@
 
335
 
 
336
%.o: %.c
 
337
        mkdir -p .dep/$(dir $<)
 
338
        $(COMPILE.c) $(CPPDEPFLAGS) -o $@ $<
 
339
 
 
340
%.o: %.cpp
 
341
        mkdir -p .dep/$(dir $<)
 
342
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
 
343
 
 
344
%.o: %.cc
 
345
        mkdir -p .dep/$(dir $<)
 
346
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
 
347
 
 
348
%.o: %.C
 
349
        mkdir -p .dep/$(dir $<)
 
350
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
324
351
 
325
352
%.o: %.ino
326
 
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
 
353
        mkdir -p .dep/$(dir $<)
 
354
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
327
355
 
328
356
%.o: %.pde
329
 
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
 
357
        mkdir -p .dep/$(dir $<)
 
358
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
330
359
 
331
360
# building the arduino library
332
361