Subversion Repositories Projects

Rev

Rev 1307 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1307 Rev 1308
Line -... Line 1...
-
 
1
# Hey Emacs, this is a -*- makefile -*-
-
 
2
#
-
 
3
# Makefile for the AVRProg-compatible Bootloader
-
 
4
#
-
 
5
# based on the 
-
 
6
# WinAVR Sample makefile written by Eric B. Weddington, Jörg Wunsch, et al.
-
 
7
# Released to the Public Domain
-
 
8
# Please read the make user manual!
-
 
9
#
-
 
10
# Additional material for this makefile was submitted by:
-
 
11
#  Tim Henigan
-
 
12
#  Peter Fleury
-
 
13
#  Reiner Patommel
-
 
14
#  Sander Pool
-
 
15
#  Frederik Rouleau
-
 
16
#  Markus Pfaff
-
 
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 (for use with AVR Studio 3.x or VMLAB).
-
 
25
#
-
 
26
# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
-
 
27
#                4.07 or greater).
-
 
28
#
-
 
29
# make program = Download the hex file to the device, using avrdude.  Please
-
 
30
#                customize the avrdude settings below first!
-
 
31
#
-
 
32
# make filename.s = Just compile filename.c into the assembler code only
-
 
33
#
-
 
34
# To rebuild project do "make clean" then "make all".
-
 
35
#
-
 
36
 
-
 
37
# user defined values
-
 
38
 
-
 
39
# MCU name
-
 
40
## MCU = atmega8
-
 
41
## MCU = atmega16
-
 
42
## MCU = atmega162
-
 
43
## MCU = atmega169
-
 
44
## MCU = atmega32
-
 
45
## MCU = atmega324p
-
 
46
## MCU = atmega64
-
 
47
## MCU = atmega644
-
 
48
MCU = atmega644p
-
 
49
## MCU = atmega128
-
 
50
## MCU = at90can128
-
 
51
 
-
 
52
################## BOOTLOADER ######################
-
 
53
#  mt: Boot loader support. So far not done with a separate section
-
 
54
#  to get the interrupt vector into the bootloader area (for BOOTINTVEC=yes).
-
 
55
#  Bootloader address in datasheet and stk500 is given as
-
 
56
#  "word", gcc toolchain needs "byte"-address
-
 
57
#  (see LDFLAGS further down)
-
 
58
 
-
 
59
#/* Select Boot Size in Words (select one, comment out the others) */
-
 
60
## NO! BOOTSIZE=128
-
 
61
## NO! BOOTSIZE=256
-
 
62
## BOOTSIZE=512
-
 
63
BOOTSIZE=1024
-
 
64
## BOOTSIZE=2048
-
 
65
 
-
 
66
# /* Select if bootloader should include the inverrupt-vectors 
-
 
67
# when selecting 'no' here, the bootloader must not use
-
 
68
# any interrupts and the modified linker-scripts are used. */
-
 
69
##BOOTINTVEC=yes
-
 
70
BOOTINTVEC=no
-
 
71
 
-
 
72
##
-
 
73
ifeq ($(MCU), atmega8)
-
 
74
BFD_MACH=avr4
-
 
75
ifeq ($(BOOTSIZE), 128)
-
 
76
	MT_BOOTLOADER_ADDRESS = 0x1F00
-
 
77
endif
-
 
78
ifeq ($(BOOTSIZE), 256)
-
 
79
	MT_BOOTLOADER_ADDRESS = 0x1E00
-
 
80
endif
-
 
81
ifeq ($(BOOTSIZE), 512)
-
 
82
	MT_BOOTLOADER_ADDRESS = 0x1C00
-
 
83
endif
-
 
84
ifeq ($(BOOTSIZE), 1024)
-
 
85
	MT_BOOTLOADER_ADDRESS = 0x1800
-
 
86
endif
-
 
87
endif
-
 
88
 
-
 
89
##
-
 
90
ifeq ($(MCU), atmega16)
-
 
91
BFD_MACH=avr5
-
 
92
ifeq ($(BOOTSIZE), 128)
-
 
93
	MT_BOOTLOADER_ADDRESS = 0x3F00
-
 
94
endif
-
 
