| 1 |
4 |
atypic |
# Hey Emacs, this is a -*- makefile -*-
|
| 2 |
|
|
#----------------------------------------------------------------------------
|
| 3 |
|
|
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
|
| 4 |
|
|
#
|
| 5 |
|
|
# Released to the Public Domain
|
| 6 |
|
|
#
|
| 7 |
|
|
# Additional material for this makefile was written by:
|
| 8 |
|
|
# Peter Fleury
|
| 9 |
|
|
# Tim Henigan
|
| 10 |
|
|
# Colin O'Flynn
|
| 11 |
|
|
# Reiner Patommel
|
| 12 |
|
|
# Markus Pfaff
|
| 13 |
|
|
# Sander Pool
|
| 14 |
|
|
# Frederik Rouleau
|
| 15 |
|
|
# Carlos Lamas
|
| 16 |
|
|
#
|
| 17 |
|
|
#----------------------------------------------------------------------------
|
| 18 |
|
|
# On command line:
|
| 19 |
|
|
#
|
| 20 |
|
|
# make all = Make software.
|
| 21 |
|
|
#
|
| 22 |
|
|
# make clean = Clean out built project files.
|
| 23 |
|
|
#
|
| 24 |
|
|
# make coff = Convert ELF to AVR COFF.
|
| 25 |
|
|
#
|
| 26 |
|
|
# make extcoff = Convert ELF to AVR Extended COFF.
|
| 27 |
|
|
#
|
| 28 |
|
|
# make program = Download the hex file to the device, using avrdude.
|
| 29 |
|
|
# Please customize the avrdude settings below first!
|
| 30 |
|
|
#
|
| 31 |
|
|
# make debug = Start either simulavr or avarice as specified for debugging,
|
| 32 |
|
|
# with avr-gdb or avr-insight as the front end for debugging.
|
| 33 |
|
|
#
|
| 34 |
|
|
# make filename.s = Just compile filename.c into the assembler code only.
|
| 35 |
|
|
#
|
| 36 |
|
|
# make filename.i = Create a preprocessed source file for use in submitting
|
| 37 |
|
|
# bug reports to the GCC project.
|
| 38 |
|
|
#
|
| 39 |
|
|
# To rebuild project do "make clean" then "make all".
|
| 40 |
|
|
#----------------------------------------------------------------------------
|
| 41 |
|
|
|
| 42 |
|
|
|
| 43 |
|
|
# MCU name
|
| 44 |
|
|
MCU = atmega128
|
| 45 |
|
|
|
| 46 |
|
|
|
| 47 |
|
|
# Processor frequency.
|
| 48 |
|
|
# This will define a symbol, F_CPU, in all source code files equal to the
|
| 49 |
|
|
# processor frequency. You can then use this symbol in your source code to
|
| 50 |
|
|
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
|
| 51 |
|
|
# automatically to create a 32-bit value in your source code.
|
| 52 |
|
|
# Typical values are:
|
| 53 |
|
|
# F_CPU = 1000000
|
| 54 |
|
|
# F_CPU = 1843200
|
| 55 |
|
|
# F_CPU = 2000000
|
| 56 |
|
|
# F_CPU = 3686400
|
| 57 |
|
|
# F_CPU = 4000000
|
| 58 |
|
|
# F_CPU = 7372800
|
| 59 |
|
|
# F_CPU = 8000000
|
| 60 |
|
|
# F_CPU = 11059200
|
| 61 |
|
|
# F_CPU = 14745600
|
| 62 |
|
|
# F_CPU = 16000000
|
| 63 |
|
|
# F_CPU = 18432000
|
| 64 |
|
|
# F_CPU = 20000000
|
| 65 |
|
|
F_CPU = 8000000
|
| 66 |
|
|
|
| 67 |
|
|
|
| 68 |
|
|
# Output format. (can be srec, ihex, binary)
|
| 69 |
|
|
FORMAT = ihex
|
| 70 |
|
|
|
| 71 |
|
|
|
| 72 |
|
|
# Target file name (without extension).
|
| 73 |
|
|
TARGET = busmaster
|
| 74 |
|
|
|
| 75 |
|
|
|
| 76 |
|
|
# Object files directory
|
| 77 |
|
|
OBJDIR = obj
|
| 78 |
|
|
|
| 79 |
|
|
|
| 80 |
|
|
# List C source files here. (C dependencies are automatically generated.)
|
| 81 |
|
|
SRC = uart.c busmaster.c main.c
|
| 82 |
|
|
|
| 83 |
|
|
|
| 84 |
|
|
# List C++ source files here. (C dependencies are automatically generated.)
|
| 85 |
|
|
CPPSRC =
|
| 86 |
|
|
|
| 87 |
|
|
|
| 88 |
|
|
# List Assembler source files here.
|
| 89 |
|
|
# Make them always end in a capital .S. Files ending in a lowercase .s
|
| 90 |
|
|
# will not be considered source files but generated files (assembler
|
| 91 |
|
|
# output from the compiler), and will be deleted upon "make clean"!
|
| 92 |
|
|
# Even though the DOS/Win* filesystem matches both .s and .S the same,
|
| 93 |
|
|
# it will preserve the spelling of the filenames, and gcc itself does
|
| 94 |
|
|
# care about how the name is spelled on its command-line.
|
| 95 |
|
|
ASRC =
|
| 96 |
|
|
|
| 97 |
|
|
|
| 98 |
|
|
# Optimization level, can be [0, 1, 2, 3, s].
|
| 99 |
|
|
# 0 = turn off optimization. s = optimize for size.
|
| 100 |
|
|
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
|
| 101 |
|
|
OPT = s
|
| 102 |
|
|
|
| 103 |
|
|
|
| 104 |
|
|
# Debugging format.
|
| 105 |
|
|
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
|
| 106 |
|
|
# AVR Studio 4.10 requires dwarf-2.
|
| 107 |
|
|
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
|
| 108 |
|
|
DEBUG = dwarf-2
|
| 109 |
|
|
|
| 110 |
|
|
|
| 111 |
|
|
# List any extra directories to look for include files here.
|
| 112 |
|
|
# Each directory must be seperated by a space.
|
| 113 |
|
|
# Use forward slashes for directory separators.
|
| 114 |
|
|
# For a directory that has spaces, enclose it in quotes.
|
| 115 |
|
|
EXTRAINCDIRS =
|
| 116 |
|
|
|
| 117 |
|
|
|
| 118 |
|
|
# Compiler flag to set the C Standard level.
|
| 119 |
|
|
# c89 = "ANSI" C
|
| 120 |
|
|
# gnu89 = c89 plus GCC extensions
|
| 121 |
|
|
# c99 = ISO C99 standard (not yet fully implemented)
|
| 122 |
|
|
# gnu99 = c99 plus GCC extensions
|
| 123 |
|
|
CSTANDARD = -std=gnu99
|
| 124 |
|
|
|
| 125 |
|
|
|
| 126 |
|
|
# Place -D or -U options here for C sources
|
| 127 |
|
|
CDEFS = -DF_CPU=$(F_CPU)UL
|
| 128 |
|
|
|
| 129 |
|
|
|
| 130 |
|
|
# Place -D or -U options here for C++ sources
|
| 131 |
|
|
CPPDEFS = -DF_CPU=$(F_CPU)UL
|
| 132 |
|
|
#CPPDEFS += -D__STDC_LIMIT_MACROS
|
| 133 |
|
|
#CPPDEFS += -D__STDC_CONSTANT_MACROS
|
| 134 |
|
|
|
| 135 |
|
|
|
| 136 |
|
|
|
| 137 |
|
|
#---------------- Compiler Options C ----------------
|
| 138 |
|
|
# -g*: generate debugging information
|
| 139 |
|
|
# -O*: optimization level
|
| 140 |
|
|
# -f...: tuning, see GCC manual and avr-libc documentation
|
| 141 |
|
|
# -Wall...: warning level
|
| 142 |
|
|
# -Wa,...: tell GCC to pass this to the assembler.
|
| 143 |
|
|
# -adhlns...: create assembler listing
|
| 144 |
|
|
CFLAGS = -g$(DEBUG)
|
| 145 |
|
|
CFLAGS += $(CDEFS)
|
| 146 |
|
|
CFLAGS += -O$(OPT)
|
| 147 |
|
|
#CFLAGS += -mint8
|
| 148 |
|
|
#CFLAGS += -mshort-calls
|
| 149 |
|
|
CFLAGS += -funsigned-char
|
| 150 |
|
|
CFLAGS += -funsigned-bitfields
|
| 151 |
|
|
CFLAGS += -fpack-struct
|
| 152 |
|
|
CFLAGS += -fshort-enums
|
| 153 |
|
|
#CFLAGS += -fno-unit-at-a-time
|
| 154 |
|
|
CFLAGS += -Wall
|
| 155 |
|
|
CFLAGS += -Wstrict-prototypes
|
| 156 |
|
|
CFLAGS += -Wundef
|
| 157 |
|
|
#CFLAGS += -Wunreachable-code
|
| 158 |
|
|
#CFLAGS += -Wsign-compare
|
| 159 |
|
|
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
|
| 160 |
|
|
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
| 161 |
|
|
CFLAGS += $(CSTANDARD)
|
| 162 |
|
|
|
| 163 |
|
|
|
| 164 |
|
|
#---------------- Compiler Options C++ ----------------
|
| 165 |
|
|
# -g*: generate debugging information
|
| 166 |
|
|
# -O*: optimization level
|
| 167 |
|
|
# -f...: tuning, see GCC manual and avr-libc documentation
|
| 168 |
|
|
# -Wall...: warning level
|
| 169 |
|
|
# -Wa,...: tell GCC to pass this to the assembler.
|
| 170 |
|
|
# -adhlns...: create assembler listing
|
| 171 |
|
|
CPPFLAGS = -g$(DEBUG)
|
| 172 |
|
|
CPPFLAGS += $(CPPDEFS)
|
| 173 |
|
|
CPPFLAGS += -O$(OPT)
|
| 174 |
|
|
#CPPFLAGS += -mint8
|
| 175 |
|
|
#CPPFLAGS += -mshort-calls
|
| 176 |
|
|
CPPFLAGS += -funsigned-char
|
| 177 |
|
|
CPPFLAGS += -funsigned-bitfields
|
| 178 |
|
|
CPPFLAGS += -fpack-struct
|
| 179 |
|
|
CPPFLAGS += -fshort-enums
|
| 180 |
|
|
CPPFLAGS += -fno-exceptions
|
| 181 |
|
|
#CPPFLAGS += -fno-unit-at-a-time
|
| 182 |
|
|
CPPFLAGS += -Wall
|
| 183 |
|
|
#CPPFLAGS += -Wstrict-prototypes
|
| 184 |
|
|
CFLAGS += -Wundef
|
| 185 |
|
|
#CPPFLAGS += -Wunreachable-code
|
| 186 |
|
|
#CPPFLAGS += -Wsign-compare
|
| 187 |
|
|
CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
|
| 188 |
|
|
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
| 189 |
|
|
#CPPFLAGS += $(CSTANDARD)
|
| 190 |
|
|
|
| 191 |
|
|
|
| 192 |
|
|
#---------------- Assembler Options ----------------
|
| 193 |
|
|
# -Wa,...: tell GCC to pass this to the assembler.
|
| 194 |
|
|
# -ahlms: create listing
|
| 195 |
|
|
# -gstabs: have the assembler create line number information; note that
|
| 196 |
|
|
# for use in COFF files, additional information about filenames
|
| 197 |
|
|
# and function names needs to be present in the assembler source
|
| 198 |
|
|
# files -- see avr-libc docs [FIXME: not yet described there]
|
| 199 |
|
|
ASFLAGS = -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs
|
| 200 |
|
|
|
| 201 |
|
|
|
| 202 |
|
|
#---------------- Library Options ----------------
|
| 203 |
|
|
# Minimalistic printf version
|
| 204 |
|
|
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
|
| 205 |
|
|
|
| 206 |
|
|
# Floating point printf version (requires MATH_LIB = -lm below)
|
| 207 |
|
|
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
|
| 208 |
|
|
|
| 209 |
|
|
# If this is left blank, then it will use the Standard printf version.
|
| 210 |
|
|
PRINTF_LIB =
|
| 211 |
|
|
#PRINTF_LIB = $(PRINTF_LIB_MIN)
|
| 212 |
|
|
PRINTF_LIB = $(PRINTF_LIB_FLOAT)
|
| 213 |
|
|
|
| 214 |
|
|
|
| 215 |
|
|
# Minimalistic scanf version
|
| 216 |
|
|
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
|
| 217 |
|
|
|
| 218 |
|
|
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
|
| 219 |
|
|
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
|
| 220 |
|
|
|
| 221 |
|
|
# If this is left blank, then it will use the Standard scanf version.
|
| 222 |
|
|
SCANF_LIB =
|
| 223 |
|
|
#SCANF_LIB = $(SCANF_LIB_MIN)
|
| 224 |
|
|
#SCANF_LIB = $(SCANF_LIB_FLOAT)
|
| 225 |
|
|
|
| 226 |
|
|
|
| 227 |
|
|
MATH_LIB = -lm
|
| 228 |
|
|
|
| 229 |
|
|
|
| 230 |
|
|
|
| 231 |
|
|
#---------------- External Memory Options ----------------
|
| 232 |
|
|
|
| 233 |
|
|
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
|
| 234 |
|
|
# used for variables (.data/.bss) and heap (malloc()).
|
| 235 |
|
|
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
|
| 236 |
|
|
|
| 237 |
|
|
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
|
| 238 |
|
|
# only used for heap (malloc()).
|
| 239 |
|
|
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
|
| 240 |
|
|
|
| 241 |
|
|
EXTMEMOPTS =
|
| 242 |
|
|
|
| 243 |
|
|
|
| 244 |
|
|
|
| 245 |
|
|
#---------------- Linker Options ----------------
|
| 246 |
|
|
# -Wl,...: tell GCC to pass this to linker.
|
| 247 |
|
|
# -Map: create map file
|
| 248 |
|
|
# --cref: add cross reference to map file
|
| 249 |
|
|
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
|
| 250 |
|
|
LDFLAGS += $(EXTMEMOPTS)
|
| 251 |
|
|
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
|
| 252 |
|
|
#LDFLAGS += -T linker_script.x
|
| 253 |
|
|
|
| 254 |
|
|
|
| 255 |
|
|
|
| 256 |
|
|
#---------------- Programming Options (avrdude) ----------------
|
| 257 |
|
|
|
| 258 |
|
|
# Programming hardware: alf avr910 avrisp bascom bsd
|
| 259 |
|
|
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
|
| 260 |
|
|
#
|
| 261 |
|
|
# Type: avrdude -c ?
|
| 262 |
|
|
# to get a full listing.
|
| 263 |
|
|
#
|
| 264 |
|
|
AVRDUDE_PROGRAMMER = stk500
|
| 265 |
|
|
|
| 266 |
|
|
# com1 = serial port. Use lpt1 to connect to parallel port.
|
| 267 |
|
|
AVRDUDE_PORT = com1 # programmer connected to serial device
|
| 268 |
|
|
|
| 269 |
|
|
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
|
| 270 |
|
|
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
|
| 271 |
|
|
|
| 272 |
|
|
|
| 273 |
|
|
# Uncomment the following if you want avrdude's erase cycle counter.
|
| 274 |
|
|
# Note that this counter needs to be initialized first using -Yn,
|
| 275 |
|
|
# see avrdude manual.
|
| 276 |
|
|
#AVRDUDE_ERASE_COUNTER = -y
|
| 277 |
|
|
|
| 278 |
|
|
# Uncomment the following if you do /not/ wish a verification to be
|
| 279 |
|
|
# performed after programming the device.
|
| 280 |
|
|
#AVRDUDE_NO_VERIFY = -V
|
| 281 |
|
|
|
| 282 |
|
|
# Increase verbosity level. Please use this when submitting bug
|
| 283 |
|
|
# reports about avrdude. See
|
| 284 |
|
|
# to submit bug reports.
|
| 285 |
|
|
#AVRDUDE_VERBOSE = -v -v
|
| 286 |
|
|
|
| 287 |
|
|
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
|
| 288 |
|
|
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
|
| 289 |
|
|
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
|
| 290 |
|
|
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
|
| 291 |
|
|
|
| 292 |
|
|
|
| 293 |
|
|
|
| 294 |
|
|
#---------------- Debugging Options ----------------
|
| 295 |
|
|
|
| 296 |
|
|
# For simulavr only - target MCU frequency.
|
| 297 |
|
|
DEBUG_MFREQ = $(F_CPU)
|
| 298 |
|
|
|
| 299 |
|
|
# Set the DEBUG_UI to either gdb or insight.
|
| 300 |
|
|
# DEBUG_UI = gdb
|
| 301 |
|
|
DEBUG_UI = insight
|
| 302 |
|
|
|
| 303 |
|
|
# Set the debugging back-end to either avarice, simulavr.
|
| 304 |
|
|
DEBUG_BACKEND = avarice
|
| 305 |
|
|
#DEBUG_BACKEND = simulavr
|
| 306 |
|
|
|
| 307 |
|
|
# GDB Init Filename.
|
| 308 |
|
|
GDBINIT_FILE = __avr_gdbinit
|
| 309 |
|
|
|
| 310 |
|
|
# When using avarice settings for the JTAG
|
| 311 |
|
|
JTAG_DEV = /dev/com1
|
| 312 |
|
|
|
| 313 |
|
|
# Debugging port used to communicate between GDB / avarice / simulavr.
|
| 314 |
|
|
DEBUG_PORT = 4242
|
| 315 |
|
|
|
| 316 |
|
|
# Debugging host used to communicate between GDB / avarice / simulavr, normally
|
| 317 |
|
|
# just set to localhost unless doing some sort of crazy debugging when
|
| 318 |
|
|
# avarice is running on a different computer.
|
| 319 |
|
|
DEBUG_HOST = localhost
|
| 320 |
|
|
|
| 321 |
|
|
|
| 322 |
|
|
|
| 323 |
|
|
#============================================================================
|
| 324 |
|
|
|
| 325 |
|
|
|
| 326 |
|
|
# Define programs and commands.
|
| 327 |
|
|
SHELL = sh
|
| 328 |
|
|
CC = avr-gcc
|
| 329 |
|
|
OBJCOPY = avr-objcopy
|
| 330 |
|
|
OBJDUMP = avr-objdump
|
| 331 |
|
|
SIZE = avr-size
|
| 332 |
|
|
NM = avr-nm
|
| 333 |
|
|
AVRDUDE = avrdude
|
| 334 |
|
|
REMOVE = rm -f
|
| 335 |
|
|
REMOVEDIR = rm -rf
|
| 336 |
|
|
COPY = cp
|
| 337 |
|
|
WINSHELL = cmd
|
| 338 |
|
|
|
| 339 |
|
|
|
| 340 |
|
|
# Define Messages
|
| 341 |
|
|
# English
|
| 342 |
|
|
MSG_ERRORS_NONE = Errors: none
|
| 343 |
|
|
MSG_BEGIN = -------- begin --------
|
| 344 |
|
|
MSG_END = -------- end --------
|
| 345 |
|
|
MSG_SIZE_BEFORE = Size before:
|
| 346 |
|
|
MSG_SIZE_AFTER = Size after:
|
| 347 |
|
|
MSG_COFF = Converting to AVR COFF:
|
| 348 |
|
|
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
|
| 349 |
|
|
MSG_FLASH = Creating load file for Flash:
|
| 350 |
|
|
MSG_EEPROM = Creating load file for EEPROM:
|
| 351 |
|
|
MSG_EXTENDED_LISTING = Creating Extended Listing:
|
| 352 |
|
|
MSG_SYMBOL_TABLE = Creating Symbol Table:
|
| 353 |
|
|
MSG_LINKING = Linking:
|
| 354 |
|
|
MSG_COMPILING = Compiling C:
|
| 355 |
|
|
MSG_COMPILING_CPP = Compiling C++:
|
| 356 |
|
|
MSG_ASSEMBLING = Assembling:
|
| 357 |
|
|
MSG_CLEANING = Cleaning project:
|
| 358 |
|
|
MSG_CREATING_LIBRARY = Creating library:
|
| 359 |
|
|
|
| 360 |
|
|
|
| 361 |
|
|
|
| 362 |
|
|
|
| 363 |
|
|
# Define all object files.
|
| 364 |
|
|
OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
|
| 365 |
|
|
|
| 366 |
|
|
# Define all listing files.
|
| 367 |
|
|
LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
|
| 368 |
|
|
|
| 369 |
|
|
|
| 370 |
|
|
# Compiler flags to generate dependency files.
|
| 371 |
|
|
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
|
| 372 |
|
|
|
| 373 |
|
|
|
| 374 |
|
|
# Combine all necessary flags and optional flags.
|
| 375 |
|
|
# Add target processor to flags.
|
| 376 |
|
|
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
|
| 377 |
|
|
ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
|
| 378 |
|
|
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
|
| 379 |
|
|
|
| 380 |
|
|
|
| 381 |
|
|
|
| 382 |
|
|
|
| 383 |
|
|
|
| 384 |
|
|
# Default target.
|
| 385 |
|
|
all: begin gccversion sizebefore build sizeafter end
|
| 386 |
|
|
|
| 387 |
|
|
# Change the build target to build a HEX file or a library.
|
| 388 |
|
|
build: elf hex eep lss sym
|
| 389 |
|
|
#build: lib
|
| 390 |
|
|
|
| 391 |
|
|
|
| 392 |
|
|
elf: $(TARGET).elf
|
| 393 |
|
|
hex: $(TARGET).hex
|
| 394 |
|
|
eep: $(TARGET).eep
|
| 395 |
|
|
lss: $(TARGET).lss
|
| 396 |
|
|
sym: $(TARGET).sym
|
| 397 |
|
|
LIBNAME=lib$(TARGET).a
|
| 398 |
|
|
lib: $(LIBNAME)
|
| 399 |
|
|
|
| 400 |
|
|
|
| 401 |
|
|
|
| 402 |
|
|
# Eye candy.
|
| 403 |
|
|
# AVR Studio 3.x does not check make's exit code but relies on
|
| 404 |
|
|
# the following magic strings to be generated by the compile job.
|
| 405 |
|
|
begin:
|
| 406 |
|
|
@echo
|
| 407 |
|
|
@echo $(MSG_BEGIN)
|
| 408 |
|
|
|
| 409 |
|
|
end:
|
| 410 |
|
|
@echo $(MSG_END)
|
| 411 |
|
|
@echo
|
| 412 |
|
|
|
| 413 |
|
|
|
| 414 |
|
|
# Display size of file.
|
| 415 |
|
|
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
|
| 416 |
|
|
ELFSIZE = $(SIZE) -A $(TARGET).elf
|
| 417 |
|
|
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
|
| 418 |
|
|
|
| 419 |
|
|
sizebefore:
|
| 420 |
|
|
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
|
| 421 |
|
|
$(AVRMEM) 2>/dev/null; echo; fi
|
| 422 |
|
|
|
| 423 |
|
|
sizeafter:
|
| 424 |
|
|
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
|
| 425 |
|
|
$(AVRMEM) 2>/dev/null; echo; fi
|
| 426 |
|
|
|
| 427 |
|
|
|
| 428 |
|
|
|
| 429 |
|
|
# Display compiler version information.
|
| 430 |
|
|
gccversion :
|
| 431 |
|
|
@$(CC) --version
|
| 432 |
|
|
|
| 433 |
|
|
|
| 434 |
|
|
|
| 435 |
|
|
# Program the device.
|
| 436 |
|
|
program: $(TARGET).hex $(TARGET).eep
|
| 437 |
|
|
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
|
| 438 |
|
|
|
| 439 |
|
|
|
| 440 |
|
|
# Generate avr-gdb config/init file which does the following:
|
| 441 |
|
|
# define the reset signal, load the target file, connect to target, and set
|
| 442 |
|
|
# a breakpoint at main().
|
| 443 |
|
|
gdb-config:
|
| 444 |
|
|
@$(REMOVE) $(GDBINIT_FILE)
|
| 445 |
|
|
@echo define reset >> $(GDBINIT_FILE)
|
| 446 |
|
|
@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
|
| 447 |
|
|
@echo end >> $(GDBINIT_FILE)
|
| 448 |
|
|
@echo file $(TARGET).elf >> $(GDBINIT_FILE)
|
| 449 |
|
|
@echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
|
| 450 |
|
|
ifeq ($(DEBUG_BACKEND),simulavr)
|
| 451 |
|
|
@echo load >> $(GDBINIT_FILE)
|
| 452 |
|
|
endif
|
| 453 |
|
|
@echo break main >> $(GDBINIT_FILE)
|
| 454 |
|
|
|
| 455 |
|
|
debug: gdb-config $(TARGET).elf
|
| 456 |
|
|
ifeq ($(DEBUG_BACKEND), avarice)
|
| 457 |
|
|
@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
|
| 458 |
|
|
@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
|
| 459 |
|
|
$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
|
| 460 |
|
|
@$(WINSHELL) /c pause
|
| 461 |
|
|
|
| 462 |
|
|
else
|
| 463 |
|
|
@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
|
| 464 |
|
|
$(DEBUG_MFREQ) --port $(DEBUG_PORT)
|
| 465 |
|
|
endif
|
| 466 |
|
|
@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
|
| 467 |
|
|
|
| 468 |
|
|
|
| 469 |
|
|
|
| 470 |
|
|
|
| 471 |
|
|
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
|
| 472 |
|
|
COFFCONVERT = $(OBJCOPY) --debugging
|
| 473 |
|
|
COFFCONVERT += --change-section-address .data-0x800000
|
| 474 |
|
|
COFFCONVERT += --change-section-address .bss-0x800000
|
| 475 |
|
|
COFFCONVERT += --change-section-address .noinit-0x800000
|
| 476 |
|
|
COFFCONVERT += --change-section-address .eeprom-0x810000
|
| 477 |
|
|
|
| 478 |
|
|
|
| 479 |
|
|
|
| 480 |
|
|
coff: $(TARGET).elf
|
| 481 |
|
|
@echo
|
| 482 |
|
|
@echo $(MSG_COFF) $(TARGET).cof
|
| 483 |
|
|
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
|
| 484 |
|
|
|
| 485 |
|
|
|
| 486 |
|
|
extcoff: $(TARGET).elf
|
| 487 |
|
|
@echo
|
| 488 |
|
|
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
|
| 489 |
|
|
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
|
| 490 |
|
|
|
| 491 |
|
|
|
| 492 |
|
|
|
| 493 |
|
|
# Create final output files (.hex, .eep) from ELF output file.
|
| 494 |
|
|
%.hex: %.elf
|
| 495 |
|
|
@echo
|
| 496 |
|
|
@echo $(MSG_FLASH) $@
|
| 497 |
|
|
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
|
| 498 |
|
|
|
| 499 |
|
|
%.eep: %.elf
|
| 500 |
|
|
@echo
|
| 501 |
|
|
@echo $(MSG_EEPROM) $@
|
| 502 |
|
|
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
|
| 503 |
|
|
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
|
| 504 |
|
|
|
| 505 |
|
|
# Create extended listing file from ELF output file.
|
| 506 |
|
|
%.lss: %.elf
|
| 507 |
|
|
@echo
|
| 508 |
|
|
@echo $(MSG_EXTENDED_LISTING) $@
|
| 509 |
|
|
$(OBJDUMP) -h -S $< > $@
|
| 510 |
|
|
|
| 511 |
|
|
# Create a symbol table from ELF output file.
|
| 512 |
|
|
%.sym: %.elf
|
| 513 |
|
|
@echo
|
| 514 |
|
|
@echo $(MSG_SYMBOL_TABLE) $@
|
| 515 |
|
|
$(NM) -n $< > $@
|
| 516 |
|
|
|
| 517 |
|
|
|
| 518 |
|
|
|
| 519 |
|
|
# Create library from object files.
|
| 520 |
|
|
.SECONDARY : $(TARGET).a
|
| 521 |
|
|
.PRECIOUS : $(OBJ)
|
| 522 |
|
|
%.a: $(OBJ)
|
| 523 |
|
|
@echo
|
| 524 |
|
|
@echo $(MSG_CREATING_LIBRARY) $@
|
| 525 |
|
|
$(AR) $@ $(OBJ)
|
| 526 |
|
|
|
| 527 |
|
|
|
| 528 |
|
|
# Link: create ELF output file from object files.
|
| 529 |
|
|
.SECONDARY : $(TARGET).elf
|
| 530 |
|
|
.PRECIOUS : $(OBJ)
|
| 531 |
|
|
%.elf: $(OBJ)
|
| 532 |
|
|
@echo
|
| 533 |
|
|
@echo $(MSG_LINKING) $@
|
| 534 |
|
|
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
|
| 535 |
|
|
|
| 536 |
|
|
|
| 537 |
|
|
# Compile: create object files from C source files.
|
| 538 |
|
|
$(OBJDIR)/%.o : %.c
|
| 539 |
|
|
@echo
|
| 540 |
|
|
@echo $(MSG_COMPILING) $<
|
| 541 |
|
|
$(CC) -c $(ALL_CFLAGS) $< -o $@
|
| 542 |
|
|
|
| 543 |
|
|
|
| 544 |
|
|
# Compile: create object files from C++ source files.
|
| 545 |
|
|
$(OBJDIR)/%.o : %.cpp
|
| 546 |
|
|
@echo
|
| 547 |
|
|
@echo $(MSG_COMPILING_CPP) $<
|
| 548 |
|
|
$(CC) -c $(ALL_CPPFLAGS) $< -o $@
|
| 549 |
|
|
|
| 550 |
|
|
|
| 551 |
|
|
# Compile: create assembler files from C source files.
|
| 552 |
|
|
%.s : %.c
|
| 553 |
|
|
$(CC) -S $(ALL_CFLAGS) $< -o $@
|
| 554 |
|
|
|
| 555 |
|
|
|
| 556 |
|
|
# Compile: create assembler files from C++ source files.
|
| 557 |
|
|
%.s : %.cpp
|
| 558 |
|
|
$(CC) -S $(ALL_CPPFLAGS) $< -o $@
|
| 559 |
|
|
|
| 560 |
|
|
|
| 561 |
|
|
# Assemble: create object files from assembler source files.
|
| 562 |
|
|
$(OBJDIR)/%.o : %.S
|
| 563 |
|
|
@echo
|
| 564 |
|
|
@echo $(MSG_ASSEMBLING) $<
|
| 565 |
|
|
$(CC) -c $(ALL_ASFLAGS) $< -o $@
|
| 566 |
|
|
|
| 567 |
|
|
|
| 568 |
|
|
# Create preprocessed source for use in sending a bug report.
|
| 569 |
|
|
%.i : %.c
|
| 570 |
|
|
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
|
| 571 |
|
|
|
| 572 |
|
|
|
| 573 |
|
|
# Target: clean project.
|
| 574 |
|
|
clean: begin clean_list end
|
| 575 |
|
|
|
| 576 |
|
|
clean_list :
|
| 577 |
|
|
@echo
|
| 578 |
|
|
@echo $(MSG_CLEANING)
|
| 579 |
|
|
$(REMOVE) $(TARGET).hex
|
| 580 |
|
|
$(REMOVE) $(TARGET).eep
|
| 581 |
|
|
$(REMOVE) $(TARGET).cof
|
| 582 |
|
|
$(REMOVE) $(TARGET).elf
|
| 583 |
|
|
$(REMOVE) $(TARGET).map
|
| 584 |
|
|
$(REMOVE) $(TARGET).sym
|
| 585 |
|
|
$(REMOVE) $(TARGET).lss
|
| 586 |
|
|
$(REMOVEDIR) $(OBJDIR)
|
| 587 |
|
|
$(REMOVE) $(SRC:.c=.s)
|
| 588 |
|
|
$(REMOVE) $(SRC:.c=.d)
|
| 589 |
|
|
$(REMOVEDIR) .dep
|
| 590 |
|
|
|
| 591 |
|
|
|
| 592 |
|
|
# Create object files directory
|
| 593 |
|
|
$(shell mkdir $(OBJDIR) 2>/dev/null)
|
| 594 |
|
|
|
| 595 |
|
|
|
| 596 |
|
|
# Include the dependency files.
|
| 597 |
|
|
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
|
| 598 |
|
|
|
| 599 |
|
|
|
| 600 |
|
|
# Listing of phony targets.
|
| 601 |
|
|
.PHONY : all begin finish end sizebefore sizeafter gccversion \
|
| 602 |
|
|
build elf hex eep lss sym coff extcoff \
|
| 603 |
|
|
clean clean_list program debug gdb-config
|
| 604 |
|
|
|
| 605 |
|
|
|