/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

Lines of Context:
34
34
# more information and documentation on it's use.  The following text
35
35
# can only really be considered a reference to it's use.
36
36
#
37
 
# To use this makefile, put a file named "Makefile" in your project
38
 
# directory.  Add all your project's settings to your Makefile and
39
 
# then include this file from it. For example, your Makefile might
40
 
# look something like this:
41
 
#
 
37
# There are two ways to use this file, an automatic mode and a manual
 
38
# mode.  In automatic mode, you simply copy this makefile to your
 
39
# arduino project directory, rename it "Makefile" and type make.  The
 
40
# project directory is expected to contain an .ino or .pde file, which
 
41
# will automatically be used automatically, along with any other .c,
 
42
# .cc or .cpp files in the project directory and any subdirectory
 
43
# named "utility".  In this way, this makefile should act as a drop-in
 
44
# replacement for the Arduino IDE's build process and can build a
 
45
# project automatically from the files in a project directory.
 
46
#
 
47
# Alternatively, you can manually specify what files should be
 
48
# inclided in a build.  To use this makefile manually, you might be
 
49
# better to keep it somewhere and include it in your project's
 
50
# Makefile after having defined certain parameters that control the
 
51
# build.  As an example, consider the following Makefile:
 
52
#
 
53
#       TARGET = my_program
 
54
#       SOURCES = main.cc foo.cc
42
55
#               BOARD = nano
43
56
#               SERIALDEV = /dev/ttyACM0
44
57
#       include ~/src/arduino.mk
45
58
#
46
 
# A complete list of all the settings you can use in your Makefile
47
 
# follows shortly. But it should be noted that there are two ways to
48
 
# use this file, an automatic mode and a manual mode.
49
 
#
50
 
# In automatic mode, you simply define a BOARD and SERIALDEV and then
51
 
# include this makefile.  The project directory must contain an .ino
52
 
# or .pde file, which will automatically be used, along with any other
53
 
# .c, .cc or .cpp files in the project directory.  When buliding, any
54
 
# arduino libraries that are #included in your code are detected and
55
 
# automatically linked against.  In this way, this makefile should act
56
 
# as a drop-in replacement for the Arduino IDE's build system.  You
57
 
# should be able to type "make" from the command line and achieve the
58
 
# same as building and uploading from the Arduino IDE.
59
 
#
60
 
# The alternative, manual mode, makes no assumptions.  If the
61
 
# directory doesn't contain an .ino or .pde file, you must also
62
 
# specify the SOURCES, TARGET and LIBRARIES manually in your Makefile.
63
 
# You will also be expected to provide a main() function, for example
64
 
# in main.cc, which may or may not duplicate the functionality of the
65
 
# default main() that calls init() and loop().
66
 
#
67
 
# Here is a list of all configuration parameters:
 
59
# In both manual and automatic modes, the standard Arduino main.cpp's
 
60
# main() is included, which expects to be able to call init() and
 
61
# loop() in your code.  The main difference is that, in manual mode,
 
62
# these would typically be placed in a .cc or .cpp file.
 
63
#
 
64
# When using manual mode, the following variables can be used:
 
65
#
 
66
# TARGET       The name of the target file.  This is typically the same name
 
67
#              as the project directory for an arduino project and, if
 
68
#              unspecified, that is used as a default.
 
69
#
 
70
# SOURCES      A list of all source files of whatever language. The language
 
71
#              type is determined by the file extension.
68
72
#
69
73
# BOARD        Specify a target board type.  These are defined in boards.txt,
70
74
#              which came with your arduino installation.  If unspecified,
73
77
# SERIALDEV    The unix device of the device where the arduino can be found.
74
78
#              If unspecified, a default is used.  (See below).
75
79
#
76
 
# The following configuration parameters can be determined automatically:
77
 
#
78
 
# TARGET       The name of the target file.  This is typically the same name
79
 
#              as the project directory for an arduino project and, if
80
 
#              unspecified, that is used as a default.
81
 
#
82
 
# SOURCES      A list of all source files of whatever language. The language
83
 
#              type is determined by the file extension.
84
 