95
ifeq ($(BOOTSIZE), 256)
-
 
96
	MT_BOOTLOADER_ADDRESS = 0x3E00
-
 
97
endif
-
 
98
ifeq ($(BOOTSIZE), 512)
-
 
99
	MT_BOOTLOADER_ADDRESS = 0x3C00
-
 
100
endif
-
 
101
ifeq ($(BOOTSIZE), 1024)
-
 
102
	MT_BOOTLOADER_ADDRESS = 0x3800
-
 
103
endif
-
 
104
endif
-
 
105
 
-
 
106
##
-
 
107
ifeq ($(MCU), atmega162)
-
 
108
BFD_MACH=avr5
-
 
109
ifeq ($(BOOTSIZE), 128)
-
 
110
	MT_BOOTLOADER_ADDRESS = 0x3F00
-
 
111
endif
-
 
112
ifeq ($(BOOTSIZE), 256)
-
 
113
	MT_BOOTLOADER_ADDRESS = 0x3E00
-
 
114
endif
-
 
115
ifeq ($(BOOTSIZE), 512)
-
 
116
	MT_BOOTLOADER_ADDRESS = 0x3C00
-
 
117
endif
-
 
118
ifeq ($(BOOTSIZE), 1024)
-
 
119
	MT_BOOTLOADER_ADDRESS = 0x3800
-
 
120
endif
-
 
121
endif
-
 
122
 
-
 
123
##
-
 
124
ifeq ($(MCU), atmega169)
-
 
125
BFD_MACH=avr5
-
 
126
ifeq ($(BOOTSIZE), 128)
-
 
127
	MT_BOOTLOADER_ADDRESS = 0x3F00
-
 
128
endif
-
 
129
ifeq ($(BOOTSIZE), 256)
-
 
130
	MT_BOOTLOADER_ADDRESS = 0x3E00
-
 
131
endif
-
 
132
ifeq ($(BOOTSIZE), 512)
-
 
133
	MT_BOOTLOADER_ADDRESS = 0x3C00
-
 
134
endif
-
 
135
ifeq ($(BOOTSIZE), 1024)
-
 
136
	MT_BOOTLOADER_ADDRESS = 0x3800
-
 
137
endif
-
 
138
endif
-
 
139
 
-
 
140
##
-
 
141
ifeq ($(MCU), atmega32)
-
 
142
BFD_MACH=avr5
-
 
143
ifeq ($(BOOTSIZE), 256)
-
 
144
	MT_BOOTLOADER_ADDRESS = 0x7E00
-
 
145
endif
-
 
146
ifeq ($(BOOTSIZE), 512)
-
 
147
	MT_BOOTLOADER_ADDRESS = 0x7C00
-
 
148
endif
-
 
149
ifeq ($(BOOTSIZE), 1024)
-
 
150
	MT_BOOTLOADER_ADDRESS = 0x7800
-
 
151
endif
-
 
152
ifeq ($(BOOTSIZE), 2048)
-
 
153
	MT_BOOTLOADER_ADDRESS = 0x7000
-
 
154
endif
-
 
155
endif
-
 
156
 
-
 
157
##
-
 
158
ifeq ($(MCU), atmega324p)
-
 
159
BFD_MACH=avr5
-
 
160
ifeq ($(BOOTSIZE), 256)
-
 
161
	MT_BOOTLOADER_ADDRESS = 0x7E00
-
 
162
endif
-
 
163
ifeq ($(BOOTSIZE), 512)
-
 
164
	MT_BOOTLOADER_ADDRESS = 0x7C00
-
 
165
endif
-
 
166
ifeq ($(BOOTSIZE), 1024)
-
 
167
	MT_BOOTLOADER_ADDRESS = 0x7800
-
 
168
endif
-
 
169
ifeq ($(BOOTSIZE), 2048)
-
 
170
	MT_BOOTLOADER_ADDRESS = 0x7000
-
 
171
endif
-
 
172
endif
-
 
173
 
-
 
174
##
-
 
175
ifeq ($(MCU), atmega64)
-
 
176
BFD_MACH=avr5
-
 
177
ifeq ($(BOOTSIZE), 512)
-
 
178
	MT_BOOTLOADER_ADDRESS = 0xFC00
