Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 366 lines (301 sloc) 10.497 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
########################################################################
#
# Arduino command line tools Makefile
# System part (i.e. project independent)
#
# Adapted from Arduino 0011 Makefile by M J Oldfield
#
# Original Arduino adaptation by mellis, eighthave, oli.keller
#
# Version 0.1 17.ii.2009 M J Oldfield
#
# 0.2 22.ii.2009 M J Oldfield
# - fixes so that the Makefile actually works!
# - support for uploading via ISP
# - orthogonal choices of using the Arduino for
# tools, libraries and uploading
#
########################################################################
#
# STANDARD ARDUINO WORKFLOW
#
# Given a normal sketch directory, all you need to do is to create
# a small Makefile which defines a few things, and then includes this one.
#
# For example:
#
# ARDUINO_DIR = /Applications/arduino-0013
#
# TARGET = CLItest
# ARDUINO_LIBS = LiquidCrystal
#
# MCU = atmega168
# F_CPU = 16000000
# ARDUINO_PORT = /dev/cu.usb*
#
# include /usr/local/share/Arduino.mk
#
# Hopefully these will be self-explanatory but in case they're not:
#
# ARDUINO_DIR - Where the Arduino software has been unpacked
# TARGET - The basename used for the final files. Canonically
# this would match the .pde file, but it's not needed
# here: you could always set it to xx if you wanted!
# ARDUINO_LIBS - A list of any libraries used by the sketch (we assume
# these are in $(ARDUINO_DIR)/hardware/libraries
# MCU,F_CPU - The target processor description
# ARDUINO_PORT - The port where the Arduino can be found (only needed
# when uploading
#
# Once this file has been created the typical workflow is just
#
# $ make upload
#
# All of the object files are created in the build subdirectory
# All sources should be in the current directory and can include:
# - at most one .pde file which will be treated as C++ after the standard
# Arduino header and footer have been affixed.
# - any number of .c, .cpp, .s and .h files
#
#
# Besides make upload you can also
# make - no upload
# make clean - remove all our dependencies
# make depends - update dependencies
#
########################################################################
#
# ARDUINO WITH OTHER TOOLS
#
# If the tools aren't in the Arduino distribution, then you need to
# specify their location:
#
# AVR_TOOLS_PATH = /usr/bin
# AVRDUDE_CONF = /etc/avrdude/avrdude.conf
#
########################################################################
#
# ARDUINO WITH ISP
#
# You need to specify some details of your ISP programmer and might
# also need to specify the fuse values:
#
# ISP_PROG = -c stk500v2
# ISP_PORT = /dev/ttyACM0
#
# ISP_LOCK_FUSE_PRE = 0x3f
# ISP_LOCK_FUSE_POST = 0xcf
# ISP_HIGH_FUSE = 0xdf
# ISP_LOW_FUSE = 0xff
# ISP_EXT_FUSE = 0x01
#
# I think the fuses here are fine for uploading to the ATmega168
# without bootloader.
#
# To actually do this upload use the ispload target:
#
# make ispload
#
#
########################################################################
# Some paths
#

ifneq (ARDUINO_DIR,)

ifndef AVR_TOOLS_PATH
AVR_TOOLS_PATH = $(ARDUINO_DIR)/hardware/tools/avr/bin
endif

ifndef ARDUINO_ETC_PATH
ARDUINO_ETC_PATH = $(ARDUINO_DIR)/hardware/tools/avr/etc
endif

ifndef AVRDUDE_CONF
AVRDUDE_CONF = $(ARDUINO_ETC_PATH)/avrdude.conf
endif

ARDUINO_LIB_PATH = $(ARDUINO_DIR)/hardware/libraries

ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/cores/arduino
endif

# Everything gets built in here
OBJDIR = build

