3
# This makefile allows you to build sketches from the command line
4
# without the Arduino environment (or Java).
6
# The Arduino environment does preliminary processing on a sketch before
7
# compiling it. If you're using this makefile instead, you'll need to do
8
# a few things differently:
10
# - Give your program's file a .cpp extension (e.g. foo.cpp).
12
# - Put this line at top of your code: #include <WProgram.h>
14
# - Write prototypes for all your functions (or define them before you
15
# call them). A prototype declares the types of parameters a
16
# function will take and what type of value it will return. This
17
# means that you can have a call to a function before the definition
18
# of the function. A function prototype looks like the first line of
19
# the function, with a semi-colon at the end. For example:
20
# int digitalRead(int pin);
22
# Instructions for using the makefile:
24
# 1. Copy this file into the folder with your sketch.
26
# 2. Below, modify the line containing "TARGET" to refer to the name of
27
# of your program's file without an extension (e.g. TARGET = foo).
29
# 3. Modify the line containg "ARDUINO" to point the directory that
30
# contains the Arduino core (for normal Arduino installations, this
31
# is the hardware/cores/arduino sub-directory).
33
# 4. Modify the line containing "PORT" to refer to the filename
34
# representing the USB or serial connection to your Arduino board
35
# (e.g. PORT = /dev/tty.USB0). If the exact name of this file
36
# changes, you can use * as a wildcard (e.g. PORT = /dev/tty.USB*).
38
# 5. At the command line, change to the directory containing your
39
# program's file and the makefile.
41
# 6. Type "make" and press enter to compile/verify your program.
43
# 7. Type "make upload", reset your Arduino board, and press enter to
44
# upload your program to the Arduino board.
46
# $Id: Makefile,v 1.7 2007/04/13 05:28:23 eighthave Exp $
48
PORT = /dev/tty.usbserial-*
49
TARGET := $(shell pwd | sed 's|.*/\(.*\)|\1|')
50
ARDUINO = /Applications/arduino
51
ARDUINO_SRC = $(ARDUINO)/hardware/cores/arduino
52
ARDUINO_LIB_SRC = $(ARDUINO)/hardware/libraries
53
INCLUDE = -I$(ARDUINO_SRC) -I$(ARDUINO)/hardware/tools/avr/avr/include \
54
-I$(ARDUINO_LIB_SRC)/EEPROM \
55
-I$(ARDUINO_LIB_SRC)/Firmata \
56
-I$(ARDUINO_LIB_SRC)/Servo \
58
SRC = $(wildcard $(ARDUINO_SRC)/*.c)
59
CXXSRC = applet/$(TARGET).cpp $(ARDUINO_SRC)/HardwareSerial.cpp \
60
$(ARDUINO_LIB_SRC)/EEPROM/EEPROM.cpp \
61
$(ARDUINO_LIB_SRC)/Firmata/Firmata.cpp \
62
$(ARDUINO_LIB_SRC)/Servo/Servo.cpp \
63
$(ARDUINO_SRC)/WMath.cpp
64
HEADERS = $(wildcard $(ARDUINO_SRC)/*.h) $(wildcard $(ARDUINO_LIB_SRC)/*/*.h)
72
# Name of this Makefile (used for "make depend").
76
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
77
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
82
# Place -D or -U options here
83
CDEFS = -DF_CPU=$(F_CPU)
84
CXXDEFS = -DF_CPU=$(F_CPU)
86
# Compiler flag to set the C Standard level.
88
# gnu89 - c89 plus GCC extensions
89
# c99 - ISO C99 standard (not yet fully implemented)
90
# gnu99 - c99 plus GCC extensions
91
CSTANDARD = -std=gnu99
93
CWARN = -Wall -Wstrict-prototypes
94
CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
95
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
97
CFLAGS = $(CDEBUG) $(CDEFS) $(INCLUDE) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
98
CXXFLAGS = $(CDEFS) $(INCLUDE) -O$(OPT)
99
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
103
# Programming support using avrdude. Settings and variables.
104
AVRDUDE_PROGRAMMER = stk500
105
AVRDUDE_PORT = $(PORT)
106
AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex
107
AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
108
-b $(UPLOAD_RATE) -q -V
113
OBJCOPY = avr-objcopy
114
OBJDUMP = avr-objdump
121
# Define all object files.
122
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
124
# Define all listing files.
125
LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
127
# Combine all necessary flags and optional flags.
128
# Add target processor to flags.
129
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
130
ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS)
131
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
137
build: applet/$(TARGET).hex
139
eep: applet/$(TARGET).eep
140
lss: applet/$(TARGET).lss
141
sym: applet/$(TARGET).sym
144
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
145
COFFCONVERT=$(OBJCOPY) --debugging \
146
--change-section-address .data-0x800000 \
147
--change-section-address .bss-0x800000 \
148
--change-section-address .noinit-0x800000 \
149
--change-section-address .eeprom-0x810000
152
coff: applet/$(TARGET).elf
153
$(COFFCONVERT) -O coff-avr applet/$(TARGET).elf applet/$(TARGET).cof
156
extcoff: applet/$(TARGET).elf
157
$(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf applet/$(TARGET).cof
160
.SUFFIXES: .elf .hex .eep .lss .sym .pde
163
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
166
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
167
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
169
# Create extended listing file from ELF output file.
171
$(OBJDUMP) -h -S $< > $@
173
# Create a symbol table from ELF output file.
178
# Compile: create object files from C++ source files.
180
$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
182
# Compile: create object files from C source files.
184
$(CC) -c $(ALL_CFLAGS) $< -o $@
187
# Compile: create assembler files from C source files.
189
$(CC) -S $(ALL_CFLAGS) $< -o $@
192
# Assemble: create object files from assembler source files.
194
$(CC) -c $(ALL_ASFLAGS) $< -o $@
198
applet/$(TARGET).cpp: $(TARGET).pde
199
test -d applet || mkdir applet
200
echo '#include "WProgram.h"' > applet/$(TARGET).cpp
201
echo '#include "avr/interrupt.h"' >> applet/$(TARGET).cpp
202
sed -n 's|^\(void .*)\).*|\1;|p' $(TARGET).pde | grep -v 'setup()' | \
203
grep -v 'loop()' >> applet/$(TARGET).cpp
204
cat $(TARGET).pde >> applet/$(TARGET).cpp
205
cat $(ARDUINO_SRC)/main.cxx >> applet/$(TARGET).cpp
207
# Link: create ELF output file from object files.
208
applet/$(TARGET).elf: applet/$(TARGET).cpp $(OBJ)
209
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
212
echo 'close;' | /Applications/Pd-extended.app/Contents/Resources/bin/pdsend 34567 || true
214
# Program the device.
215
upload: applet/$(TARGET).hex
216
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
219
pd_test: build pd_close_serial upload
221
# Target: clean project.
223
$(REMOVE) -- applet/$(TARGET).hex applet/$(TARGET).eep \
224
applet/$(TARGET).cof applet/$(TARGET).elf $(TARGET).map \
225
applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp \
226
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
230
if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
232
sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
233
$(MAKEFILE).$$$$ && \
234
$(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
236
echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
238
$(CC) -M -mmcu=$(MCU) $(CDEFS) $(INCLUDE) $(SRC) $(ASRC) >> $(MAKEFILE)
240
.PHONY: all build eep lss sym coff extcoff clean depend pd_close_serial pd_test
244
make etags_`uname -s`
246
$(ARDUINO_SRC)/*.[ch] \
247
$(ARDUINO_SRC)/*.cpp \
248
$(ARDUINO_LIB_SRC)/*/*.[ch] \
249
$(ARDUINO_LIB_SRC)/*/*.cpp \
250
$(ARDUINO)/hardware/tools/avr/avr/include/avr/*.[ch] \
251
$(ARDUINO)/hardware/tools/avr/avr/include/*.[ch]
257
# etags -a /usr/include/*.h linux/input.h /usr/include/sys/*.h
260
# etags -a /usr/include/*.h /usr/include/sys/*.h