-
 
179
endif
-
 
180
ifeq ($(BOOTSIZE), 1024)
-
 
181
	MT_BOOTLOADER_ADDRESS = 0xF800
-
 
182
endif
-
 
183
ifeq ($(BOOTSIZE), 2048)
-
 
184
	MT_BOOTLOADER_ADDRESS = 0xF000
-
 
185
endif
-
 
186
ifeq ($(BOOTSIZE), 4096)
-
 
187
	MT_BOOTLOADER_ADDRESS = 0xE000
-
 
188
endif
-
 
189
endif
-
 
190
 
-
 
191
##
-
 
192
ifeq ($(MCU), atmega644)
-
 
193
BFD_MACH=avr5
-
 
194
ifeq ($(BOOTSIZE), 512)
-
 
195
	MT_BOOTLOADER_ADDRESS = 0xFC00
-
 
196
endif
-
 
197
ifeq ($(BOOTSIZE), 1024)
-
 
198
	MT_BOOTLOADER_ADDRESS = 0xF800
-
 
199
endif
-
 
200
ifeq ($(BOOTSIZE), 2048)
-
 
201
	MT_BOOTLOADER_ADDRESS = 0xF000
-
 
202
endif
-
 
203
ifeq ($(BOOTSIZE), 4096)
-
 
204
	MT_BOOTLOADER_ADDRESS = 0xE000
-
 
205
endif
-
 
206
endif
-
 
207
 
-
 
208
##
-
 
209
ifeq ($(MCU), atmega644p)
-
 
210
BFD_MACH=avr5
-
 
211
ifeq ($(BOOTSIZE), 512)
-
 
212
	MT_BOOTLOADER_ADDRESS = 0xFC00
-
 
213
endif
-
 
214
ifeq ($(BOOTSIZE), 1024)
-
 
215
	MT_BOOTLOADER_ADDRESS = 0xF800
-
 
216
endif
-
 
217
ifeq ($(BOOTSIZE), 2048)
-
 
218
	MT_BOOTLOADER_ADDRESS = 0xF000
-
 
219
endif
-
 
220
ifeq ($(BOOTSIZE), 4096)
-
 
221
	MT_BOOTLOADER_ADDRESS = 0xE000
-
 
222
endif
-
 
223
endif
-
 
224
 
-
 
225
##
-
 
226
ifeq ($(MCU), atmega128)
-
 
227
BFD_MACH=avr5
-
 
228
ifeq ($(BOOTSIZE), 512)
-
 
229
	MT_BOOTLOADER_ADDRESS = 0x1FC00
-
 
230
endif
-
 
231
ifeq ($(BOOTSIZE), 1024)
-
 
232
	MT_BOOTLOADER_ADDRESS = 0x1F800
-
 
233
endif
-
 
234
ifeq ($(BOOTSIZE), 2048)
-
 
235
	MT_BOOTLOADER_ADDRESS = 0x1F000
-
 
236
endif
-
 
237
ifeq ($(BOOTSIZE), 4096)
-
 
238
	MT_BOOTLOADER_ADDRESS = 0x1E000
-
 
239
endif
-
 
240
endif
-
 
241
 
-
 
242
##
-
 
243
ifeq ($(MCU), at90can128)
-
 
244
BFD_MACH=avr5
-
 
245
ifeq ($(BOOTSIZE), 512)
-
 
246
	MT_BOOTLOADER_ADDRESS = 0x1FC00
-
 
247
endif
-
 
248
ifeq ($(BOOTSIZE), 1024)
-
 
249
	MT_BOOTLOADER_ADDRESS = 0x1F800
-
 
250
endif
-
 
251
ifeq ($(BOOTSIZE), 2048)
-
 
252
	MT_BOOTLOADER_ADDRESS = 0x1F000
-
 
253
endif
-
 
254
ifeq ($(BOOTSIZE), 4096)
-
 
255
	MT_BOOTLOADER_ADDRESS = 0x1E000
-
 
256
endif
-
 
257
endif
-
 
258
 
-
 
259
 
-
 
260
# Output format. (can be srec, ihex, binary)
-
 
261
FORMAT = ihex
-
 