#
85
 
# LIBRARIES    A list of arduino libraries to include
86
 
#
87
80
# This general-purpose makefile also defines the following goals for use on the
88
81
# command line when you run make:
89
82
#
129
122
#   atmega168   Arduino NG or older w/ ATmega168
130
123
#   atmega8     Arduino NG or older w/ ATmega8
131
124
ifndef BOARD
132
 
BOARD := uno
 
125
BOARD := nano
133
126
endif
134
127
 
135
128
# The name of the serial device that the arduino is at. For example,
149
142
endif
150
143
TARGET := $(basename $(INOFILE))
151
144
SOURCES := $(INOFILE) \
152
 
        $(wildcard *.c *.cc *.cpp) \
153
 
        $(wildcard $(addprefix util/, *.c *.cc *.cpp)) \
154
 
        $(wildcard $(addprefix utility/, *.c *.cc *.cpp))
155
 
# automatically determine included libraries
156
 
ARDUINOLIBSAVAIL := $(notdir $(wildcard $(ARDUINODIR)/libraries/*))
157
 
LIBRARIES := $(filter $(ARDUINOLIBSAVAIL), \
158
 
        $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
 
145
        $(wildcard *.c *.cc *.cpp $(addprefix utility/, *.c *.cc *.cpp))
159
146
endif
160
147
 
161
148
# files
162
149
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
 
150
ifdef INOFILE
 
151
OBJECT += main.o
 
152
endif
163
153
ARDUINOSRCDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
164
154
ARDUINOLIB := _arduino.a
165
155
ARDUINOLIBTMP := _arduino.a.tmp
166
 
ARDUINOLIBOBJS := $(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
167
 
        $(wildcard $(addprefix $(ARDUINOSRCDIR)/, *.c *.cpp)))))
168
 
ARDUINOLIBOBJS += $(foreach lib, $(LIBRARIES), \
169
 
        $(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
170
 
        $(wildcard $(addprefix $(ARDUINODIR)/libraries/$(lib)/, *.c *.cpp))))))
 
156
ARDUINOSOURCES := $(wildcard $(addprefix $(ARDUINOSRCDIR)/, *.c *.cpp))
 
157
ARDUINOOBJECTS := $(addsuffix .o, $(addprefix $(ARDUINOLIBTMP)/, $(basename \
 
158
        $(subst $(ARDUINOSRCDIR)/,,$(ARDUINOSOURCES)))))
171
159
 
172
160
# obtain board parameters from the arduino boards.txt file
173
161
BOARDS_FILE := $(ARDUINODIR)/hardware/arduino/boards.txt
196
184
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU) -DF_CPU=$(BOARD_BUILD_FCPU)
197
185
CPPFLAGS += -I. -Iutility -I$(ARDUINOSRCDIR)
198
186
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
199
 
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/,$(LIBRARIES))
200
187
AVRDUDEFLAGS = -C $(ARDUINODIR)/hardware/tools/avrdude.conf -DV
201
188
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
202
189
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
246
233
 
247
234
# building the arduino library
248
235
 
249
 
$(ARDUINOLIB): $(ARDUINOLIBOBJS)
 
236
$(ARDUINOLIB): $(ARDUINOOBJECTS)
250
237
        $(AR) rcs $@ $?
251
238
        rm -rf $(ARDUINOLIBTMP)
252
239
 
253
 
.INTERMEDIATE: $(ARDUINOLIBOBJS)
 
240
.INTERMEDIATE: $(ARDUINOOBJECTS)
254
241
 
255
242
$(ARDUINOLIBTMP)/%.o: $(ARDUINOSRCDIR)/%.c
256
243
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
259
246
$(ARDUINOLIBTMP)/%.o: $(ARDUINOSRCDIR)/%.cpp
260
247
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
261
248
        $(COMPILE.cpp) -o $@ $<
262
 
 
263
 
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/%.c
264
 
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
265
 
        $(COMPILE.c) -o $@ $<
266
 
 
267
 
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/%.cpp
268
 
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
269
 
        $(COMPILE.cpp) -o $@ $<