########################################################################
# Local sources
#
LOCAL_C_SRCS = $(wildcard *.c)
LOCAL_CPP_SRCS = $(wildcard *.cpp)
LOCAL_CC_SRCS = $(wildcard *.cc)
LOCAL_PDE_SRCS = $(wildcard *.pde)
LOCAL_AS_SRCS = $(wildcard *.S)
LOCAL_OBJ_FILES = $(LOCAL_C_SRCS:.c=.o) $(LOCAL_CPP_SRCS:.cpp=.o) \
$(LOCAL_CC_SRCS:.cc=.o) $(LOCAL_PDE_SRCS:.pde=.o) \
$(LOCAL_AS_SRCS:.S=.o)
LOCAL_OBJS = $(patsubst %,$(OBJDIR)/%,$(LOCAL_OBJ_FILES))

# Dependency files
DEPS = $(LOCAL_OBJS:.o=.d)

# core sources
ifeq ($(strip $(NO_CORE)),)
ifdef ARDUINO_CORE_PATH
CORE_C_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.c)
CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp)
CORE_OBJ_FILES = $(CORE_C_SRCS:.c=.o) $(CORE_CPP_SRCS:.cpp=.o)
CORE_OBJS = $(patsubst $(ARDUINO_CORE_PATH)/%, \
$(OBJDIR)/%,$(CORE_OBJ_FILES))
endif
endif

# all the objects!
OBJS = $(LOCAL_OBJS) $(CORE_OBJS)

########################################################################
# Rules for making stuff
#

# The name of the main targets
TARGET_HEX = $(OBJDIR)/$(TARGET).hex
TARGET_ELF = $(OBJDIR)/$(TARGET).elf
TARGETS = $(OBJDIR)/$(TARGET).*

# A list of dependencies
DEP_FILE = $(OBJDIR)/depends.mk

# Names of executables
CC = $(AVR_TOOLS_PATH)/avr-gcc
CXX = $(AVR_TOOLS_PATH)/avr-g++
OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
AR = $(AVR_TOOLS_PATH)/avr-ar
SIZE = $(AVR_TOOLS_PATH)/avr-size
NM = $(AVR_TOOLS_PATH)/avr-nm
REMOVE = rm -f
MV = mv -f
CAT = cat
ECHO = echo