262
#FORMAT = srec
-
 
263
 
-
 
264
# Target file name (without extension).
-
 
265
TARGET = main
-
 
266
 
-
 
267
 
-
 
268
# List C source files here. (C dependencies are automatically generated.)
-
 
269
SRC = $(TARGET).c
-
 
270
 
-
 
271
 
-
 
272
# List Assembler source files here.
-
 
273
# Make them always end in a capital .S.  Files ending in a lowercase .s
-
 
274
# will not be considered source files but generated files (assembler
-
 
275
# output from the compiler), and will be deleted upon "make clean"!
-
 
276
# Even though the DOS/Win* filesystem matches both .s and .S the same,
-
 
277
# it will preserve the spelling of the filenames, and gcc itself does
-
 
278
# care about how the name is spelled on its command-line.
-
 
279
ASRC =
-
 
280
 
-
 
281
 
-
 
282
 
-
 
283
# Optimization level, can be [0, 1, 2, 3, s].
-
 
284
# 0 = turn off optimization. s = optimize for size.
-
 
285
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
-
 
286
OPT = s
-
 
287
 
-
 
288
# Debugging format.
-
 
289
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
-
 
290
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
-
 
291
DEBUG = stabs
-
 
292
 
-
 
293
# List any extra directories to look for include files here.
-
 
294
#     Each directory must be seperated by a space.
-
 
295
EXTRAINCDIRS =
-
 
296
 
-
 
297
 
-
 
298
# Compiler flag to set the C Standard level.
-
 
299
# c89   - "ANSI" C
-
 
300
# gnu89 - c89 plus GCC extensions
-
 
301
# c99   - ISO C99 standard (not yet fully implemented)
-
 
302
# gnu99 - c99 plus GCC extensions
-
 
303
CSTANDARD = -std=gnu99
-
 
304
 
-
 
305
# Place -D or -U options here
-
 
306
CDEFS = -DBOOTSIZE=$(BOOTSIZE)
-
 
307
 
-
 
308
# Place -I options here
-
 
309
CINCS =
-
 
310
 
-
 
311
 
-
 
312
# Compiler flags.
-
 
313
#  -g*:          generate debugging information
-
 
314
#  -O*:          optimization level
-
 
315
#  -f...:        tuning, see GCC manual and avr-libc documentation
-
 
316
#  -Wall...:     warning level
-
 
317
#  -Wa,...:      tell GCC to pass this to the assembler.
-
 
318
#    -adhlns...: create assembler listing
-
 
319
CFLAGS = -g$(DEBUG)
-
 
320
CFLAGS += $(CDEFS) $(CINCS)
-
 
321
CFLAGS += -O$(OPT)
-
 
322
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
-
 
323
CFLAGS += -Wall -Wstrict-prototypes
-
 
324
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
-
 
325
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
-
 
326
CFLAGS += $(CSTANDARD)
-
 
327
 
-
 
328
 
-
 
329
 
-
 
330
# Assembler flags.
-
 
331
#  -Wa,...:   tell GCC to pass this to the assembler.
-
 
332
#  -ahlms:    create listing
-
 
333
#  -gstabs:   have the assembler create line number information; note that
-
 
334
#             for use in COFF files, additional information about filenames
-
 
335
#             and function names needs to be present in the assembler source
-
 
336
#             files -- see avr-libc docs [FIXME: not yet described there]
-
 
337
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
-
 
338
 
-
 
339
 
-
 
340
 
-
 
341
#Additional libraries.
-
 
342
 
-
 
343
# Minimalistic printf version
-
 
344
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
-
 
345
 
-
 
346
# Floating point printf version (requires MATH_LIB = -lm below)
-
 
347
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
-
 
348
 
-
 
349
PRINTF_LIB =
-
 
350
 
-
 
351
# Minimalistic scanf version
-
 
352
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
-
 
353
 
-
 
354
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
-
 
355
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
-
 
356
 
-
 
357
SCANF_LIB =
-
 
358
 
-
 
359
MATH_LIB = -lm
-
 
360
 
-
 
361
# External memory options
-
 
362
 
-
 
363
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
-
 
364
# used for variables (.data/.bss) and heap (malloc()).
-
 
365
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
-
 
