/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: 2012-10-22 16:34:19 UTC
  • Revision ID: tim@ed.am-20121022163419-568rvcv8vdvg3tgn
link against libm (as the IDE does)

Show diffs side-by-side

added added

removed removed

2
2
#
3
3
#                         edam's Arduino makefile
4
4
#_______________________________________________________________________________
5
 
#                                                                 version 0.5dev
 
5
#                                                                 version 0.4dev
6
6
#
7
 
# Copyright (C) 2011, 2012 Tim Marston <tim@ed.am>.
 
7
# Copyright (C) 2011, 1012 Tim Marston <tim@ed.am>.
8
8
#
9
9
# Permission is hereby granted, free of charge, to any person obtaining a copy
10
10
# of this software and associated documentation files (the "Software"), to deal
156
156
AVRTOOLSPATH += $(ARDUINODIR)/hardware/tools/avr/bin
157
157
endif
158
158
 
159
 
# default path to find libraries
160
 
LIBRARIESPATH := libraries libs $(ARDUINODIR)/libraries
161
 
 
162
159
# auto mode?
163
160
INOFILE := $(wildcard *.ino *.pde)
164
161
ifdef INOFILE
169
166
# automatically determine sources and targeet
170
167
TARGET := $(basename $(INOFILE))
171
168
SOURCES := $(INOFILE) \
172
 
        $(wildcard *.c *.cc *.cpp *.C) \
173
 
        $(wildcard $(addprefix util/, *.c *.cc *.cpp *.C)) \
174
 
        $(wildcard $(addprefix utility/, *.c *.cc *.cpp *.C))
 
169
        $(wildcard *.c *.cc *.cpp) \
 
170
        $(wildcard $(addprefix util/, *.c *.cc *.cpp)) \
 
171
        $(wildcard $(addprefix utility/, *.c *.cc *.cpp))
175
172
 
176
173
# automatically determine included libraries
177
 
LIBRARIES := $(filter $(notdir $(wildcard $(addsuffix /*, $(LIBRARIESPATH)))), \
 
174
LIBRARIES := $(filter $(notdir $(wildcard $(ARDUINODIR)/libraries/*)), \
178
175
        $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
179
176
 
180
177
endif
201
198
TARGET := $(if $(TARGET),$(TARGET),a.out)
202
199
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
203
200
DEPFILES := $(patsubst %, .dep/%.dep, $(SOURCES))
204
 
 
205
 
# directories
206
 
LIBRARIESDIRS := $(foreach lib, $(LIBRARIES), \
207
 
        $(firstword $(wildcard $(addsuffix /$(lib), $(LIBRARIESPATH)))))
208
 
LIBRARIESDIRS += $(addsuffix /utility, $(LIBRARIESDIRS))
209
201
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
210
 
 
211
 
# static arduino lib
212
202
ARDUINOLIB := .lib/arduino.a
213
 
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(LIBRARIESDIRS), \
 
203
ARDUINOLIBLIBSDIR := $(ARDUINODIR)/libraries
 
204
ARDUINOLIBLIBSPATH := $(foreach lib, $(LIBRARIES), \
 
205
        $(ARDUINODIR)/libraries/$(lib)/ $(ARDUINODIR)/libraries/$(lib)/utility/ )
 
206
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(ARDUINOLIBLIBSPATH), \
214
207
        $(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
215
 
 
216
 
# avrdude confifuration
217
208
ifeq "$(AVRDUDECONF)" ""
218
209
ifeq "$(AVRDUDE)" "$(ARDUINODIR)/hardware/tools/avr/bin/avrdude"
219
210
AVRDUDECONF := $(ARDUINODIR)/hardware/tools/avr/etc/avrdude.conf
243
234
        $(shell sed -ne "s/$(BOARD).upload.speed=\(.*\)/\1/p" $(BOARDS_FILE))
244
235
BOARD_UPLOAD_PROTOCOL := \
245
236
        $(shell sed -ne "s/$(BOARD).upload.protocol=\(.*\)/\1/p" $(BOARDS_FILE))
246
 
BOARD_USB_VID := \
247
 
        $(shell sed -ne "s/$(BOARD).build.vid=\(.*\)/\1/p" $(BOARDS_FILE))
248
 
BOARD_USB_PID := \
249
 
        $(shell sed -ne "s/$(BOARD).build.pid=\(.*\)/\1/p" $(BOARDS_FILE))
250
237
 
251
238
# invalid board?
252
239
ifeq "$(BOARD_BUILD_MCU)" ""
258
245
endif
259
246
 
260
247
# flags
261
 
CPPFLAGS += -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
 
248
CPPFLAGS := -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
262
249
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
263
250
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
264
251
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
265
 
CPPFLAGS += -DUSB_VID=$(BOARD_USB_VID) -DUSB_PID=$(BOARD_USB_PID)
266
252
CPPFLAGS += -I. -Iutil -Iutility -I $(ARDUINOCOREDIR)
267
253
CPPFLAGS += -I $(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
268
 
CPPFLAGS += $(addprefix -I , $(LIBRARIESDIRS))
 
254
CPPFLAGS += $(addprefix -I $(ARDUINODIR)/libraries/, $(LIBRARIES))
 
255
CPPFLAGS += $(patsubst %, -I $(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
269
256
CPPDEPFLAGS = -MMD -MP -MF .dep/$<.dep
270
257
CPPINOFLAGS := -x c++ -include $(ARDUINOCOREDIR)/Arduino.h
271
 
AVRDUDEFLAGS += $(addprefix -C , $(AVRDUDECONF)) -DV
 
258
AVRDUDEFLAGS := $(addprefix -C , $(AVRDUDECONF)) -DV
272
259
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
273
260
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
274
 
LINKFLAGS += -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
 
261
LINKFLAGS := -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
275
262
 
276
263
# figure out which arg to use with stty (for OS X, GNU and busybox stty)
277
264
STTYFARG := $(shell stty --help 2>&1 | \
339
326
.INTERMEDIATE: $(TARGET).elf
340
327
 
341
328
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
342
 
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -lm -o $@
 
329
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -o $@ -lm
343
330
 
344
331
%.o: %.c
345
332
        mkdir -p .dep/$(dir $<)
363
350
 
364
351
%.o: %.pde
365
352
        mkdir -p .dep/$(dir $<)
366
 
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
 
353
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
367
354
 
368
355
# building the arduino library
369
356