/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock

« back to all changes in this revision

Viewing changes to src/Makefile

  • Committer: edam
  • Date: 2012-01-01 14:05:28 UTC
  • Revision ID: edam@waxworlds.org-20120101140528-ldqldo67nil1xf1s
added arduino.mk to the project

Show diffs side-by-side

added added

removed removed

27
27
#_______________________________________________________________________________
28
28
#
29
29
#
30
 
# This is a general purpose makefile for use with Arduino hardware and
31
 
# software.  It works with the arduino-1.0 release and requires that
32
 
# software to be downloaded separately (see http://arduino.cc/).  To
33
 
# download the latest version of this makefile, visit the following
34
 
# website, where you can also find more information and documentation
35
 
# on it's use.  The following text can only really be considered a
36
 
# reference to it's use.
37
 
#
38
 
#   http://ed.am/dev/make/arduino-makefile
 
30
# This is a general purpose makefile for use with Arduino (see
 
31
# http://arduino.cc/) hardware and software.  It works with the
 
32
# arduino-1.0 release and requires that to be downloaded separately.
 
33
# It can be downloaded from http://ed.am/dev/make/arduino-makefile
 
34
# where you can also find more information and documentation on it's
 
35
# use.  The following text can only really be considered a reference
 
36
# to it's use.
39
37
#
40
38
# To install, it is suggested that you keep arduino.mk somewhere and
41
39
# either symlink to it or include it in your make files.  I keep mine
45
43
#
46
44
# This makefile can be used as a drop-in replacement for the Arduino
47
45
# IDE's build system.  Simply create a symlink to it under the name
48
 
# "Makefile" and run make (remembering to specify an ARDUINODIR and
49
 
# BOARD, as described below).  You would create the symlink like like
50
 
# so:
 
46
# "Makefile" and run make as described below (remembering to specify a
 
47
# BOARD).  You would create the symlink like like so:
51
48
#
52
 
#   $ ln -s ~/src/arduino.mk Makefile
 
49
#       $ ln -s ~/src/arduino.mk Makefile
53
50
#
54
51
# The presence of a .ino or .pde file causes the arduino.mk to
55
52
# atuomatically determine va;ues for SOURCES, TARGET and LIBRARIES.
65
62
# default main() that calls init() and loop().  Here is an example
66
63
# Makefile:
67
64
#
68
 
#   SOURCES := main.cc foo.cc
69
 
#   LIBRARIES := EEPROM
70
 
#   include ~/src/arduino.mk
 
65
#       SOURCES := main.cc foo.cc
 
66
#       LIBRARIES := EEPROM
 
67
#       include ~/src/arduino.mk
71
68
#
72
69
# A complete list of all the settings you can use in your Makefile
73
70
# follows shortly.  It should be noted, however, that some variables
74
 
# are better specified in the environment (or on the command line)
75
 
# than in your Makefile.  Specifically, the ARDUINODIR, BOARD and, if
76
 
# it is not automatically detected, SERIALDEV.
77
 
#
78
 
# When running make, you might want to specify the board and path to
79
 
# your installation of the arduino software, like this:
80
 
#
81
 
#   $ export ARDUINODIR=~/opt/arduino-1.0
82
 
#   $ export BOARD=pro5v
83
 
#   $ make
 
71
# are better specified in the environment or on the command line than
 
72
# in a Makefile.  Specifically, the BOARD and SERIALDEV (if it is not
 
73
# automatically detected).
 
74
#
 
75
# When running make, you might want to specify the board type:
 
76
#
 
77
#       $ BOARD=pro5v make
 
78
#
 
79
# Or in the environment:
 
80
#
 
81
#       $ export BOARD=pro5v
 
82
#       $ make
84
83
#
85
84
# For a list of available board types, run `make boards`.
86
85
87
 
# Here is a complete list of configuration parameters:
88
 
#
89
 
# ARDUINODIR   The path where you have installed/unpacked the arduino
90
 
#              software (from http://arduino.cc/)
 
86
# Here is a list of all configuration parameters:
91
87
#
92
88
# BOARD        Specify a target board type.
93
89
#
95
91
#              found.  If unspecified, an attempt is made to determine
96
92
#              the name of a connected arduino's serial device.
97
93
#
98
 
# TARGET       The name of the target file.  This is set automatically
99
 
#              if a .ino or .pde is found, but it is not neccesary to
100
 
#              set it otherwise.
 
94
# The following configuration parameters can be determined automatically:
 
95
#
 
96
# TARGET       The name of the target file.  This need not be set if it
 
97
#              is not determined automatically.
101
98
#
102
99
# SOURCES      A list of all source files of whatever language.  The
103
100
#              language type is determined by the file extension.
104
 
#              This is set automatically if a .ino or .pde is found.
105
101
#
106
 
# LIBRARIES    A list of arduino libraries to build and include.  This
107
 