366
 
-
 
367
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
-
 
368
# only used for heap (malloc()).
-
 
369
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
-
 
370
 
-
 
371
EXTMEMOPTS =
-
 
372
 
-
 
373
# Linker flags.
-
 
374
#  -Wl,...:     tell GCC to pass this to linker.
-
 
375
#    -Map:      create map file
-
 
376
#    --cref:    add cross reference to  map file
-
 
377
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
-
 
378
LDFLAGS += $(EXTMEMOPTS)
-
 
379
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
-
 
380
 
-
 
381
################## BOOTLOADER ######################
-
 
382
# MT_BOOTLOADER_ADDRESS (=Start of Boot Loader section
-
 
383
# in bytes - not words) as defined above.
-
 
384
LDFLAGS += -Wl,--section-start=.text=$(MT_BOOTLOADER_ADDRESS)
-
 
385
 
-
 
386
# check if linker-scripts without interrupt-vectors should
-
 
387
# be used and set linker-option, announce to C-code by define
-
 
388
ifeq ($(BOOTINTVEC), no)
-
 
389
LDFLAGS += -T./ldscripts_no_vector/$(BFD_MACH).x
-
 
390
CFLAGS  += -DBOOTLOADERHASNOVECTORS
-
 
391
endif
-
 
392
 
-
 
393
 
-
 
394
# Programming support using avrdude. Settings and variables.
-
 
395
 
-
 
396
# Programming hardware: alf avr910 avrisp bascom bsd
-
 
397
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
-
 
398
#
-
 
399
# Type: avrdude -c ?
-
 
400
# to get a full listing.
-
 
401
#
-
 
402
AVRDUDE_PROGRAMMER = stk500v2
-
 
403
 
-
 
404
# com1 = serial port. Use lpt1 to connect to parallel port.
-
 
405
AVRDUDE_PORT = com1    # programmer connected to serial device
-
 
406
#AVRDUDE_PORT = /dev/ttyS0    # programmer connected to serial device
-
 
407
 
-
 
408
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
-
 
409
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
-
 
410
 
-
 
411
 
-
 
412
# Uncomment the following if you want avrdude's erase cycle counter.
-
 
413
# Note that this counter needs to be initialized first using -Yn,
-
 
414
# see avrdude manual.
-
 
415
#AVRDUDE_ERASE_COUNTER = -y
-
 
416
 
-
 
417
# Uncomment the following if you do /not/ wish a verification to be
-
 
418
# performed after programming the device.
-
 
419
#AVRDUDE_NO_VERIFY = -V
-
 
420
 
-
 
421
# Increase verbosity level.  Please use this when submitting bug
-
 
422
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
-
 
423
# to submit bug reports.
-
 
424
#AVRDUDE_VERBOSE = -v -v
-
 
425
 
-
 
426
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
-
 
427
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
-
 
428
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
-
 
429
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
-
 
430
 
-
 
431
 
-
 
432
 
-
 
433
# ---------------------------------------------------------------------------
-
 
434
 
-
 
435
# Define directories, if needed.
-
 
436
#DIRAVR = c:/winavr
-
 
437
#DIRAVRBIN = $(DIRAVR)/bin
-
 
438
#DIRAVRUTILS = $(DIRAVR)/utils/bin
-
 
439
#DIRINC = .
-
 
440
#DIRLIB = $(DIRAVR)/avr/lib
-
 
441
 
-
 
442
 
-
 
443
# Define programs and commands.
-
 
444
#SHELL = $(DIRAVRUTILS)/sh
-
 
445
#NM = $(DIRAVRBIN)/avr-nm
-
 
446
#CC = $(DIRAVRBIN)/avr-gcc
-
 
447
#OBJCOPY = $(DIRAVRBIN)/avr-objcopy
-
 
448
#OBJDUMP= $(DIRAVRBIN)/avr-objdump
-
 
449
#SIZE = $(DIRAVRBIN)/avr-size
-
 
450
#AVRDUDE = $(DIRAVRBIN)/avrdude.sh
-
 
451
#REMOVE = rm -f
-
 
452
#COPY = cp
-
 
453
 
-
 
454
# Define programs and commands.
-
 
