/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 21:59:10 UTC
  • Revision ID: edam@waxworlds.org-20111229215910-l0wjvdoap0lptgsa
fixed build (missing library), tested upload, and made the .elf file an intermediate file (the .hex file is now the target)

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.
 
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.
33
36
#
34
37
# There are two ways to use this file, an automatic mode and a manual
35
38
# mode.  In automatic mode, you simply copy this makefile to your
154
157
ARDUINOOBJECTS := $(addsuffix .o, $(addprefix $(ARDUINOLIBTMP)/, $(basename \
155
158
        $(subst $(ARDUINOSRCDIR)/,,$(ARDUINOSOURCES)))))
156
159
 
157
 
# obtain parameters from the arduino boards.txt file
 
160
# obtain board parameters from the arduino boards.txt file
158
161
BOARDS_FILE := $(ARDUINODIR)/hardware/arduino/boards.txt
159
162
BOARD_BUILD_MCU := \
160
163
        $(shell sed -ne "s/$(BOARD).build.mcu=\(.*\)/\1/p" $(BOARDS_FILE))
173
176
LD := avr-ld
174
177
AR := avr-ar
175
178
OBJCOPY := avr-objcopy
176
 
AVRDUDE := $(ARDUINODIR)/hardware/tools/avrdude
 
179
AVRDUDE := avrdude
 
180
#$(ARDUINODIR)/hardware/tools/avrdude
177
181
 
178
182
# flags
179
183
CPPFLAGS = -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
180
184
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU) -DF_CPU=$(BOARD_BUILD_FCPU)
181
185
CPPFLAGS += -I. -Iutility -I$(ARDUINOSRCDIR)
182
186
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
183
 
AVRDUDEFLAGS = -V -F -C $(ARDUINODIR)/hardware/tools/avrdude.conf
 
187
AVRDUDEFLAGS = -C $(ARDUINODIR)/hardware/tools/avrdude.conf -DV
184
188
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
185
189
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
 
190
LINKFLAGS = -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
186
191
 
187
192
# checks
188
193
ifeq ($(TARGET),)
199
204
 
200
205
all: target upload
201
206
 
202
 
target: $(TARGET).elf
 
207
target: $(TARGET).hex
203
208
 
204
209
upload:
205
210
        stty -F $(SERIALDEV) hupcl
206
 
        $(OBJCOPY) -O ihex -R .eeprom $(TARGET).elf $(TARGET).hex
207
 
        $(AVRDUDE) $(ARVDUDEFLAGS) -U flash:w:$(TARGET).hex
208
 
        rm $(TARGET).hex
 
211
        $(AVRDUDE) $(AVRDUDEFLAGS) -U flash:w:$(TARGET).hex:i
209
212
 
210
213
clean:
211
214
        rm -f $(OBJECTS)
214
217
 
215
218
# building the target
216
219
 
 
220
$(TARGET).hex: $(TARGET).elf
 
221
        $(OBJCOPY) -O ihex -R .eeprom $< $@
 
222
 
 
223
.INTERMEDIATE: $(TARGET).elf
 
224
 
217
225
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
218
 
        $(CC) -Os -Wl,--gc-sections $(OBJECTS) $(ARDUINOLIB) -o $@
 
226
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -o $@
219
227
 
220
228
%.o: %.ino
221
229
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOSRCDIR)/Arduino.h $<