/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: 2011-12-29 13:52:05 UTC
  • Revision ID: edam@waxworlds.org-20111229135205-ppyojdxqty9sdikj
initial commit

Show diffs side-by-side

added added

removed removed

29
29
#
30
30
# This is a general purpose makefile for use with Arduino (arduino.cc)
31
31
# hardware and software.  It works with the arduino-1.0 release and
32
 
# requires that to be downloaded separately.  It can be downloaded
33
 
# from http://ed.am/dev/make/arduino-makefile where you can also find
34
 
# more information and documentation on it's use.  The following text
35
 
# can only really be considered a reference to it's use.
 
32
# requires that to be downloaded separately.
36
33
#
37
34
# There are two ways to use this file, an automatic mode and a manual
38
35
# mode.  In automatic mode, you simply copy this makefile to your
153
150
ARDUINOSRCDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
154
151
ARDUINOLIB := _arduino.a
155
152
ARDUINOLIBTMP := _arduino.a.tmp
156
 
ARDUINOSOURCES := $(wildcard $(ARDUINOSRCDIR)/*.c $(ARDUINOSRCDIR)/*.cpp)
 
153
ARDUINOSOURCES := $(wildcard $(addprefix $(ARDUINOSRCDIR)/, *.c *.cpp))
157
154
ARDUINOOBJECTS := $(addsuffix .o, $(addprefix $(ARDUINOLIBTMP)/, $(basename \
158
 
        $(notdir $(ARDUINOSOURCES)))))
 
155
        $(subst $(ARDUINOSRCDIR)/,,$(ARDUINOSOURCES)))))
159
156
 
160
 
# obtain board parameters from the arduino boards.txt file
 
157
# obtain parameters from the arduino boards.txt file
161
158
BOARDS_FILE := $(ARDUINODIR)/hardware/arduino/boards.txt
162
159
BOARD_BUILD_MCU := \
163
160
        $(shell sed -ne "s/$(BOARD).build.mcu=\(.*\)/\1/p" $(BOARDS_FILE))
176
173
LD := avr-ld
177
174
AR := avr-ar
178
175
OBJCOPY := avr-objcopy
179
 
AVRDUDE := avrdude
180
 
#$(ARDUINODIR)/hardware/tools/avrdude
 
176
AVRDUDE := $(ARDUINODIR)/hardware/tools/avrdude
181
177
 
182
178
# flags
183
179
CPPFLAGS = -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
184
180
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU) -DF_CPU=$(BOARD_BUILD_FCPU)
185
181
CPPFLAGS += -I. -Iutility -I$(ARDUINOSRCDIR)
186
182
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
187
 
AVRDUDEFLAGS = -C $(ARDUINODIR)/hardware/tools/avrdude.conf -DV
 
183
AVRDUDEFLAGS = -V -F -C $(ARDUINODIR)/hardware/tools/avrdude.conf
188
184
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
189
185
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
190
 
LINKFLAGS = -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
191
186
 
192
187
# checks
193
188
ifeq ($(TARGET),)
204
199
 
205
200
all: target upload
206
201
 
207
 
target: $(TARGET).hex
 
202
target: $(TARGET).elf
208
203
 
209
204
upload:
210
205
        stty -F $(SERIALDEV) hupcl
211
 
        $(AVRDUDE) $(AVRDUDEFLAGS) -U flash:w:$(TARGET).hex:i
 
206
        $(OBJCOPY) -O ihex -R .eeprom $(TARGET).elf $(TARGET).hex
 
207
        $(AVRDUDE) $(ARVDUDEFLAGS) -U flash:w:$(TARGET).hex
 
208
        rm $(TARGET).hex
212
209
 
213
210
clean:
214
211
        rm -f $(OBJECTS)
217
214
 
218
215
# building the target
219
216
 
220
 
$(TARGET).hex: $(TARGET).elf
221
 
        $(OBJCOPY) -O ihex -R .eeprom $< $@
222
 
 
223
 
.INTERMEDIATE: $(TARGET).elf
224
 
 
225
217
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
226
 
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -o $@
 
218
        $(CC) -Os -Wl,--gc-sections $(OBJECTS) $(ARDUINOLIB) -o $@
227
219
 
228
220
%.o: %.ino
229
221
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOSRCDIR)/Arduino.h $<