455
SHELL = sh
-
 
456
CC = avr-gcc
-
 
457
OBJCOPY = avr-objcopy
-
 
458
OBJDUMP = avr-objdump
-
 
459
SIZE = avr-size
-
 
460
NM = avr-nm
-
 
461
AVRDUDE = avrdude
-
 
462
REMOVE = rm -f
-
 
463
COPY = cp
-
 
464
WINSHELL = cmd
-
 
465
 
-
 
466
 
-
 
467
# Define Messages
-
 
468
# English
-
 
469
MSG_ERRORS_NONE = Errors: none
-
 
470
MSG_BEGIN = -------- begin --------
-
 
471
MSG_END = --------  end  --------
-
 
472
MSG_SIZE_BEFORE = Size before:
-
 
473
MSG_SIZE_AFTER = Size after:
-
 
474
MSG_COFF = Converting to AVR COFF:
-
 
475
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
-
 
476
MSG_FLASH = Creating load file for Flash:
-
 
477
MSG_EEPROM = Creating load file for EEPROM:
-
 
478
MSG_EXTENDED_LISTING = Creating Extended Listing:
-
 
479
MSG_SYMBOL_TABLE = Creating Symbol Table:
-
 
480
MSG_LINKING = Linking:
-
 
481
MSG_COMPILING = Compiling:
-
 
482
MSG_ASSEMBLING = Assembling:
-
 
483
MSG_CLEANING = Cleaning project:
-
 
484
 
-
 
485
 
-
 
486
 
-
 
487
 
-
 
488
# Define all object files.
-
 
489
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
-
 
490
 
-
 
491
# Define all listing files.
-
 
492
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
-
 
493
 
-
 
494
 
-
 
495
# Compiler flags to generate dependency files.
-
 
496
### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
-
 
497
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
-
 
498
 
-
 
499
# Combine all necessary flags and optional flags.
-
 
500
# Add target processor to flags.
-
 
501
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
-
 
502
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
-
 
503
 
-
 
504
 
-
 
505
 
-
 
506
 
-
 
507
 
-
 
508
# Default target.
-
 
509
all: begin gccversion sizebefore build sizeafter finished end
-
 
510
 
-
 
511
build: elf hex eep lss sym
-
 
512
 
-
 
513
elf: $(TARGET).elf
-
 
514
hex: $(TARGET).hex
-
 
515
eep: $(TARGET).eep
-
 
516
lss: $(TARGET).lss
-
 
517
sym: $(TARGET).sym
-
 
518
 
-
 
519
 
-
 
520
 
-
 
521
# Eye candy.
-
 
522
# AVR Studio 3.x does not check make's exit code but relies on
-
 
523
# the following magic strings to be generated by the compile job.
-
 
524
begin:
-
 
525
	@echo
-
 
526
	@echo $(MSG_BEGIN)
-
 
527
 
-
 
528
finished:
-
 
529
	@echo $(MSG_ERRORS_NONE)
-
 
530
 
-
 
531
end:
-
 
532
	@echo $(MSG_END)
-
 
533
	@echo
-
 
534
 
-
 
535
 
-
 
536
# Display size of file.
-
 
537
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
-
 
538
ELFSIZE = $(SIZE) -x -A $(TARGET).elf
-
 
539
sizebefore:
-
 
540
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
-
 
541
 
-
 
542
sizeafter:
-
 
543
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
-
 
544
 
-
 
545
 
-
 
546
 
-
 
547
# Display compiler version information.
-
 
548
gccversion :
-
 
549
	@$(CC) --version
-
 
550
 
-
 
551
 
-
 
552
 
-
 
553
# Program the device.
-
 
554
program: $(TARGET).hex $(TARGET).eep
-
 
555
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
-
 
556
 
-
 
557
 
-
 
558
 
-
 
559
 
-
 
560
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
-
 
561
COFFCONVERT=$(OBJCOPY) --debugging \
-
 
562
--change-section-address .data-0x800000 \
-
 
563
--change-section-address .bss-0x800000 \
-
 
564
--change-section-address .noinit-0x800000 \
-
 
565
--change-section-address .eeprom-0x810000
-
 
566
 
-
 
567
 
-
 
