~ubuntu-branches/debian/experimental/arduino/experimental

« back to all changes in this revision

Viewing changes to debian/patches/mjo_makefile

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2012-03-11 18:19:42 UTC
  • mfrom: (1.1.5) (5.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120311181942-be2clnbz1gcehixb
Tags: 1:1.0.1~rc1+dfsg-1
New upstream release, experimental.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
From: Martin Oldfield <ex-atelier@mjo.tc>
2
 
Description: Unpack Martin Oldfield's arduino-mk tarball into mjo/
3
 
 This patch populates the mjo/ directory with the contents of the
4
 
 tarball published by Martin Oldfield.  Effectively this is
5
 
 upstream source, but from a different upstream than the main
6
 
 package.
7
 
Origin: other, http://mjo.tc/atelier/2009/02/arduino-cli.html
8
 
 
9
 
--- /dev/null
10
 
+++ b/mjo/README
11
 
@@ -0,0 +1 @@
12
 
+The contents of this directory originate from: http://mjo.tc/atelier/2009/02/arduino-cli.html
13
 
--- /dev/null
14
 
+++ b/mjo/Arduino.mk
15
 
@@ -0,0 +1,394 @@
16
 
+########################################################################
17
 
+#
18
 
+# Arduino command line tools Makefile
19
 
+# System part (i.e. project independent)
20
 
+#
21
 
+# Copyright (C) 2010 Martin Oldfield <m@mjo.tc>, based on work that is
22
 
+# Copyright Nicholas Zambetti, David A. Mellis & Hernando Barragan
23
 
+# 
24
 
+# This file is free software; you can redistribute it and/or modify it
25
 
+# under the terms of the GNU Lesser General Public License as
26
 
+# published by the Free Software Foundation; either version 2.1 of the
27
 
+# License, or (at your option) any later version.
28
 
+#
29
 
+# Adapted from Arduino 0011 Makefile by M J Oldfield
30
 
+#
31
 
+# Original Arduino adaptation by mellis, eighthave, oli.keller
32
 
+#
33
 
+# Version 0.1  17.ii.2009  M J Oldfield
34
 
+#
35
 
+#         0.2  22.ii.2009  M J Oldfield
36
 
+#                          - fixes so that the Makefile actually works!
37
 
+#                          - support for uploading via ISP
38
 
+#                          - orthogonal choices of using the Arduino for
39
 
+#                            tools, libraries and uploading
40
 
+#
41
 
+#         0.3  21.v.2010   M J Oldfield
42
 
+#                          - added proper license statement
43
 
+#                          - added code from Philip Hands to reset
44
 
+#                            Arduino prior to upload
45
 
+#
46
 
+#         0.4  25.v.2010   M J Oldfield
47
 
+#                          - tweaked reset target on Philip Hands' advice
48
 
+#
49
 
+########################################################################
50
 
+#
51
 
+# STANDARD ARDUINO WORKFLOW
52
 
+#
53
 
+# Given a normal sketch directory, all you need to do is to create
54
 
+# a small Makefile which defines a few things, and then includes this one.
55
 
+#
56
 
+# For example:
57
 
+#
58
 
+#       ARDUINO_DIR  = /Applications/arduino-0013
59
 
+#
60
 
+#       TARGET       = CLItest
61
 
+#       ARDUINO_LIBS = LiquidCrystal
62
 
+#
63
 
+#       MCU          = atmega168
64
 
+#       F_CPU        = 16000000
65
 
+#       ARDUINO_PORT = /dev/cu.usb*
66
 
+#
67
 
+#       include /usr/local/share/Arduino.mk
68
 
+#
69
 
+# Hopefully these will be self-explanatory but in case they're not:
70
 
+#
71
 
+#    ARDUINO_DIR  - Where the Arduino software has been unpacked
72
 
+#    TARGET       - The basename used for the final files. Canonically
73
 
+#                   this would match the .pde file, but it's not needed
74
 
+#                   here: you could always set it to xx if you wanted!
75
 
+#    ARDUINO_LIBS - A list of any libraries used by the sketch (we assume
76
 
+#                   these are in $(ARDUINO_DIR)/hardware/libraries
77
 
+#    MCU,F_CPU    - The target processor description
78
 
+#    ARDUINO_PORT - The port where the Arduino can be found (only needed
79
 
+#                   when uploading
80
 
+#
81
 
+# Once this file has been created the typical workflow is just
82
 
+#
83
 
+#   $ make upload
84
 
+#
85
 
+# All of the object files are created in the build-cli subdirectory
86
 
+# All sources should be in the current directory and can include:
87
 
+#  - at most one .pde file which will be treated as C++ after the standard
88
 
+#    Arduino header and footer have been affixed.
89
 
+#  - any number of .c, .cpp, .s and .h files
90
 
+#
91
 
+#
92
 
+# Besides make upload you can also
93
 
+#   make            - no upload
94
 
+#   make clean      - remove all our dependencies
95
 
+#   make depends    - update dependencies
96
 
+#   make reset      - reset the Arduino by tickling DTR on the serial port
97
 
+#   make raw_upload - upload without first resetting
98
 
+#
99
 
+########################################################################
100
 
+#
101
 
+# ARDUINO WITH OTHER TOOLS
102
 
+#
103
 
+# If the tools aren't in the Arduino distribution, then you need to 
104
 
+# specify their location:
105
 
+#
106
 
+#    AVR_TOOLS_PATH = /usr/bin
107
 
+#    AVRDUDE_CONF   = /etc/avrdude/avrdude.conf
108
 
+#
109
 
+########################################################################
110
 
+#
111
 
+# ARDUINO WITH ISP
112
 
+#
113
 
+# You need to specify some details of your ISP programmer and might
114
 
+# also need to specify the fuse values:
115
 
+#
116
 
+#     ISP_PROG    = -c stk500v2
117
 
+#     ISP_PORT     = /dev/ttyACM0
118
 
+#     
119
 
+#     ISP_LOCK_FUSE_PRE  = 0x3f
120
 
+#     ISP_LOCK_FUSE_POST = 0xcf
121
 
+#     ISP_HIGH_FUSE      = 0xdf
122
 
+#     ISP_LOW_FUSE       = 0xff
123
 
+#     ISP_EXT_FUSE       = 0x01
124
 
+#
125
 
+# I think the fuses here are fine for uploading to the ATmega168
126
 
+# without bootloader.
127
 
+# 
128
 
+# To actually do this upload use the ispload target:
129
 
+#
130
 
+#    make ispload
131
 
+#
132
 
+#
133
 
+########################################################################
134
 
+# Some paths
135
 
+#
136
 
+
137
 
+ifneq (ARDUINO_DIR,)
138
 
+
139
 
+ifndef AVR_TOOLS_PATH
140
 
+AVR_TOOLS_PATH    = $(ARDUINO_DIR)/hardware/tools/avr/bin
141
 
+endif
142
 
+
143
 
+ifndef ARDUINO_ETC_PATH
144
 
+ARDUINO_ETC_PATH  = $(ARDUINO_DIR)/hardware/tools/avr/etc
145
 
+endif
146
 
+
147
 
+ifndef AVRDUDE_CONF
148
 
+AVRDUDE_CONF     = $(ARDUINO_ETC_PATH)/avrdude.conf
149
 
+endif
150
 
+
151
 
+ARDUINO_LIB_PATH  = $(ARDUINO_DIR)/hardware/libraries
152
 
+ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
153
 
+
154
 
+endif
155
 
+
156
 
+# Everything gets built in here
157
 
+OBJDIR           = build-cli
158
 
+
159
 
+########################################################################
160
 
+# Local sources
161
 
+#
162
 
+LOCAL_C_SRCS    = $(wildcard *.c)
163
 
+LOCAL_CPP_SRCS  = $(wildcard *.cpp)
164
 
+LOCAL_CC_SRCS   = $(wildcard *.cc)
165
 
+LOCAL_PDE_SRCS  = $(wildcard *.pde)
166
 
+LOCAL_AS_SRCS   = $(wildcard *.S)
167
 
+LOCAL_OBJ_FILES = $(LOCAL_C_SRCS:.c=.o) $(LOCAL_CPP_SRCS:.cpp=.o) \
168
 
+               $(LOCAL_CC_SRCS:.cc=.o) $(LOCAL_PDE_SRCS:.pde=.o) \
169
 
+               $(LOCAL_AS_SRCS:.S=.o)
170
 
+LOCAL_OBJS      = $(patsubst %,$(OBJDIR)/%,$(LOCAL_OBJ_FILES))
171
 
+
172
 
+# Dependency files
173
 
+DEPS            = $(LOCAL_OBJS:.o=.d)
174
 
+
175
 
+# core sources
176
 
+ifeq ($(strip $(NO_CORE)),)
177
 
+ifdef ARDUINO_CORE_PATH
178
 
+CORE_C_SRCS     = $(wildcard $(ARDUINO_CORE_PATH)/*.c)
179
 
+CORE_CPP_SRCS   = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp)
180
 
+CORE_OBJ_FILES  = $(CORE_C_SRCS:.c=.o) $(CORE_CPP_SRCS:.cpp=.o)
181
 
+CORE_OBJS       = $(patsubst $(ARDUINO_CORE_PATH)/%,  \
182
 
+                       $(OBJDIR)/%,$(CORE_OBJ_FILES))
183
 
+endif
184
 
+endif
185
 
+
186
 
+# all the objects!
187
 
+OBJS            = $(LOCAL_OBJS) $(CORE_OBJS)
188
 
+
189
 
+########################################################################
190
 
+# Rules for making stuff
191
 
+#
192
 
+
193
 
+# The name of the main targets
194
 
+TARGET_HEX = $(OBJDIR)/$(TARGET).hex
195
 
+TARGET_ELF = $(OBJDIR)/$(TARGET).elf
196
 
+TARGETS    = $(OBJDIR)/$(TARGET).*
197
 
+
198
 
+# A list of dependencies
199
 
+DEP_FILE   = $(OBJDIR)/depends.mk
200
 
+
201
 
+# Names of executables
202
 
+CC      = $(AVR_TOOLS_PATH)/avr-gcc
203
 
+CXX     = $(AVR_TOOLS_PATH)/avr-g++
204
 
+OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
205
 
+OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
206
 
+AR      = $(AVR_TOOLS_PATH)/avr-ar
207
 
+SIZE    = $(AVR_TOOLS_PATH)/avr-size
208
 
+NM      = $(AVR_TOOLS_PATH)/avr-nm
209
 
+REMOVE  = rm -f
210
 
+MV      = mv -f
211
 
+CAT     = cat
212
 
+ECHO    = echo
213
 
+
214
 
+# General arguments
215
 
+SYS_LIBS      = $(patsubst %,$(ARDUINO_LIB_PATH)/%,$(ARDUINO_LIBS))
216
 
+SYS_INCLUDES  = $(patsubst %,-I%,$(SYS_LIBS))
217
 
+SYS_OBJS      = $(wildcard $(patsubst %,%/*.o,$(SYS_LIBS)))
218
 
+
219
 
+CPPFLAGS      = -mmcu=$(MCU) -DF_CPU=$(F_CPU) \
220
 
+                       -I. -I$(ARDUINO_CORE_PATH) \
221
 
+                       $(SYS_INCLUDES) -g -Os -w -Wall \
222
 
+                       -ffunction-sections -fdata-sections
223
 
+CFLAGS        = -std=gnu99
224
 
+CXXFLAGS      = -fno-exceptions
225
 
+ASFLAGS       = -mmcu=$(MCU) -I. -x assembler-with-cpp
226
 
+LDFLAGS       = -mmcu=$(MCU) -lm -Wl,--gc-sections -Os
227
 
+
228
 
+# Rules for making a CPP file from the main sketch (.cpe)
229
 
+PDEHEADER     = \\\#include \"WProgram.h\"
230
 
+
231
 
+# Expand and pick the first port
232
 
+ARD_PORT      = $(firstword $(wildcard $(ARDUINO_PORT)))
233
 
+
234
 
+# Implicit rules for building everything (needed to get everything in
235
 
+# the right directory)
236
 
+#
237
 
+# Rather than mess around with VPATH there are quasi-duplicate rules
238
 
+# here for building e.g. a system C++ file and a local C++
239
 
+# file. Besides making things simpler now, this would also make it
240
 
+# easy to change the build options in future
241
 
+
242
 
+# normal local sources
243
 
+# .o rules are for objects, .d for dependency tracking
244
 
+# there seems to be an awful lot of duplication here!!!
245
 
+$(OBJDIR)/%.o: %.c
246
 
+       $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
247
 
+
248
 
+$(OBJDIR)/%.o: %.cc
249
 
+       $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
250
 
+
251
 
+$(OBJDIR)/%.o: %.cpp
252
 
+       $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
253
 
+
254
 
+$(OBJDIR)/%.o: %.S
255
 
+       $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
256
 
+
257
 
+$(OBJDIR)/%.o: %.s
258
 
+       $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
259
 
+
260
 
+$(OBJDIR)/%.d: %.c
261
 
+       $(CC) -MM $(CPPFLAGS) $(CFLAGS) $< -MF $@ -MT $(@:.d=.o)
262
 
+
263
 
+$(OBJDIR)/%.d: %.cc
264
 
+       $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)
265
 
+
266
 
+$(OBJDIR)/%.d: %.cpp
267
 
+       $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)
268
 
+
269
 
+$(OBJDIR)/%.d: %.S
270
 
+       $(CC) -MM $(CPPFLAGS) $(ASFLAGS) $< -MF $@ -MT $(@:.d=.o)
271
 
+
272
 
+$(OBJDIR)/%.d: %.s
273
 
+       $(CC) -MM $(CPPFLAGS) $(ASFLAGS) $< -MF $@ -MT $(@:.d=.o)
274
 
+
275
 
+# the pde -> cpp -> o file
276
 
+$(OBJDIR)/%.cpp: %.pde
277
 
+       $(ECHO) $(PDEHEADER) > $@
278
 
+       $(CAT)  $< >> $@
279
 
+
280
 
+$(OBJDIR)/%.o: $(OBJDIR)/%.cpp
281
 
+       $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
282
 
+
283
 
+$(OBJDIR)/%.d: $(OBJDIR)/%.cpp
284
 
+       $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)
285
 
+
286
 
+# core files
287
 
+$(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.c
288
 
+       $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
289
 
+
290
 
+$(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.cpp
291
 
+       $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
292
 
+
293
 
+# various object conversions
294
 
+$(OBJDIR)/%.hex: $(OBJDIR)/%.elf
295
 
+       $(OBJCOPY) -O ihex -R .eeprom $< $@
296
 
+
297
 
+$(OBJDIR)/%.eep: $(OBJDIR)/%.elf
298
 
+       -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
299
 
+               --change-section-lma .eeprom=0 -O ihex $< $@
300
 
+
301
 
+$(OBJDIR)/%.lss: $(OBJDIR)/%.elf
302
 
+       $(OBJDUMP) -h -S $< > $@
303
 
+
304
 
+$(OBJDIR)/%.sym: $(OBJDIR)/%.elf
305
 
+       $(NM) -n $< > $@
306
 
+
307
 
+########################################################################
308
 
+#
309
 
+# Avrdude
310
 
+#
311
 
+ifndef AVRDUDE
312
 
+AVRDUDE          = $(AVR_TOOLS_PATH)/avrdude
313
 
+endif
314
 
+
315
 
+AVRDUDE_COM_OPTS = -q -V -p $(MCU)
316
 
+ifdef AVRDUDE_CONF
317
 
+AVRDUDE_COM_OPTS += -C $(AVRDUDE_CONF)
318
 
+endif
319
 
+
320
 
+ifndef AVRDUDE_ARD_PROGRAMMER
321
 
+AVRDUDE_ARD_PROGRAMMER = stk500v1
322
 
+endif
323
 
+
324
 
+ifndef AVRDUDE_ARD_BAUDRATE
325
 
+AVRDUDE_ARD_BAUDRATE   = 19200
326
 
+endif
327
 
+
328
 
+AVRDUDE_ARD_OPTS = -c $(AVRDUDE_ARD_PROGRAMMER) -b $(AVRDUDE_ARD_BAUDRATE) -P $(ARD_PORT)
329
 
+
330
 
+ifndef ISP_LOCK_FUSE_PRE
331
 
+ISP_LOCK_FUSE_PRE  = 0x3f
332
 
+endif
333
 
+
334
 
+ifndef ISP_LOCK_FUSE_POST
335
 
+ISP_LOCK_FUSE_POST = 0xcf
336
 
+endif
337
 
+
338
 
+ifndef ISP_HIGH_FUSE
339
 
+ISP_HIGH_FUSE      = 0xdf
340
 
+endif
341
 
+
342
 
+ifndef ISP_LOW_FUSE
343
 
+ISP_LOW_FUSE       = 0xff
344
 
+endif
345
 
+
346
 
+ifndef ISP_EXT_FUSE
347
 
+ISP_EXT_FUSE       = 0x01
348
 
+endif
349
 
+
350
 
+ifndef ISP_PROG
351
 
+ISP_PROG          = -c stk500v2
352
 
+endif
353
 
+
354
 
+AVRDUDE_ISP_OPTS = -P $(ISP_PORT) $(ISP_PROG)
355
 
+
356
 
+
357
 
+########################################################################
358
 
+#
359
 
+# Explicit targets start here
360
 
+#
361
 
+
362
 
+all:           $(OBJDIR) $(TARGET_HEX)
363
 
+
364
 
+$(OBJDIR):
365
 
+               mkdir $(OBJDIR)
366
 
+
367
 
+$(TARGET_ELF):         $(OBJS)
368
 
+               $(CC) $(LDFLAGS) -o $@ $(OBJS) $(SYS_OBJS)
369
 
+
370
 
+$(DEP_FILE):   $(OBJDIR) $(DEPS)
371
 
+               cat $(DEPS) > $(DEP_FILE)
372
 
+
373
 
+upload:                reset raw_upload
374
 
+
375
 
+raw_upload:    $(TARGET_HEX)
376
 
+               $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \
377
 
+                       -U flash:w:$(TARGET_HEX):i
378
 
+
379
 
+# stty on MacOS likes -F, but on Debian it likes -f redirecting
380
 
+# stdin/out appears to work but generates a spurious error on MacOS at
381
 
+# least. Perhaps it would be better to just do it in perl ?
382
 
+reset:         
383
 
+               for STTYF in 'stty --file' 'stty -f' 'stty <' ; \
384
 
+                 do $$STTYF /dev/tty >/dev/null 2>/dev/null && break ; \
385
 
+               done ;\
386
 
+               $$STTYF $(ARD_PORT)  hupcl ;\
387
 
+               (sleep 0.1 || sleep 1)     ;\
388
 
+               $$STTYF $(ARD_PORT) -hupcl 
389
 
+
390
 
+ispload:       $(TARGET_HEX)
391
 
+               $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e \
392
 
+                       -U lock:w:$(ISP_LOCK_FUSE_PRE):m \
393
 
+                       -U hfuse:w:$(ISP_HIGH_FUSE):m \
394
 
+                       -U lfuse:w:$(ISP_LOW_FUSE):m \
395
 
+                       -U efuse:w:$(ISP_EXT_FUSE):m
396
 
+               $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -D \
397
 
+                       -U flash:w:$(TARGET_HEX):i
398
 
+               $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) \
399
 
+                       -U lock:w:$(ISP_LOCK_FUSE_POST):m
400
 
+
401
 
+clean:
402
 
+               $(REMOVE) $(OBJS) $(TARGETS) $(DEP_FILE) $(DEPS)
403
 
+
404
 
+depends:       $(DEPS)
405
 
+               cat $(DEPS) > $(DEP_FILE)
406
 
+
407
 
+.PHONY:        all clean depends upload raw_upload reset
408
 
+
409
 
+include $(DEP_FILE)
410
 
--- /dev/null
411
 
+++ b/mjo/arduino-cli.html
412
 
@@ -0,0 +1,350 @@
413
 
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
414
 
+<html xmlns="http://www.w3.org/1999/xhtml">
415
 
+  <head>
416
 
+    <title>Martin's Atelier: Arduino from the command line</title>
417
 
+    <link rel="alternate" type="application/atom+xml" href="../../feed.atom" />   
418
 
+    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
419
 
+    <meta name="robots"      content="all" />
420
 
+    <meta name="author"      content="Martin Oldfield" />
421
 
+    <meta name="keywords"    content="Arduino command line Makefile" />
422
 
+    <meta name="description" content="" />    
423
 
+    <style type="text/css" media="all">@import "../../std.css";</style>
424
 
+    <style type="text/css" media="print">@import "../../print.css";</style>
425
 
+</head>
426
 
+
427
 
+  <body>
428
 
+    <div id="wrapper">
429
 
+      <div id="header">
430
 
+        <img id="logo_col" src="../../gears.png"/>
431
 
+        <img id="logo_bw"  src="../../gears_bw.png"/>
432
 
+        <h1>Arduino from the command line</h1>
433
 
+      </div>
434
 
+      <div id="main">
435
 
+        <h2>Update News</h2>
436
 
+
437
 
+<p>The current version of this software (0.4) won&#39;t work with versions of the Arduino software before 0018.</p>
438
 
+
439
 
+<h2>Introduction</h2>
440
 
+
441
 
+<p>The <a href="http://www.arduino.cc/">Arduino</a><span class="link_list"><sup>1</sup></span> has done much to popularize microcontrollers for the casual tinkerer. Its success suggests that there&#39;s considerable value in combining a standard microcontroller (the ATmega) and a <span class="caps">GCC </span>based toolchain into an easily digesible package. For myself, it&#39;s certainly easier to just install the latest release of the Arduino software than worry about building my own cross-compilers, particularly when it&#39;s all new to me and consequently somewhat confusing.</p>
442
 
+
443
 
+<p>After working through the toy tutorials though, I found myself wishing that writing code for the Arduino were more like writing other C programs. In my case, that means editing it with emacs then building it with make. I must emphasize that I&#39;m not criticizing the Arduino <span class="caps">IDE</span>: there&#39;s nothing wrong with it beyond it not being emacs...</p>
444
 
+
445
 
+<p>It turns out that others have been along this path before: the Arduino website has a hopeful sounding <a href="http://www.arduino.cc/en/Hacking/CommandLine">Arduino from the Command Line</a><span class="link_list"><sup>2</sup></span> article. In turn this points you at the Makefile shipped as part of the Arduino software distribution: hardware/cores/arduino/Makefile.</p>
446
 
+
447
 
+<p>This didn&#39;t really fit quite what I wanted to do though, so I wrote my own Makefile. You might wonder why I should embark on such a task. Well:</p>
448
 
+
449
 
+<ul>
450
 
+<li>I was keen that all of my objects and random other files were   completely separate from the main Arduino stuff in the applet   directory.</li>
451
 
+<li>Although I wanted to be able to build Arduino sketches, I also   wanted a suitable jumping-off point for code which didn&#39;t use   wiring. In other words, to regard the Arduino software as a   convenient way to get the <span class="caps">AVR GCC </span>toolchain.</li>
452
 
+<li>Rather than dumping a big Makefile in each sketch directory, I   wanted to have a few definitions in the directory which then   included a large project-independent file from elsewhere.</li>
453
 
+</ul>
454
 
+
455
 
+<p>Finally, one of the things I enjoy about writing code for microcontrollers is the sense of continuity between the hardware datasheets published by the chip manufacturer and the code I write (by contrast if you&#39;re writing code on Linux there&#39;s a vast gulf between the code executing printf and stuff appearing on the screen). Writing my own Makefile seemed a good way to make sure I understood what was going on.</p>
456
 
+
457
 
+<p>So to the Makefile. Obviously it owes a great debt to the people who wrote the Makefile shipped with the Arduino <span class="caps">IDE </span>and here&#39;s the credit list from that file:</p>
458
 
+
459
 
+<pre><code># Arduino 0011 Makefile                                  
460
 
+# Arduino adaptation by mellis, eighthave, oli.keller    </code></pre>
461
 
+
462
 
+<p>Thanks then to mellis, eighthavem and oli.keller.</p>
463
 
+
464
 
+<h2>Installation instructions</h2>
465
 
+
466
 
+<p>You&#39;ll need to download <a href="http://mjo.tc/atelier/2009/02/acli/arduino-mk_0.4.tar.gz">the tarball containing the Makefile,</a><span class="link_list"><sup>3</sup></span>, unpack it, and then copy the Makefile somewhere sensible:</p>
467
 
+
468
 
+<pre><code>$ wget http://mjo.tc/atelier/2009/02/acli/arduino-mk_0.4.tar.gz 
469
 
+$ tar xzvf arduino-mk_0.4.tar.gz 
470
 
+$ cp arduino-mk-0.4/Arduino.mk /path/to/my/arduino/stuff/Arduino.mk </code></pre>
471
 
+
472
 
+<p>The next step is to create a small Makefile for the sketch you actually want to build. The typical Arduino sketch directory looks like this:</p>
473
 
+
474
 
+<pre><code>$ ls -ltr  
475
 
+total 8    
476
 
+drwxr-xr-x   4 mjo  staff  136 15 Feb 19:53 applet        
477
 
+-rw-r--r--@  1 mjo  staff  384 17 Feb 16:11 CLItest.pde</code></pre>
478
 
+
479
 
+<p>To this we&#39;ll add a Makefile:</p>
480
 
+
481
 
+<pre><code>ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java 
482
 
+                                            
483
 
+TARGET       = CLItest                            
484
 
+MCU          = atmega168                          
485
 
+F_CPU        = 16000000                           
486
 
+ARDUINO_PORT = /dev/cu.usb*                       
487
 
+                                            
488
 
+ARDUINO_LIBS = LiquidCrystal              
489
 
+                                            
490
 
+include /path/to/my/arduino/stuff/Arduino.mk</code></pre>
491
 
+
492
 
+<p>Hopefully these will be self-explanatory but in case they&#39;re not:</p>
493
 
+
494
 
+<dl>
495
 
+<dt><span class="caps">ARDUINO</span>_DIR</dt>
496
 
+<dd>Where you installed the Arduino software. On the Mac this has to point deep inside the Arduino installation /Applications.  </dd>
497
 
+<dt><span class="caps">TARGET</span></dt>
498
 
+<dd>The basename used for the final files. Canonically            this would match the .pde file, but you can choose anything!        </dd>
499
 
+<dt><span class="caps">ARDUINO</span>_LIBS</dt>
500
 
+<dd>A list of any libraries used by the sketch&mdash;we assume  these are in $(ARDUINO_DIR)/hardware/libraries.                     </dd>
501
 
+<dt><span class="caps">MCU</span></dt>
502
 
+<dd>The target processor (atmega168 for the Duemilanove).           </dd>
503
 
+<dt>F_CPU</dt>
504
 
+<dd>The target&#39;s clock speed (16000000 for the Duemilanove).      </dd>
505
 
+<dt><span class="caps">ARDUINO</span>_PORT</dt>
506
 
+<dd>The port where the Arduino can be found (only needed when  uploading) If this expands to several ports, the first will be used.</dd>
507
 
+</dl>
508
 
+
509
 
+
510
 
+<p>A couple of other options might be useful:</p>
511
 
+
512
 
+<dl>
513
 
+<dt><span class="caps">AVRDUDE</span>_ARD_PROGRAMMER</dt>
514
 
+<dd>The protocol avrdude speaks&mdash;defaults to stk500v1.           </dd>
515
 
+<dt><span class="caps">AVRDUDE</span>_ARD_BAUDRATE</dt>
516
 
+<dd>The rate at which we talk to the board&mdash;defaults to 19,200.</dd>
517
 
+</dl>
518
 
+
519
 
+
520
 
+<p>If you&#39;re using the toolchain provided by the system rather than bundled with the Arduino software (as I think is the case on Linux) then you&#39;ll have to add some more paths:</p>
521
 
+
522
 
+<pre><code>AVR_TOOLS_PATH   = /usr/bin  
523
 
+AVRDUDE_CONF     = /etc/avrdude.conf</code></pre>
524
 
+
525
 
+<h2>Building</h2>
526
 
+
527
 
+<p>If you&#39;re used to Unix then this is easy:</p>
528
 
+
529
 
+<pre><code>$ make 
530
 
+...</code></pre>
531
 
+
532
 
+<p>The output is pretty verbose, but I think it should be obvious if it worked. After building you&#39;ll see a new directory has been created which contains all the object files: build-cli.</p>
533
 
+
534
 
+<pre><code>$ ls -l  
535
 
+total 32 
536
 
+-rw-r--r--@  1 mjo  staff  384 17 Feb 16:11 CLItest.pde  
537
 
+-rw-r--r--@  1 mjo  staff  202 17 Feb 16:39 Makefile     
538
 
+drwxr-xr-x   4 mjo  staff  136 15 Feb 19:53 applet       
539
 
+drwxr-xr-x  21 mjo  staff  714 17 Feb 17:52 build-cli    </code></pre>
540
 
+
541
 
+<h3>build-cli</h3>
542
 
+
543
 
+<p>Let&#39;s peek inside the build-cli directory:</p>
544
 
+
545
 
+<pre><code>$ ls -l build-cli 
546
 
+total 392 
547
 
+-rw-r--r--  1 mjo  staff    491 17 Feb 17:52 CLItest.cpp          
548
 
+-rw-r--r--  1 mjo  staff    583 17 Feb 17:52 CLItest.d            
549
 
+-rwxr-xr-x  1 mjo  staff  60971 17 Feb 17:52 CLItest.elf          
550
 
+-rw-r--r--  1 mjo  staff   3994 17 Feb 17:52 CLItest.hex          
551
 
+-rw-r--r--  1 mjo  staff   5932 17 Feb 17:52 CLItest.o            
552
 
+-rw-r--r--  1 mjo  staff   6920 17 Feb 17:52 HardwareSerial.o     
553
 
+-rw-r--r--  1 mjo  staff  12708 17 Feb 17:52 Print.o              
554
 
+-rw-r--r--  1 mjo  staff   6852 17 Feb 17:52 WInterrupts.o        
555
 
+-rw-r--r--  1 mjo  staff   4680 17 Feb 17:52 WMath.o              
556
 
+-rw-r--r--  1 mjo  staff    611 17 Feb 17:52 depends.mk           
557
 
+-rw-r--r--  1 mjo  staff   5900 17 Feb 17:52 pins_arduino.o       
558
 
+-rw-r--r--  1 mjo  staff   8476 17 Feb 17:52 wiring.o             
559
 
+-rw-r--r--  1 mjo  staff   7224 17 Feb 17:52 wiring_analog.o      
560
 
+-rw-r--r--  1 mjo  staff   8244 17 Feb 17:52 wiring_digital.o     
561
 
+-rw-r--r--  1 mjo  staff   6544 17 Feb 17:52 wiring_pulse.o       
562
 
+-rw-r--r--  1 mjo  staff   7424 17 Feb 17:52 wiring_serial.o      
563
 
+-rw-r--r--  1 mjo  staff   5308 17 Feb 17:52 wiring_shift.o       </code></pre>
564
 
+
565
 
+<p>Most of the files in here are object files for the wiring library. What about the others ?</p>
566
 
+
567
 
+<dl>
568
 
+<dt><span class="caps">CLI</span>test.cpp</dt>
569
 
+<dd>This is the .pde sketch file with a small main program prepended and a suitable #include prepended. </dd>
570
 
+<dt><span class="caps">CLI</span>test.d</dt>
571
 
+<dd>This tracks the dependencies used by <span class="caps">CLI</span>test.pde </dd>
572
 
+<dt><span class="caps">CLI</span>test.elf</dt>
573
 
+<dd>This is executable produced by the linker </dd>
574
 
+<dt><span class="caps">CLI</span>test.hex</dt>
575
 
+<dd>This is a hex dump of (the code part) of the executable  in a format understood by the Arduino&#39;s bootloader. </dd>
576
 
+<dt><span class="caps">CLI</span>test.o</dt>
577
 
+<dd>The object file we got by compiling <span class="caps">CLI</span>test.cpp. </dd>
578
 
+<dt>depends.mk</dt>
579
 
+<dd>A single file containing all the dependency relations  (it&#39;s the concatentation of all the .d files).</dd>
580
 
+</dl>
581
 
+
582
 
+
583
 
+<p>You may recall the <span class="caps">TARGET </span>variable we specified in the Makefile above: it&#39;s that which sets the base name for e.g. <span class="caps">CLI</span>test.elf. However <span class="caps">CLI</span>test.cpp, <span class="caps">CLI</span>test.o and <span class="caps">CLI</span>test.d take their name from the .pde sketch file.</p>
584
 
+
585
 
+<h2>Uploading code</h2>
586
 
+
587
 
+<p>This is easy:</p>
588
 
+
589
 
+<pre><code>$ make upload</code></pre>
590
 
+
591
 
+<h2>Uploading via <span class="caps">ISP</span></h2>
592
 
+
593
 
+<p>If you&#39;re using target hardware which doesn&#39;t have a bootloader then you might want to use <span class="caps">ISP </span>to upload the code. Though you&#39;ll obviously need some extra hardware to do this.</p>
594
 
+
595
 
+<p>Assuming that avrdude supports your programmer though, you&#39;ll only need to make a few changes to the Makefile to tell avrdude where it can find the programmer and how to talk to it:</p>
596
 
+
597
 
+<pre><code>ISP_PORT         = /dev/ttyACM0 
598
 
+ISP_PROG         = -c stk500v2</code></pre>
599
 
+
600
 
+<p>Then to upload:</p>
601
 
+
602
 
+<pre><code>$ make ispload</code></pre>
603
 
+
604
 
+<h3>Fuses</h3>
605
 
+
606
 
+<p>You might need to change the fuse settings when programming, though some care needs to be taken here or you might irreversibly change the chip. You can set the fuse settings thus (the values below are the defaults):</p>
607
 
+
608
 
+<pre><code>ISP_LOCK_FUSE_PRE  = 0x3f 
609
 
+ISP_LOCK_FUSE_POST = 0xcf 
610
 
+ISP_HIGH_FUSE      = 0xdf 
611
 
+ISP_LOW_FUSE       = 0xff 
612
 
+ISP_EXT_FUSE       = 0x01
613
 
+</code></pre>
614
 
+
615
 
+<h2>Growing the project</h2>
616
 
+
617
 
+<p>There a couple of obvious things to do now. You might want to edit the sketch. That&#39;s easy: just edit the .pde file and run make again.</p>
618
 
+
619
 
+<p>Alternatively you might want to add some more source files to the project. That&#39;s easy too: the Makefile understands C, C++ and assembler files in the source directory (with .c, .cpp, and .s extensions). Everything <strong>should</strong> just work.</p>
620
 
+
621
 
+
622
 
+
623
 
+<h2>Wiring-less development</h2>
624
 
+
625
 
+<p>Finally you might want to develop code which isn&#39;t linked against the Wiring library. There&#39;s some scope for this: just set NO_CORE in the Makefile e.g.</p>
626
 
+
627
 
+<pre><code>NO_CORE = 1</code></pre>
628
 
+
629
 
+<h2>Bugs and problems</h2>
630
 
+
631
 
+<ul>
632
 
+<li>The Makefile isn&#39;t very elegant.</li>
633
 
+<li>Handling Arduino libraries isn&#39;t very clean. For one thing I&#39;m   relying on them being compiled in a compatible way by the Arduino   environment which is probably a bit risky. Secondly it&#39;s a bit lazy   to get the user to specify which libraries are being used manually.</li>
634
 
+<li>When compiling the sketch file, the compiler actually sees the .cpp   file derived from it. Accordingly the line numbers of any errors   will be wrong (but not by that much).</li>
635
 
+<li>I fear that the Makefile makes unwarranted assumptions about the   hardware: for example, all my Arduino experience has been ATmega 168   related.</li>
636
 
+<li>The Makefile doesn&#39;t do some of the things that the Makefile   distributed with the Arduino software does e.g. generating <span class="caps">COFF   </span>files. I worry that some of these might be important.</li>
637
 
+<li>This hasn&#39;t been used very much yet, even by me. I&#39;m writing this   now as much for my benefit as anyone else&#39;s, though I&#39;d be delighted   to know if anyone else finds it useful.</li>
638
 
+</ul>
639
 
+
640
 
+<h2>Changelog</h2>
641
 
+
642
 
+<h3>2010-05-21, version 0.3</h3>
643
 
+
644
 
+<ul>
645
 
+<li>Tidied up the licensing, making it clear that it&#39;s released under <span class="caps">LGPL</span> 2.1.</li>
646
 
+<li><a href="http://hands.com/~phil/">Philip Hands</a><span class="link_list"><sup>4</sup></span> sent me some code to reset the   Arduino by dropping <span class="caps">DTR </span>for 100ms, and I added it.</li>
647
 
+<li>Tweaked the Makefile to handle version 0018 of the Arduino software   which now includes main.cpp. Accordingly we don&#39;t need to&mdash;and   indeed must not&mdash;add main.cxx to the .pde sketch file. The paths   seem to have changed a bit too.</li>
648
 
+</ul>
649
 
+
650
 
+<h3>2010-05-24, version 0.4</h3>
651
 
+
652
 
+<ul>
653
 
+<li>Tweaked rules for the reset target on Philip Hands&#39; advice. </li>
654
 
+</ul>
655
 
+        <div id="link_list">
656
 
+          <h2>References</h2>
657
 
+          <ul><li>1. http://www.arduino.cc/</li><li>2. http://www.arduino.cc/en/Hacking/CommandLine</li><li>3. http://mjo.tc/atelier/2009/02/acli/arduino-mk_0.4.tar.gz</li><li>4. http://hands.com/~phil/</li></ul>
658
 
+        </div>      </div>
659
 
+           
660
 
+      <div id="sidebar">
661
 
+        <div class="listcontainer">
662
 
+          <h2><a href="../../index/index.html">Martin's Atelier</a></h2>
663
 
+          <div id="subscribe"><p><a href="../../feed.atom"><img src="../../atom.png" alt="[ Atom Feed ]" title="Atom Feed" /></a></p></div>
664
 
+        </div>
665
 
+        
666
 
+        
667
 
+        <div class="listcontainer">        
668
 
+          <h3>Related Articles</h3>
669
 
+          <ul>
670
 
+            
671
 
+            <li><a href="../03/aarduino.html">The AArduino</a><br/>Martin Oldfield, 16 Jun 2009</li>
672
 
+            
673
 
+            <li><a href="avrdude-cookbook.html">Avrdude Cookbook</a><br/>Martin Oldfield, 23 Feb 2009</li>
674
 
+            
675
 
+            <li><a href="olimex-avrdude-mac.html">MacOS X and the Olimex AVR-ISP500</a><br/>Martin Oldfield, 17 Feb 2009</li>
676
 
+            
677
 
+          </ul>
678
 
+        </div>
679
 
+        
680
 
+  
681
 
+        
682
 
+        <div class="listcontainer">        
683
 
+          <h3><a href="../../index/st_subject.html">Related Subjects</a></h3>
684
 
+          <ul>
685
 
+            
686
 
+            <li><a href="../../index/t_Arduino.html">Arduino</a></li>
687
 
+            
688
 
+            <li><a href="../../index/t_command line.html">command line</a></li>
689
 
+            
690
 
+            <li><a href="../../index/t_Makefile.html">Makefile</a></li>
691
 
+            
692
 
+          </ul>
693
 
+        </div>
694
 
+        
695
 
+
696
 
+        
697
 
+        <div class="listcontainer">        
698
 
+          <h3><a href="../../index/index.html">Other Articles</a></h3>
699
 
+          <ul>
700
 
+            
701
 
+            <li><a href="../../2010/06/arm-toolchain.html">Getting an ARM toolchain on MacOS 10.6</a><br/>Martin Oldfield, 06 Jun 2010</li>
702
 
+            
703
 
+            <li><a href="../../2010/05/bus-pirate.html">The Bus Pirate on MacOS</a><br/>Martin Oldfield, 26 May 2010</li>
704
 
+            
705
 
+            <li><a href="../../2010/04/perl-unicode.html">Unicode games with perl, MySQL, and XML</a><br/>Martin Oldfield, 17 Apr 2010</li>
706
 
+            
707
 
+            <li><a href="../../2010/01/gps-track-filter.html">Filtering GPS tracks</a><br/>Martin Oldfield, 04 Jan 2010</li>
708
 
+            
709
 
+            <li><a href="../01/paris_drink.html">Places to drink in Paris</a><br/>Martin Oldfield, 15 Dec 2009</li>
710
 
+            
711
 
+            <li><a href="../01/paris_food.html">Places to eat in Paris</a><br/>Martin Oldfield, 15 Dec 2009</li>
712
 
+            
713
 
+            <li><a href="../11/sons-and-daughters.html">Sons and Daughters</a><br/>Martin Oldfield, 06 Dec 2009</li>
714
 
+            
715
 
+            <li><a href="../12/garmin-gpx.html">Faking geocaches in Garmin GPX files</a><br/>Martin Oldfield, 06 Dec 2009</li>
716
 
+            
717
 
+            <li><a href="../08/macos-pic.html">Playing with PICs on MacOS X</a><br/>Martin Oldfield, 18 Aug 2009</li>
718
 
+            
719
 
+            <li>...</li>
720
 
+          </ul>
721
 
+        </div>
722
 
+        
723
 
+
724
 
+        
725
 
+        <div class="lastlistcontainer">
726
 
+          <h3>Bookmark this article</h3>
727
 
+        <ul class="social">
728
 
+          
729
 
+          <li><a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fmjo.tc%2Fatelier%2F2009%2F02%2Farduino-cli.html" title="Facebook"><img src="../../social/facebook.png" alt="[ facebook ]"/></a></li>
730
 
+          
731
 
+          <li><a href="http://del.icio.us/post?url=http%3A%2F%2Fmjo.tc%2Fatelier%2F2009%2F02%2Farduino-cli.html&title=Arduino+from+the+command+line" title="Delicious"><img src="../../social/delicious.png" alt="[ delicious ]"/></a></li>
732
 
+          
733
 
+          <li><a href="http://digg.com/submit?url=http%3A%2F%2Fmjo.tc%2Fatelier%2F2009%2F02%2Farduino-cli.html&title=Arduino+from+the+command+line" title="Digg"><img src="../../social/digg.png" alt="[ digg ]"/></a></li>
734
 
+          
735
 
+          <li><a href="http://reddit.com/submit?url=http%3A%2F%2Fmjo.tc%2Fatelier%2F2009%2F02%2Farduino-cli.html&title=Arduino+from+the+command+line" title="Reddit"><img src="../../social/reddit.png" alt="[ reddit ]"/></a></li>
736
 
+          
737
 
+          <li><a href="http://www.stumbleupon.com?url=http%3A%2F%2Fmjo.tc%2Fatelier%2F2009%2F02%2Farduino-cli.html&title=Arduino+from+the+command+line" title="Stumbleupon"><img src="../../social/stumbleupon.png" alt="[ stumbleupon ]"/></a></li>
738
 
+          
739
 
+        </ul>
740
 
+        </div>
741
 
+        
742
 
+
743
 
+        </div>
744
 
+
745
 
+        <div id="footer">
746
 
+          Revised by Martin Oldfield on 07 Jun 2010, original version 17 Feb 2009.<br/>
747
 
+          Contact: Martin Oldfield, ex-atelier@mjo.tc<br/>
748
 
+          This work is available under the <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>, or the <a href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</a> version 2.1 or later.
749
 
+       </div>
750
 
+
751
 
+        </div>
752
 
+        
753
 
+    </div>
754
 
+    <script src="http://www.google-analytics.com/urchin.js"
755
 
+    type="text/javascript">
756
 
+    </script>
757
 
+    <script type="text/javascript">
758
 
+    _uacct = "UA-567180-1";
759
 
+    urchinTracker();
760
 
+    </script>
761
 
+  </body>
762
 
+</html>