/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-03-20 22:14:41 UTC
  • Revision ID: tim@ed.am-20120320221441-1w3uknfaki3u7ohu
build arduino static lib in .lib using full pathnames in object files (so files of the same name but in different locations can co-exist)

Show diffs side-by-side

added added

removed removed

117
117
# when you run make:
118
118
#
119
119
# all          This is the default if no goal is specified.  It builds the
120
 
#              target and uploads it.
 
120
#              target.
121
121
#
122
122
# target       Builds the target.
123
123
#
171
171
        $(wildcard $(addprefix utility/, *.c *.cc *.cpp))
172
172
 
173
173
# automatically determine included libraries
174
 
ARDUINOLIBSAVAIL := $(notdir $(wildcard $(ARDUINODIR)/libraries/*))
175
 
LIBRARIES := $(filter $(ARDUINOLIBSAVAIL), \
 
174
LIBRARIES := $(filter $(notdir $(wildcard $(ARDUINODIR)/libraries/*)), \
176
175
        $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
177
176
 
178
177
endif
198
197
# files
199
198
TARGET := $(if $(TARGET),$(TARGET),a.out)
200
199
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
201
 
ARDUINOSRCDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
202
 
ARDUINOLIBSDIR := $(ARDUINODIR)/libraries
203
 
ARDUINOLIB := _arduino.a
204
 
ARDUINOLIBTMP := $(ARDUINOLIB).tmp
205
 
ARDUINOLIBOBJS := $(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
206
 
        $(wildcard $(addprefix $(ARDUINOSRCDIR)/, *.c *.cpp)))))
207
 
ARDUINOLIBOBJS += $(foreach lib, $(LIBRARIES), \
208
 
        $(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
209
 
        $(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/, *.c *.cpp)) \
210
 
        $(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/utility/, *.c *.cpp)) ))))
 
200
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
 
201
ARDUINOLIB := .lib/arduino.a
 
202
ARDUINOLIBLIBSDIR := $(ARDUINODIR)/libraries
 
203
ARDUINOLIBLIBSPATH := $(foreach lib, $(LIBRARIES), \
 
204
        $(ARDUINODIR)/libraries/$(lib)/ $(ARDUINODIR)/libraries/$(lib)/utility/ )
 
205
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(ARDUINOLIBLIBSPATH), \
 
206
        $(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
211
207
ifeq "$(AVRDUDECONF)" ""
212
208
ifeq "$(AVRDUDE)" "$(ARDUINODIR)/hardware/tools/avr/bin/avrdude"
213
209
AVRDUDECONF := $(ARDUINODIR)/hardware/tools/avr/etc/avrdude.conf
248
244
endif
249
245
 
250
246
# flags
251
 
CPPFLAGS := -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
252
 
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
253
 
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
254
 
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
255
 
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOSRCDIR)
256
 
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
257
 
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/, $(LIBRARIES))
258
 
CPPFLAGS += $(patsubst %, -I$(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
 
247
CPPFLAGS_S := -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
 
248
CPPFLAGS_S += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
 
249
CPPFLAGS_S += -mmcu=$(BOARD_BUILD_MCU)
 
250
CPPFLAGS_S += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
 
251
CPPFLAGS_S += -I. -Iutil -Iutility -I$(ARDUINOCOREDIR)
 
252
CPPFLAGS_S += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
 
253
CPPFLAGS_S += $(addprefix -I$(ARDUINODIR)/libraries/, $(LIBRARIES))
 
254
CPPFLAGS_S += $(patsubst %, -I$(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
 
255
CPPFLAGS = $(CPPFLAGS_S)
259
256
AVRDUDEFLAGS := $(addprefix -C , $(AVRDUDECONF)) -DV
260
257
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
261
258
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
272
269
 
273
270
.PHONY: all target upload clean boards monitor size
274
271
 
275
 
all: target upload
 
272
all: target
276
273
 
277
274
target: $(TARGET).hex
278
275
 
290
287
clean:
291
288
        rm -f $(OBJECTS)
292
289
        rm -f $(TARGET).elf $(TARGET).hex $(ARDUINOLIB) *~
293
 
        rm -rf $(ARDUINOLIBTMP)
 
290
        rm -rf .lib
294
291
 
295
292
boards:
296
293
        @echo Available values for BOARD:
322
319
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
323
320
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -o $@
324
321
 
 
322
#%.o: %.c
 
323
#       $(COMPILE.c) -o $@ $<
 
324
 
325
325
%.o: %.ino
326
 
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOSRCDIR)/Arduino.h $<
 
326
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
327
327
 
328
328
%.o: %.pde
329
 
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOSRCDIR)/Arduino.h $<
 
329
        $(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
330
330
 
331
331
# building the arduino library
332
332
 
333
333
$(ARDUINOLIB): $(ARDUINOLIBOBJS)
334
334
        $(AR) rcs $@ $?
335
 
        rm -rf $(ARDUINOLIBTMP)
336
 
 
337
 
.INTERMEDIATE: $(ARDUINOLIBOBJS)
338
 
 
339
 
$(ARDUINOLIBTMP)/%.o: $(ARDUINOSRCDIR)/%.c
340
 
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
341
 
        $(COMPILE.c) -o $@ $<
342
 
 
343
 
$(ARDUINOLIBTMP)/%.o: $(ARDUINOSRCDIR)/%.cpp
344
 
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
345
 
        $(COMPILE.cpp) -o $@ $<
346
 
 
347
 
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/%.c
348
 
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
349
 
        $(COMPILE.c) -o $@ $<
350
 
 
351
 
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/%.cpp
352
 
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
353
 
        $(COMPILE.cpp) -o $@ $<
354
 
 
355
 
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/utility/%.c
356
 
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
357
 
        $(COMPILE.c) -o $@ $<
358
 
 
359
 
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/utility/%.cpp
360
 
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
 
335
 
 
336
.lib/%.c.o: %.c
 
337
        mkdir -p $(dir $@)
 
338
        $(COMPILE.c) -o $@ $<
 
339
 
 
340
.lib/%.cpp.o: %.cpp
 
341
        mkdir -p $(dir $@)
 
342
        $(COMPILE.cpp) -o $@ $<
 
343
 
 
344
.lib/%.cc.o: %.cc
 
345
        mkdir -p $(dir $@)
 
346
        $(COMPILE.cpp) -o $@ $<
 
347
 
 
348
.lib/%.C.o: %.C
 
349
        mkdir -p $(dir $@)
361
350
        $(COMPILE.cpp) -o $@ $<