#              is set automatically if a .ino or .pde is found.
 
102
# LIBRARIES    A list of arduino libraries to build and include.
108
103
#
109
104
# This general-purpose makefile also defines the following goals for
110
105
# use on the command line when you run make:
122
117
#              target, from those that that would be built for the
123
118
#              project.
124
119
#
125
 
# boards       This is not a real goal.  It just displays a list of
126
 
#              available board names, so that you can set the BOARD
127
 
#              environment variable appropriately.
128
 
#
129
 
# monitor      This is not a real goal.  It starts screen on the serial
130
 
#              device.  It is ment to be an equivelant to the arduino
131
 
#              serial monitor.
132
120
#_______________________________________________________________________________
133
121
#
134
122
 
135
123
# The full path to the arduino software, from arduino.cc
136
 
ifndef ARDUINODIR
137
124
ARDUINODIR := $(wildcard ~/opt/arduino-1.0)
138
 
endif
139
125
 
140
126
# check arduino software
141
127
ifeq ($(wildcard $(ARDUINODIR)/hardware/arduino/boards.txt), )
142
 
$(error ARDUINODIR is not set correctly; arduino software not found)
 
128
$(error ARDUINODIR is not set correctly at the top of arduino.mk)
143
129
endif
144
130
 
145
131
# auto mode?
160
146
endif
161
147
 
162
148
# no target? use default
163
 
ifeq ($(TARGET), )
 
149
ifndef TARGET
164
150
TARGET := a.out
165
151
endif
166
152
 
167
153
# no serial device? attempt to detect an arduino
168
 
ifeq ($(SERIALDEV), )
 
154
ifndef SERIALDEV
169
155
SERIALDEV := $(firstword $(wildcard /dev/ttyACM? /dev/ttyUSB?))
170
156
endif
171
157
 
181
167
# files
182
168
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
183
169
ARDUINOSRCDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
184
 
ARDUINOLIBSDIR := $(ARDUINODIR)/libraries
185
170
ARDUINOLIB := _arduino.a
186
171
ARDUINOLIBTMP := _arduino.a.tmp
187
172
ARDUINOLIBOBJS := $(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
188
173
        $(wildcard $(addprefix $(ARDUINOSRCDIR)/, *.c *.cpp)))))
189
174
ARDUINOLIBOBJS += $(foreach lib, $(LIBRARIES), \
190
175
        $(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
191
 
        $(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/, *.c *.cpp)) \
192
 
        $(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/utility/, *.c *.cpp)) ))))
 
176
        $(wildcard $(addprefix $(ARDUINODIR)/libraries/$(lib)/, *.c *.cpp))))))
193
177
 
194
178
# obtain board parameters from the arduino boards.txt file
195
179
BOARDS_FILE := $(ARDUINODIR)/hardware/arduino/boards.txt
217
201
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU) -DF_CPU=$(BOARD_BUILD_FCPU)
218
202
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOSRCDIR)
219
203
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
220
 
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/, $(LIBRARIES))
221
 
CPPFLAGS += $(patsubst %, -I$(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
 
204
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/,$(LIBRARIES))
222
205
AVRDUDEFLAGS = -C $(ARDUINODIR)/hardware/tools/avrdude.conf -DV
223
206
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
224
207
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
230
213
#_______________________________________________________________________________
231
214
#                                                                          RULES
232
215
 
233
 
.PHONY: all target upload clean boards monitor
 
216
.PHONY: all target upload clean boards
234
217
 
235
218
all: target upload
236
219
 
237
220
target: $(TARGET).hex
238
221
 
239
222
upload:
240
 
        @test -n "$(SERIALDEV)" || { echo "SERIALDEV is unset." >&2; exit 1; }
241
223
        stty -F $(SERIALDEV) hupcl
242
224
        $(AVRDUDE) $(AVRDUDEFLAGS) -U flash:w:$(TARGET).hex:i
243
225
 
251
233
        @sed -ne '/^#/d;s/^\(.*\).name=\(.*\)/\1            \2/;T' \
252
234
                -e 's/\(.\{12\}\) *\(.*\)/\1 \2/;p' $(BOARDS_FILE)
253
235
 
254
 
monitor:
255
 
        @test -n "$(SERIALDEV)" || { echo "SERIALDEV is unset." >&2; exit 1; }
256
 
        screen $(SERIALDEV)
257
 
 
258
236
# building the target
259
237
 
260
238
$(TARGET).hex: $(TARGET).elf
294
272
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/%.cpp
295
273
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
296
274
        $(COMPILE.cpp) -o $@ $<
297
 
 
298
 
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/utility/%.c
299
 
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
300
 
        $(COMPILE.c) -o $@ $<
301
 
 
302
 
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/utility/%.cpp
303
 
        @test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
304
 
        $(COMPILE.cpp) -o $@ $<