~ubuntu-branches/ubuntu/precise/arduino/precise

« back to all changes in this revision

Viewing changes to .pc/makefile_libraries.diff/mjo/Arduino.mk

  • Committer: Bazaar Package Importer
  • Author(s): Scott Howard
  • Date: 2011-03-29 11:01:22 UTC
  • Revision ID: james.westby@ubuntu.com-20110329110122-geu3djqg7g0ovmqa
Tags: 0022+dfsg-3
* Moved all non-java bits to arduino-core (Closes: #613812)
* Edited Makefile to compile libraries during Makefile builds.
  - debian/patches/makefile_libraries.diff (Closes: #594191)
    Thanks to Stefan Tomanek
* debian/icons/* debian/arduino.xpm  New icons, thanks to Peter Oliver.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
########################################################################
 
2
#
 
3
# Arduino command line tools Makefile
 
4
# System part (i.e. project independent)
 
5
#
 
6
# Copyright (C) 2010 Martin Oldfield <m@mjo.tc>, based on work that is
 
7
# Copyright Nicholas Zambetti, David A. Mellis & Hernando Barragan
 
8
 
9
# This file is free software; you can redistribute it and/or modify it
 
10
# under the terms of the GNU Lesser General Public License as
 
11
# published by the Free Software Foundation; either version 2.1 of the
 
12
# License, or (at your option) any later version.
 
13
#
 
14
# Adapted from Arduino 0011 Makefile by M J Oldfield
 
15
#
 
16
# Original Arduino adaptation by mellis, eighthave, oli.keller
 
17
#
 
18
# Version 0.1  17.ii.2009  M J Oldfield
 
19
#
 
20
#         0.2  22.ii.2009  M J Oldfield
 
21
#                          - fixes so that the Makefile actually works!
 
22
#                          - support for uploading via ISP
 
23
#                          - orthogonal choices of using the Arduino for
 
24
#                            tools, libraries and uploading
 
25
#
 
26
#         0.3  21.v.2010   M J Oldfield
 
27
#                          - added proper license statement
 
28
#                          - added code from Philip Hands to reset
 
29
#                            Arduino prior to upload
 
30
#
 
31
#         0.4  25.v.2010   M J Oldfield
 
32
#                          - tweaked reset target on Philip Hands' advice
 
33
#
 
34
########################################################################
 
35
#
 
36
# STANDARD ARDUINO WORKFLOW
 
37
#
 
38
# Given a normal sketch directory, all you need to do is to create
 
39
# a small Makefile which defines a few things, and then includes this one.
 
40
#
 
41
# For example:
 
42
#
 
43
#       ARDUINO_DIR  = /usr/share/arduino
 
44
#
 
45
#       TARGET       = CLItest
 
46
#       ARDUINO_LIBS = LiquidCrystal
 
47
#
 
48
#       MCU          = atmega168
 
49
#       F_CPU        = 16000000
 
50
#       ARDUINO_PORT = /dev/cu.usb*
 
51
#
 
52
#       include /usr/local/share/Arduino.mk
 
53
#
 
54
# Hopefully these will be self-explanatory but in case they're not:
 
55
#
 
56
#    ARDUINO_DIR  - Where the Arduino software has been unpacked
 
57
#    TARGET       - The basename used for the final files. Canonically
 
58
#                   this would match the .pde file, but it's not needed
 
59
#                   here: you could always set it to xx if you wanted!
 
60
#    ARDUINO_LIBS - A list of any libraries used by the sketch (we assume
 
61
#                   these are in $(ARDUINO_DIR)/hardware/libraries
 
62
#    MCU,F_CPU    - The target processor description
 
63
#    ARDUINO_PORT - The port where the Arduino can be found (only needed
 
64
#                   when uploading
 
65
#
 
66
# Once this file has been created the typical workflow is just
 
67
#
 
68
#   $ make upload
 
69
#
 
70
# All of the object files are created in the build-cli subdirectory
 
71
# All sources should be in the current directory and can include:
 
72
#  - at most one .pde file which will be treated as C++ after the standard
 
73
#    Arduino header and footer have been affixed.
 
74
#  - any number of .c, .cpp, .s and .h files
 
75
#
 
76
#
 
77
# Besides make upload you can also
 
78
#   make            - no upload
 
79
#   make clean      - remove all our dependencies
 
80
#   make depends    - update dependencies
 
81
#   make reset      - reset the Arduino by tickling DTR on the serial port
 
82
#   make raw_upload - upload without first resetting
 
83
#
 
84
########################################################################
 
85
#
 
86
# ARDUINO WITH OTHER TOOLS
 
87
#
 
88
# If the tools aren't in the Arduino distribution, then you need to 
 
89
# specify their location:
 
90
#
 
91
#    AVR_TOOLS_PATH = /usr/bin
 
92
#    AVRDUDE_CONF   = /etc/avrdude/avrdude.conf
 
93
#
 
94
########################################################################
 
95
#
 
96
# ARDUINO WITH ISP
 
97
#
 
98
# You need to specify some details of your ISP programmer and might
 
99
# also need to specify the fuse values:
 
100
#
 
101
#     ISP_PROG     = -c stk500v2
 
102
#     ISP_PORT     = /dev/ttyACM0
 
103
#     
 
104
#     ISP_LOCK_FUSE_PRE  = 0x3f
 
105
#     ISP_LOCK_FUSE_POST = 0xcf
 
106
#     ISP_HIGH_FUSE      = 0xdf
 
107
#     ISP_LOW_FUSE       = 0xff
 
108
#     ISP_EXT_FUSE       = 0x01
 
109
#
 
110
# I think the fuses here are fine for uploading to the ATmega168
 
111
# without bootloader.
 
112
 
113
# To actually do this upload use the ispload target:
 
114
#
 
115
#    make ispload
 
116
#
 
117
#
 
118
########################################################################
 
119
# Some paths
 
120
#
 
121
 
 
122
ifneq (ARDUINO_DIR,)
 
123
 
 
124
ifndef AVR_TOOLS_PATH
 
125
AVR_TOOLS_PATH    = /usr/bin
 
126
endif
 
127
 
 
128
ifndef ARDUINO_ETC_PATH
 
129
ARDUINO_ETC_PATH  = /etc
 
130
endif
 
131
 
 
132
ifndef AVRDUDE_CONF
 
133
AVRDUDE_CONF     = $(ARDUINO_ETC_PATH)/avrdude.conf
 
134
endif
 
135
 
 
136
ARDUINO_LIB_PATH  = $(ARDUINO_DIR)/hardware/libraries
 
137
ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
 
138
 
 
139
endif
 
140
 
 
141
# Everything gets built in here
 
142
OBJDIR            = build-cli
 
143
 
 
144
########################################################################
 
145
# Local sources
 
146
#
 
147
LOCAL_C_SRCS    = $(wildcard *.c)
 
148
LOCAL_CPP_SRCS  = $(wildcard *.cpp)
 
149
LOCAL_CC_SRCS   = $(wildcard *.cc)
 
150
LOCAL_PDE_SRCS  = $(wildcard *.pde)
 
151
LOCAL_AS_SRCS   = $(wildcard *.S)
 
152
LOCAL_OBJ_FILES = $(LOCAL_C_SRCS:.c=.o) $(LOCAL_CPP_SRCS:.cpp=.o) \
 
153
                $(LOCAL_CC_SRCS:.cc=.o) $(LOCAL_PDE_SRCS:.pde=.o) \
 
154
                $(LOCAL_AS_SRCS:.S=.o)
 
155
LOCAL_OBJS      = $(patsubst %,$(OBJDIR)/%,$(LOCAL_OBJ_FILES))
 
156
 
 
157
# Dependency files
 
158
DEPS            = $(LOCAL_OBJS:.o=.d)
 
159
 
 
160
# core sources
 
161
ifeq ($(strip $(NO_CORE)),)
 
162
ifdef ARDUINO_CORE_PATH
 
163
CORE_C_SRCS     = $(wildcard $(ARDUINO_CORE_PATH)/*.c)
 
164
CORE_CPP_SRCS   = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp)
 
165
CORE_OBJ_FILES  = $(CORE_C_SRCS:.c=.o) $(CORE_CPP_SRCS:.cpp=.o)
 
166
CORE_OBJS       = $(patsubst $(ARDUINO_CORE_PATH)/%,  \
 
167
                        $(OBJDIR)/%,$(CORE_OBJ_FILES))
 
168
endif
 
169
endif
 
170
 
 
171
# all the objects!
 
172
OBJS            = $(LOCAL_OBJS) $(CORE_OBJS)
 
173
 
 
174
########################################################################
 
175
# Rules for making stuff
 
176
#
 
177
 
 
178
# The name of the main targets
 
179
TARGET_HEX = $(OBJDIR)/$(TARGET).hex
 
180
TARGET_ELF = $(OBJDIR)/$(TARGET).elf
 
181
TARGETS    = $(OBJDIR)/$(TARGET).*
 
182
 
 
183
# A list of dependencies
 
184
DEP_FILE   = $(OBJDIR)/depends.mk
 
185
 
 
186
# Names of executables
 
187
CC      = $(AVR_TOOLS_PATH)/avr-gcc
 
188
CXX     = $(AVR_TOOLS_PATH)/avr-g++
 
189
OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
 
190
OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
 
191
AR      = $(AVR_TOOLS_PATH)/avr-ar
 
192
SIZE    = $(AVR_TOOLS_PATH)/avr-size
 
193
NM      = $(AVR_TOOLS_PATH)/avr-nm
 
194
REMOVE  = rm -f
 
195
MV      = mv -f
 
196
CAT     = cat
 
197
ECHO    = echo
 
198
 
 
199
# General arguments
 
200
SYS_LIBS      = $(patsubst %,$(ARDUINO_LIB_PATH)/%,$(ARDUINO_LIBS))
 
201
SYS_INCLUDES  = $(patsubst %,-I%,$(SYS_LIBS))
 
202
SYS_OBJS      = $(wildcard $(patsubst %,%/*.o,$(SYS_LIBS)))
 
203
 
 
204
CPPFLAGS      = -mmcu=$(MCU) -DF_CPU=$(F_CPU) \
 
205
                        -I. -I$(ARDUINO_CORE_PATH) \
 
206
                        $(SYS_INCLUDES) -g -Os -w -Wall \
 
207
                        -ffunction-sections -fdata-sections
 
208
CFLAGS        = -std=gnu99
 
209
CXXFLAGS      = -fno-exceptions
 
210
ASFLAGS       = -mmcu=$(MCU) -I. -x assembler-with-cpp
 
211
LDFLAGS       = -mmcu=$(MCU) -lm -Wl,--gc-sections -Os
 
212
 
 
213
# Rules for making a CPP file from the main sketch (.cpe)
 
214
PDEHEADER     = \\\#include \"WProgram.h\"
 
215
 
 
216
# Expand and pick the first port
 
217
ARD_PORT      = $(firstword $(wildcard $(ARDUINO_PORT)))
 
218
 
 
219
# Implicit rules for building everything (needed to get everything in
 
220
# the right directory)
 
221
#
 
222
# Rather than mess around with VPATH there are quasi-duplicate rules
 
223
# here for building e.g. a system C++ file and a local C++
 
224
# file. Besides making things simpler now, this would also make it
 
225
# easy to change the build options in future
 
226
 
 
227
# normal local sources
 
228
# .o rules are for objects, .d for dependency tracking
 
229
# there seems to be an awful lot of duplication here!!!
 
230
$(OBJDIR)/%.o: %.c
 
231
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
 
232
 
 
233
$(OBJDIR)/%.o: %.cc
 
234
        $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
 
235
 
 
236
$(OBJDIR)/%.o: %.cpp
 
237
        $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
 
238
 
 
239
$(OBJDIR)/%.o: %.S
 
240
        $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
 
241
 
 
242
$(OBJDIR)/%.o: %.s
 
243
        $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
 
244
 
 
245
$(OBJDIR)/%.d: %.c
 
246
        $(CC) -MM $(CPPFLAGS) $(CFLAGS) $< -MF $@ -MT $(@:.d=.o)
 
247
 
 
248
$(OBJDIR)/%.d: %.cc
 
249
        $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)
 
250
 
 
251
$(OBJDIR)/%.d: %.cpp
 
252
        $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)
 
253
 
 
254
$(OBJDIR)/%.d: %.S
 
255
        $(CC) -MM $(CPPFLAGS) $(ASFLAGS) $< -MF $@ -MT $(@:.d=.o)
 
256
 
 
257
$(OBJDIR)/%.d: %.s
 
258
        $(CC) -MM $(CPPFLAGS) $(ASFLAGS) $< -MF $@ -MT $(@:.d=.o)
 
259
 
 
260
# the pde -> cpp -> o file
 
261
$(OBJDIR)/%.cpp: %.pde
 
262
        $(ECHO) $(PDEHEADER) > $@
 
263
        $(CAT)  $< >> $@
 
264
 
 
265
$(OBJDIR)/%.o: $(OBJDIR)/%.cpp
 
266
        $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
 
267
 
 
268
$(OBJDIR)/%.d: $(OBJDIR)/%.cpp
 
269
        $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)
 
270
 
 
271
# core files
 
272
$(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.c
 
273
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
 
274
 
 
275
$(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.cpp
 
276
        $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
 
277
 
 
278
# various object conversions
 
279
$(OBJDIR)/%.hex: $(OBJDIR)/%.elf
 
280
        $(OBJCOPY) -O ihex -R .eeprom $< $@
 
281
 
 
282
$(OBJDIR)/%.eep: $(OBJDIR)/%.elf
 
283
        -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
 
284
                --change-section-lma .eeprom=0 -O ihex $< $@
 
285
 
 
286
$(OBJDIR)/%.lss: $(OBJDIR)/%.elf
 
287
        $(OBJDUMP) -h -S $< > $@
 
288
 
 
289
$(OBJDIR)/%.sym: $(OBJDIR)/%.elf
 
290
        $(NM) -n $< > $@
 
291
 
 
292
########################################################################
 
293
#
 
294
# Avrdude
 
295
#
 
296
ifndef AVRDUDE
 
297
AVRDUDE          = $(AVR_TOOLS_PATH)/avrdude
 
298
endif
 
299
 
 
300
AVRDUDE_COM_OPTS = -q -V -p $(MCU)
 
301
ifdef AVRDUDE_CONF
 
302
AVRDUDE_COM_OPTS += -C $(AVRDUDE_CONF)
 
303
endif
 
304
 
 
305
ifndef AVRDUDE_ARD_PROGRAMMER
 
306
AVRDUDE_ARD_PROGRAMMER = stk500v1
 
307
endif
 
308
 
 
309
ifndef AVRDUDE_ARD_BAUDRATE
 
310
AVRDUDE_ARD_BAUDRATE   = 19200
 
311
endif
 
312
 
 
313
AVRDUDE_ARD_OPTS = -c $(AVRDUDE_ARD_PROGRAMMER) -b $(AVRDUDE_ARD_BAUDRATE) -P $(ARD_PORT) $(AVRDUDE_ARD_EXTRAOPTS)
 
314
 
 
315
ifndef ISP_LOCK_FUSE_PRE
 
316
ISP_LOCK_FUSE_PRE  = 0x3f
 
317
endif
 
318
 
 
319
ifndef ISP_LOCK_FUSE_POST
 
320
ISP_LOCK_FUSE_POST = 0xcf
 
321
endif
 
322
 
 
323
ifndef ISP_HIGH_FUSE
 
324
ISP_HIGH_FUSE      = 0xdf
 
325
endif
 
326
 
 
327
ifndef ISP_LOW_FUSE
 
328
ISP_LOW_FUSE       = 0xff
 
329
endif
 
330
 
 
331
ifndef ISP_EXT_FUSE
 
332
ISP_EXT_FUSE       = 0x01
 
333
endif
 
334
 
 
335
ifndef ISP_PROG
 
336
ISP_PROG           = -c stk500v2
 
337
endif
 
338
 
 
339
AVRDUDE_ISP_OPTS = -P $(ISP_PORT) $(ISP_PROG)
 
340
 
 
341
 
 
342
########################################################################
 
343
#
 
344
# Explicit targets start here
 
345
#
 
346
 
 
347
all:            $(OBJDIR) $(TARGET_HEX)
 
348
 
 
349
$(OBJDIR):
 
350
                mkdir $(OBJDIR)
 
351
 
 
352
$(TARGET_ELF):  $(OBJS)
 
353
                $(CC) $(LDFLAGS) -o $@ $(OBJS) $(SYS_OBJS)
 
354
 
 
355
$(DEP_FILE):    $(OBJDIR) $(DEPS)
 
356
                cat $(DEPS) > $(DEP_FILE)
 
357
 
 
358
upload:         reset raw_upload
 
359
 
 
360
raw_upload:     $(TARGET_HEX)
 
361
                $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \
 
362
                        -U flash:w:$(TARGET_HEX):i
 
363
 
 
364
# BSD stty likes -F, but GNU stty likes -f/--file.  Redirecting
 
365
# stdin/out appears to work but generates a spurious error on MacOS at
 
366
# least. Perhaps it would be better to just do it in perl ?
 
367
reset:          
 
368
                for STTYF in 'stty --file' 'stty -f' 'stty <' ; \
 
369
                  do $$STTYF /dev/tty >/dev/null 2>&1 && break ; \
 
370
                done ; \
 
371
                $$STTYF $(ARD_PORT)  hupcl ; \
 
372
                (sleep 0.1 2>/dev/null || sleep 1) ; \
 
373
                $$STTYF $(ARD_PORT) -hupcl 
 
374
 
 
375
ispload:        $(TARGET_HEX)
 
376
                $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e \
 
377
                        -U lock:w:$(ISP_LOCK_FUSE_PRE):m \
 
378
                        -U hfuse:w:$(ISP_HIGH_FUSE):m \
 
379
                        -U lfuse:w:$(ISP_LOW_FUSE):m \
 
380
                        -U efuse:w:$(ISP_EXT_FUSE):m
 
381
                $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -D \
 
382
                        -U flash:w:$(TARGET_HEX):i
 
383
                $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) \
 
384
                        -U lock:w:$(ISP_LOCK_FUSE_POST):m
 
385
 
 
386
clean:
 
387
                $(REMOVE) $(OBJS) $(TARGETS) $(DEP_FILE) $(DEPS)
 
388
 
 
389
depends:        $(DEPS)
 
390
                cat $(DEPS) > $(DEP_FILE)
 
391
 
 
392
.PHONY: all clean depends upload raw_upload reset
 
393
 
 
394
include $(DEP_FILE)