568
coff: $(TARGET).elf
-
 
569
	@echo
-
 
570
	@echo $(MSG_COFF) $(TARGET).cof
-
 
571
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
-
 
572
 
-
 
573
 
-
 
574
extcoff: $(TARGET).elf
-
 
575
	@echo
-
 
576
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
-
 
577
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
-
 
578
 
-
 
579
 
-
 
580
 
-
 
581
# Create final output files (.hex, .eep) from ELF output file.
-
 
582
%.hex: %.elf
-
 
583
	@echo
-
 
584
	@echo $(MSG_FLASH) $@
-
 
585
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
-
 
586
 
-
 
587
%.eep: %.elf
-
 
588
	@echo
-
 
589
	@echo $(MSG_EEPROM) $@
-
 
590
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
-
 
591
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
-
 
592
 
-
 
593
# Create extended listing file from ELF output file.
-
 
594
%.lss: %.elf
-
 
595
	@echo
-
 
596
	@echo $(MSG_EXTENDED_LISTING) $@
-
 
597
	$(OBJDUMP) -h -S $< > $@
-
 
598
 
-
 
599
# Create a symbol table from ELF output file.
-
 
600
%.sym: %.elf
-
 
601
	@echo
-
 
602
	@echo $(MSG_SYMBOL_TABLE) $@
-
 
603
	$(NM) -n $< > $@
-
 
604
 
-
 
605
 
-
 
606
 
-
 
607
# Link: create ELF output file from object files.
-
 
608
.SECONDARY : $(TARGET).elf
-
 
609
.PRECIOUS : $(OBJ)
-
 
610
%.elf: $(OBJ)
-
 
611
	@echo
-
 
612
	@echo $(MSG_LINKING) $@
-
 
613
	$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
-
 
614
 
-
 
615
 
-
 
616
# Compile: create object files from C source files.
-
 
617
%.o : %.c
-
 
618
	@echo
-
 
619
	@echo $(MSG_COMPILING) $<
-
 
620
	$(CC) -c $(ALL_CFLAGS) $< -o $@
-
 
621
 
-
 
622
 
-
 
623
# Compile: create assembler files from C source files.
-
 
624
%.s : %.c
-
 
625
	$(CC) -S $(ALL_CFLAGS) $< -o $@
-
 
626
 
-
 
627
 
-
 
628
# Assemble: create object files from assembler source files.
-
 
629
%.o : %.S
-
 
630
	@echo
-
 
631
	@echo $(MSG_ASSEMBLING) $<
-
 
632
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
-
 
633
 
-
 
634
 
-
 
635
 
-
 
636
# Target: clean project.
-
 
637
clean: begin clean_list finished end
-
 
638
 
-
 
639
clean_list :
-
 
640
	@echo
-
 
641
	@echo $(MSG_CLEANING)
-
 
642
	$(REMOVE) $(TARGET).hex
-
 
643
	$(REMOVE) $(TARGET).eep
-
 
644
	$(REMOVE) $(TARGET).obj
-
 
645
	$(REMOVE) $(TARGET).cof
-
 
646
	$(REMOVE) $(TARGET).elf
-
 
647
	$(REMOVE) $(TARGET).map
-
 
648
	$(REMOVE) $(TARGET).obj
-
 
649
	$(REMOVE) $(TARGET).a90
-
 
650
	$(REMOVE) $(TARGET).sym
-
 
651
	$(REMOVE) $(TARGET).lnk
-
 
652
	$(REMOVE) $(TARGET).lss
-
 
653
	$(REMOVE) $(OBJ)
-
 
654
	$(REMOVE) $(LST)
-
 
655
	$(REMOVE) $(SRC:.c=.s)
-
 
656
	$(REMOVE) $(SRC:.c=.d)
-
 
657
	$(REMOVE) .dep/*
-
 
658
 
-
 
659
 
-
 
660
 
-
 
661
# Include the dependency files.
-
 
662
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
-
 
663
 
-
 
664
 
-
 
665
# Listing of phony targets.
-
 
666
.PHONY : all begin finish end sizebefore sizeafter gccversion \
-
 
667
build elf hex eep lss sym coff extcoff \
-
 
668
clean clean_list program
-
 
669