# General arguments
SYS_LIBS = $(patsubst %,$(ARDUINO_LIB_PATH)/%,$(ARDUINO_LIBS))
SYS_INCLUDES = $(patsubst %,-I%,$(SYS_LIBS))
SYS_OBJS = $(wildcard $(patsubst %,%/*.o,$(SYS_LIBS)))

CPPFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) \
-I. -I$(ARDUINO_CORE_PATH) \
$(SYS_INCLUDES) -g -Os -w -Wall \
-ffunction-sections -fdata-sections
CFLAGS = -std=gnu99 -Wall
CXXFLAGS = -fshort-enums -fno-exceptions -Wall -Wno-variadic-macros -pedantic
ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp
LDFLAGS = -mmcu=$(MCU) -lm -Wl,--gc-sections -Os

# avr-gcc -c -mmcu=atmega328p -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -DF_CPU=8000000 -Wa,-adhlns=gl
# cd.lst -std=gnu99 -DTXMODE= glcd.c -o glcd.o
#

# Rules for making a CPP file from the main sketch (.cpe)
PDEHEADER = \\\#include \"WProgram.h\"
PDEFOOTER_FILE = $(ARDUINO_CORE_PATH)/main.cxx

# Implicit rules for building everything (needed to get everything in
# the right directory)
#
# Rather than mess around with VPATH there are quasi-duplicate rules
# here for building e.g. a system C++ file and a local C++
# file. Besides making things simpler now, this would also make it
# easy to change the build options in future

# normal local sources
# .o rules are for objects, .d for dependency tracking
# there seems to be an awful lot of duplication here!!!
$(OBJDIR)/%.o: %.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@

$(OBJDIR)/%.o: %.cc
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@

$(OBJDIR)/%.o: %.cpp
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@

$(OBJDIR)/%.o: %.S
$(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@

$(OBJDIR)/%.o: %.s
$(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@

$(OBJDIR)/%.d: %.c
$(CC) -MM $(CPPFLAGS) $(CFLAGS) $< -MF $@ -MT $(@:.d=.o)

$(OBJDIR)/%.d: %.cc
$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)

$(OBJDIR)/%.d: %.cpp
$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)

$(OBJDIR)/%.d: %.S
$(CC) -MM $(CPPFLAGS) $(ASFLAGS) $< -MF $@ -MT $(@:.d=.o)

$(OBJDIR)/%.d: %.s
$(CC) -MM $(CPPFLAGS) $(ASFLAGS) $< -MF $@ -MT $(@:.d=.o)

# the pde -> cpp -> o file
$(OBJDIR)/%.cpp: %.pde
$(ECHO) $(PDEHEADER) > $@
$(CAT) $< $(PDEFOOTER_FILE) >> $@

$(OBJDIR)/%.o: $(OBJDIR)/%.cpp
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@

$(OBJDIR)/%.d: $(OBJDIR)/%.cpp
$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)

# core files
$(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@

$(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.cpp
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@

# various object conversions
$(OBJDIR)/%.hex: $(OBJDIR)/%.elf
$(OBJCOPY) -O ihex -R .eeprom $< $@

$(OBJDIR)/%.eep: $(OBJDIR)/%.elf
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O ihex $< $@

$(OBJDIR)/%.lss: $(OBJDIR)/%.elf
$(OBJDUMP) -h -S $< > $@

$(OBJDIR)/%.sym: $(OBJDIR)/%.elf
$(NM) -n $< > $@

########################################################################
#
# Avrdude
#
ifndef AVRDUDE
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude
endif

AVRDUDE_COM_OPTS = -q -V -p $(MCU)
ifdef AVRDUDE_CONF
AVRDUDE_COM_OPTS += -C $(AVRDUDE_CONF)
endif

#AVRDUDE_ARD_OPTS = -c stk500v1 -b 19200 -P $(ARDUINO_PORT)
AVRDUDE_ARD_OPTS = -c stk500v1 -b 57600 -P $(ARDUINO_PORT)

ifndef ISP_LOCK_FUSE_PRE
ISP_LOCK_FUSE_PRE = 0x3f
endif

ifndef ISP_LOCK_FUSE_POST
ISP_LOCK_FUSE_POST = 0xcf
endif

ifndef ISP_HIGH_FUSE
ISP_HIGH_FUSE = 0xdf
endif

ifndef ISP_LOW_FUSE
ISP_LOW_FUSE = 0xff
endif

ifndef ISP_EXT_FUSE
ISP_EXT_FUSE = 0x01
endif

ifndef ISP_PROG
ISP_PROG = -c stk500v2
endif

AVRDUDE_ISP_OPTS = -P $(ISP_PORT) $(ISP_PROG)


########################################################################
#
# Explicit targets start here
#

all:
# foo
$(OBJDIR) $(TARGET_HEX)

$(OBJDIR):
mkdir $(OBJDIR)

$(TARGET_ELF): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(SYS_OBJS)

$(DEP_FILE): $(OBJDIR) $(DEPS)
cat $(DEPS) > $(DEP_FILE)

sizes: $(TARGET_HEX)
$(SIZE) -C --mcu=$(MCU) $(TARGET_ELF)


upload: $(TARGET_HEX) sizes
$(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \
-U flash:w:$(TARGET_HEX):i

ispload: $(TARGET_HEX)
$(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e \
-U lock:w:$(ISP_LOCK_FUSE_PRE):m \
-U hfuse:w:$(ISP_HIGH_FUSE):m \
-U lfuse:w:$(ISP_LOW_FUSE):m \
-U efuse:w:$(ISP_EXT_FUSE):m
$(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -D \
-U flash:w:$(TARGET_HEX):i
$(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) \
-U lock:w:$(ISP_LOCK_FUSE_POST):m

clean:
$(REMOVE) $(OBJS) $(TARGETS) $(DEP_FILE) $(DEPS)

depends: $(DEPS)
cat $(DEPS) > $(DEP_FILE)

.PHONY: all clean depends upload

include $(DEP_FILE)

Something went wrong with that request. Please try again.