Subversion Repositories HomeAutomation

Rev

Rev 325 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 325 Rev 355
1
# Hey Emacs, this is a -*- makefile -*-
1
# Hey Emacs, this is a -*- makefile -*-
2
#
2
#
3
# WinAVR makefile written by Eric B. Weddington, J�rg Wunsch, et al.
3
# WinAVR makefile written by Eric B. Weddington, J�rg Wunsch, et al.
4
# Released to the Public Domain
4
# Released to the Public Domain
5
# Please read the make user manual!
5
# Please read the make user manual!
6
#
6
#
7
# Additional material for this makefile was submitted by:
7
# Additional material for this makefile was submitted by:
8
#  Tim Henigan
8
#  Tim Henigan
9
#  Peter Fleury
9
#  Peter Fleury
10
#  Reiner Patommel
10
#  Reiner Patommel
11
#  Sander Pool
11
#  Sander Pool
12
#  Frederik Rouleau
12
#  Frederik Rouleau
13
#  Markus Pfaff
13
#  Markus Pfaff
14
#
14
#
15
# On command line:
15
# On command line:
16
#
16
#
17
# make all = Make software.
17
# make all = Make software.
18
#
18
#
19
# make clean = Clean out built project files.
19
# make clean = Clean out built project files.
20
#
20
#
21
# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
21
# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
22
#
22
#
23
# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
23
# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
24
#                4.07 or greater).
24
#                4.07 or greater).
25
#
25
#
26
# make program = Download the hex file to the device, using avrdude.  Please
26
# make program = Download the hex file to the device, using avrdude.  Please
27
#                customize the avrdude settings below first!
27
#                customize the avrdude settings below first!
28
#
28
#
29
# make filename.s = Just compile filename.c into the assembler code only
29
# make filename.s = Just compile filename.c into the assembler code only
30
#
30
#
31
# To rebuild project do "make clean" then "make all".
31
# To rebuild project do "make clean" then "make all".
32
#
32
#
33
 
33
 
34
########
34
########
35
# Differences from WinAVR 20040720 sample:
35
# Differences from WinAVR 20040720 sample:
36
# - DEPFLAGS according to Eric Weddingtion's fix (avrfreaks/gcc-forum)
36
# - DEPFLAGS according to Eric Weddingtion's fix (avrfreaks/gcc-forum)
37
# - F_OSC Define in CFLAGS and AFLAGS
37
# - F_OSC Define in CFLAGS and AFLAGS
38
 
38
 
39
 
39
 
40
# MCU name
40
# MCU name
41
#MCU = atmega32
41
#MCU = atmega32
42
MCU = atmega8
42
MCU = atmega8
43
#MCU = atmega16
43
#MCU = atmega16
44
 
44
 
45
 
45
 
46
# Main Oscillator Frequency
46
# Main Oscillator Frequency
47
F_OSC = 8000000
47
F_CPU = 8000000
48
##F_OSC = 1000000
48
##F_OSC = 1000000
49
##F_OSC = 1843200
49
##F_OSC = 1843200
50
##F_OSC = 2000000
50
##F_OSC = 2000000
51
##F_OSC = 3686400
51
##F_OSC = 3686400
52
##F_OSC = 4000000
52
##F_OSC = 4000000
53
##F_OSC = 8000000
53
##F_OSC = 8000000
54
##F_OSC = 11059200
54
##F_OSC = 11059200
55
##F_OSC = 16000000
55
##F_OSC = 16000000
56
 
56
 
57
# Output format. (can be srec, ihex, binary)
57
# Output format. (can be srec, ihex, binary)
58
FORMAT = ihex
58
FORMAT = ihex
59
 
59
 
60
 
60
 
61
# Target file name (without extension).
61
# Target file name (without extension).
62
TARGET = main
62
TARGET = main
63
 
63
 
64
BIOSDIR = ../AVR-Bios
64
BIOSDIR = ../AVR-Bios
65
LIBDIR = ../lib/src
65
LIBDIR = ../lib/src
66
 
66
 
67
 
67
 
68
# List C source files here. (C dependencies are automatically generated.)
68
# List C source files here. (C dependencies are automatically generated.)
69
SRC =	$(TARGET).c\
69
SRC =	$(TARGET).c\
70
		$(LIBDIR)/mcu/serial.c\
70
		$(LIBDIR)/mcu/serial.c\
71
		$(LIBDIR)/mcu/uart.c\
71
		$(LIBDIR)/mcu/uart.c\
72
		$(LIBDIR)/mcu/mcu.c\
72
		$(LIBDIR)/mcu/mcu.c\
73
 
73
 
74
# List Assembler source files here.
74
# List Assembler source files here.
75
# Make them always end in a capital .S.  Files ending in a lowercase .s
75
# Make them always end in a capital .S.  Files ending in a lowercase .s
76
# will not be considered source files but generated files (assembler
76
# will not be considered source files but generated files (assembler
77
# output from the compiler), and will be deleted upon "make clean"!
77
# output from the compiler), and will be deleted upon "make clean"!
78
# Even though the DOS/Win* filesystem matches both .s and .S the same,
78
# Even though the DOS/Win* filesystem matches both .s and .S the same,
79
# it will preserve the spelling of the filenames, and gcc itself does
79
# it will preserve the spelling of the filenames, and gcc itself does
80
# care about how the name is spelled on its command-line.
80
# care about how the name is spelled on its command-line.
81
ASRC = 
81
ASRC = 
82
 
82
 
83
 
83
 
84
# Optimization level, can be [0, 1, 2, 3, s]. 
84
# Optimization level, can be [0, 1, 2, 3, s]. 
85
# 0 = turn off optimization. s = optimize for size.
85
# 0 = turn off optimization. s = optimize for size.
86
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
86
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
87
OPT = s
87
OPT = s
88
#OPT = 3
88
#OPT = 3
89
 
89
 
90
# Debugging format.
90
# Debugging format.
91
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
91
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
92
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
92
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
93
#DEBUG = stabs
93
#DEBUG = stabs
94
DEBUG = dwarf-2
94
DEBUG = dwarf-2
95
 
95
 
96
# List any extra directories to look for include files here.
96
# List any extra directories to look for include files here.
97
#     Each directory must be seperated by a space.
97
#     Each directory must be seperated by a space.
98
EXTRAINCDIRS = $(BIOSDIR) $(LIBDIR)/can $(LIBDIR)/can/mcp2515 $(LIBDIR)/mcu
98
EXTRAINCDIRS = $(BIOSDIR) $(LIBDIR)/can $(LIBDIR)/can/mcp2515 $(LIBDIR)/mcu
99
 
99
 
100
# Compiler flag to set the C Standard level.
100
# Compiler flag to set the C Standard level.
101
# c89   - "ANSI" C
101
# c89   - "ANSI" C
102
# gnu89 - c89 plus GCC extensions
102
# gnu89 - c89 plus GCC extensions
103
# c99   - ISO C99 standard (not yet fully implemented)
103
# c99   - ISO C99 standard (not yet fully implemented)
104
# gnu99 - c99 plus GCC extensions
104
# gnu99 - c99 plus GCC extensions
105
CSTANDARD = -std=gnu99
105
CSTANDARD = -std=gnu99
106
 
106
 
107
# Place -D or -U options here
107
# Place -D or -U options here
108
CDEFS =
108
CDEFS =
109
 
109
 
110
# Place -I options here
110
# Place -I options here
111
CINCS =
111
CINCS =
112
 
112
 
113
 
113
 
114
# Compiler flags.
114
# Compiler flags.
115
#  -g*:          generate debugging information
115
#  -g*:          generate debugging information
116
#  -O*:          optimization level
116
#  -O*:          optimization level
117
#  -f...:        tuning, see GCC manual and avr-libc documentation
117
#  -f...:        tuning, see GCC manual and avr-libc documentation
118
#  -Wall...:     warning level
118
#  -Wall...:     warning level
119
#  -Wa,...:      tell GCC to pass this to the assembler.
119
#  -Wa,...:      tell GCC to pass this to the assembler.
120
#    -adhlns...: create assembler listing
120
#    -adhlns...: create assembler listing
121
CFLAGS = 
121
CFLAGS = 
122
#CFLAGS += -g$(DEBUG)
122
#CFLAGS += -g$(DEBUG)
123
CFLAGS += $(CDEFS) $(CINCS)
123
CFLAGS += $(CDEFS) $(CINCS)
124
CFLAGS += -O$(OPT)
124
CFLAGS += -O$(OPT)
125
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
125
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
126
CFLAGS += -Wall -Wstrict-prototypes
126
CFLAGS += -Wall -Wstrict-prototypes
127
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
127
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
128
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
128
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
129
CFLAGS += $(CSTANDARD)
129
CFLAGS += $(CSTANDARD)
130
CFLAGS += -DF_OSC=$(F_OSC)
130
CFLAGS += -DF_CPU=$(F_CPU)
131
 
131
 
132
 
132
 
133
 
133
 
134
# Assembler flags.
134
# Assembler flags.
135
#  -Wa,...:   tell GCC to pass this to the assembler.
135
#  -Wa,...:   tell GCC to pass this to the assembler.
136
#  -ahlms:    create listing
136
#  -ahlms:    create listing
137
#  -gstabs:   have the assembler create line number information; note that
137
#  -gstabs:   have the assembler create line number information; note that
138
#             for use in COFF files, additional information about filenames
138
#             for use in COFF files, additional information about filenames
139
#             and function names needs to be present in the assembler source
139
#             and function names needs to be present in the assembler source
140
#             files -- see avr-libc docs [FIXME: not yet described there]
140
#             files -- see avr-libc docs [FIXME: not yet described there]
141
##ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
141
##ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
142
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-g$(DEBUG)
142
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-g$(DEBUG)
143
ASFLAGS += -DF_OSC=$(F_OSC)
143
ASFLAGS += -DF_OSC=$(F_OSC)
144
 
144
 
145
 
145
 
146
#Additional libraries.
146
#Additional libraries.
147
 
147
 
148
# Minimalistic printf version
148
# Minimalistic printf version
149
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
149
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
150
 
150
 
151
# Floating point printf version (requires MATH_LIB = -lm below)
151
# Floating point printf version (requires MATH_LIB = -lm below)
152
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
152
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
153
 
153
 
154
PRINTF_LIB = 
154
PRINTF_LIB = 
155
 
155
 
156
# Minimalistic scanf version
156
# Minimalistic scanf version
157
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
157
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
158
 
158
 
159
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
159
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
160
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
160
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
161
 
161
 
162
SCANF_LIB = 
162
SCANF_LIB = 
163
 
163
 
164
MATH_LIB = -lm
164
MATH_LIB = -lm
165
 
165
 
166
# External memory options
166
# External memory options
167
 
167
 
168
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
168
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
169
# used for variables (.data/.bss) and heap (malloc()).
169
# used for variables (.data/.bss) and heap (malloc()).
170
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
170
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
171
 
171
 
172
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
172
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
173
# only used for heap (malloc()).
173
# only used for heap (malloc()).
174
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
174
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
175
 
175
 
176
EXTMEMOPTS =
176
EXTMEMOPTS =
177
 
177
 
178
BIOS_RAM_END   = 0x0080008c
178
BIOS_RAM_END   = 0x0080008c
179
BIOSOPTS = -Wl,-L$(BIOSDIR),--defsym,__bios_ram_end=$(BIOS_RAM_END),-T$(MCU)_app.ld
179
BIOSOPTS = -Wl,-L$(BIOSDIR),--defsym,__bios_ram_end=$(BIOS_RAM_END),-T$(MCU)_app.ld
180
 
180
 
181
# Linker flags.
181
# Linker flags.
182
#  -Wl,...:     tell GCC to pass this to linker.
182
#  -Wl,...:     tell GCC to pass this to linker.
183
#    -Map:      create map file
183
#    -Map:      create map file
184
#    --cref:    add cross reference to  map file
184
#    --cref:    add cross reference to  map file
185
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
185
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
186
LDFLAGS += $(EXTMEMOPTS)
186
LDFLAGS += $(EXTMEMOPTS)
187
LDFLAGS += $(BIOSOPTS)
187
LDFLAGS += $(BIOSOPTS)
188
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
188
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
189
 
189
 
190
 
190
 
191
 
191
 
192
 
192
 
193
# Programming support using avrdude. Settings and variables.
193
# Programming support using avrdude. Settings and variables.
194
 
194
 
195
# Programming hardware: alf avr910 avrisp bascom bsd 
195
# Programming hardware: alf avr910 avrisp bascom bsd 
196
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
196
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
197
#
197
#
198
# Type: avrdude -c ?
198
# Type: avrdude -c ?
199
# to get a full listing.
199
# to get a full listing.
200
#
200
#
201
AVRDUDE_PROGRAMMER = avr910
201
AVRDUDE_PROGRAMMER = avr910
202
 
202
 
203
# com1 = serial port. Use lpt1 to connect to parallel port.
203
# com1 = serial port. Use lpt1 to connect to parallel port.
204
AVRDUDE_PORT = /dev/ttyS0    # programmer connected to serial device
204
AVRDUDE_PORT = /dev/ttyS0    # programmer connected to serial device
205
AVRDUDE_BAUD = 115200
205
AVRDUDE_BAUD = 115200
206
 
206
 
207
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
207
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
208
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
208
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
209
 
209
 
210
 
210
 
211
# Uncomment the following if you want avrdude's erase cycle counter.
211
# Uncomment the following if you want avrdude's erase cycle counter.
212
# Note that this counter needs to be initialized first using -Yn,
212
# Note that this counter needs to be initialized first using -Yn,
213
# see avrdude manual.
213
# see avrdude manual.
214
#AVRDUDE_ERASE_COUNTER = -y
214
#AVRDUDE_ERASE_COUNTER = -y
215
 
215
 
216
# Uncomment the following if you do /not/ wish a verification to be
216
# Uncomment the following if you do /not/ wish a verification to be
217
# performed after programming the device.
217
# performed after programming the device.
218
#AVRDUDE_NO_VERIFY = -V
218
#AVRDUDE_NO_VERIFY = -V
219
 
219
 
220
# Increase verbosity level.  Please use this when submitting bug
220
# Increase verbosity level.  Please use this when submitting bug
221
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
221
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
222
# to submit bug reports.
222
# to submit bug reports.
223
#AVRDUDE_VERBOSE = -v -v
223
#AVRDUDE_VERBOSE = -v -v
224
 
224
 
225
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -b $(AVRDUDE_BAUD)
225
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -b $(AVRDUDE_BAUD)
226
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
226
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
227
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
227
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
228
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
228
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
229
 
229
 
230
 
230
 
231
 
231
 
232
# ---------------------------------------------------------------------------
232
# ---------------------------------------------------------------------------
233
 
233
 
234
# Define directories, if needed.
234
# Define directories, if needed.
235
DIRAVR = c:/progra~1/winavr
235
DIRAVR = c:/progra~1/winavr
236
DIRAVRBIN = $(DIRAVR)/bin
236
DIRAVRBIN = $(DIRAVR)/bin
237
DIRAVRUTILS = $(DIRAVR)/utils/bin
237
DIRAVRUTILS = $(DIRAVR)/utils/bin
238
DIRINC = .
238
DIRINC = .
239
DIRLIB = $(DIRAVR)/avr/lib
239
DIRLIB = $(DIRAVR)/avr/lib
240
 
240
 
241
 
241
 
242
# Define programs and commands.
242
# Define programs and commands.
243
SHELL = sh
243
SHELL = sh
244
CC = avr-gcc
244
CC = avr-gcc
245
OBJCOPY = avr-objcopy
245
OBJCOPY = avr-objcopy
246
OBJDUMP = avr-objdump
246
OBJDUMP = avr-objdump
247
SIZE = avr-size
247
SIZE = avr-size
248
NM = avr-nm
248
NM = avr-nm
249
AVRDUDE = avrdude
249
AVRDUDE = avrdude
250
REMOVE = rm -f
250
REMOVE = rm -f
251
COPY = cp
251
COPY = cp
252
 
252
 
253
 
253
 
254
 
254
 
255
 
255
 
256
# Define Messages
256
# Define Messages
257
# English
257
# English
258
MSG_ERRORS_NONE = Errors: none
258
MSG_ERRORS_NONE = Errors: none
259
MSG_BEGIN = -------- begin --------
259
MSG_BEGIN = -------- begin --------
260
MSG_END = --------  end  --------
260
MSG_END = --------  end  --------
261
MSG_SIZE_BEFORE = Size before: 
261
MSG_SIZE_BEFORE = Size before: 
262
MSG_SIZE_AFTER = Size after:
262
MSG_SIZE_AFTER = Size after:
263
MSG_COFF = Converting to AVR COFF:
263
MSG_COFF = Converting to AVR COFF:
264
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
264
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
265
MSG_FLASH = Creating load file for Flash:
265
MSG_FLASH = Creating load file for Flash:
266
MSG_EEPROM = Creating load file for EEPROM:
266
MSG_EEPROM = Creating load file for EEPROM:
267
MSG_EXTENDED_LISTING = Creating Extended Listing:
267
MSG_EXTENDED_LISTING = Creating Extended Listing:
268
MSG_SYMBOL_TABLE = Creating Symbol Table:
268
MSG_SYMBOL_TABLE = Creating Symbol Table:
269
MSG_LINKING = Linking:
269
MSG_LINKING = Linking:
270
MSG_COMPILING = Compiling:
270
MSG_COMPILING = Compiling:
271
MSG_ASSEMBLING = Assembling:
271
MSG_ASSEMBLING = Assembling:
272
MSG_CLEANING = Cleaning project:
272
MSG_CLEANING = Cleaning project:
273
 
273
 
274
 
274
 
275
 
275
 
276
 
276
 
277
# Define all object files.
277
# Define all object files.
278
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
278
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
279
 
279
 
280
# Define all listing files.
280
# Define all listing files.
281
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
281
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
282
 
282
 
283
 
283
 
284
# Compiler flags to generate dependency files.
284
# Compiler flags to generate dependency files.
285
### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
285
### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
286
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
286
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
287
 
287
 
288
# Combine all necessary flags and optional flags.
288
# Combine all necessary flags and optional flags.
289
# Add target processor to flags.
289
# Add target processor to flags.
290
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
290
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
291
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
291
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
292
 
292
 
293
 
293
 
294
 
294
 
295
 
295
 
296
 
296
 
297
# Default target.
297
# Default target.
298
all: begin gccversion sizebefore build sizeafter finished end
298
all: begin gccversion sizebefore build sizeafter finished end
299
 
299
 
300
build: elf hex eep lss sym
300
build: elf hex eep lss sym
301
 
301
 
302
elf: $(TARGET).elf
302
elf: $(TARGET).elf
303
hex: $(TARGET).hex
303
hex: $(TARGET).hex
304
eep: $(TARGET).eep
304
eep: $(TARGET).eep
305
lss: $(TARGET).lss 
305
lss: $(TARGET).lss 
306
sym: $(TARGET).sym
306
sym: $(TARGET).sym
307
 
307
 
308
 
308
 
309
 
309
 
310
# Eye candy.
310
# Eye candy.
311
# AVR Studio 3.x does not check make's exit code but relies on
311
# AVR Studio 3.x does not check make's exit code but relies on
312
# the following magic strings to be generated by the compile job.
312
# the following magic strings to be generated by the compile job.
313
begin:
313
begin:
314
	@echo
314
	@echo
315
	@echo $(MSG_BEGIN)
315
	@echo $(MSG_BEGIN)
316
 
316
 
317
finished:
317
finished:
318
	@echo $(MSG_ERRORS_NONE)
318
	@echo $(MSG_ERRORS_NONE)
319
 
319
 
320
end:
320
end:
321
	@echo $(MSG_END)
321
	@echo $(MSG_END)
322
	@echo
322
	@echo
323
 
323
 
324
 
324
 
325
# Display size of file.
325
# Display size of file.
326
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
326
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
327
ELFSIZE = $(SIZE) -A $(TARGET).elf
327
ELFSIZE = $(SIZE) -A $(TARGET).elf
328
sizebefore:
328
sizebefore:
329
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
329
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
330
 
330
 
331
sizeafter:
331
sizeafter:
332
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
332
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
333
 
333
 
334
 
334
 
335
 
335
 
336
# Display compiler version information.
336
# Display compiler version information.
337
gccversion : 
337
gccversion : 
338
	@$(CC) --version
338
	@$(CC) --version
339
 
339
 
340
 
340
 
341
 
341
 
342
# Program the device.  
342
# Program the device.  
343
program: $(TARGET).hex $(TARGET).eep
343
program: $(TARGET).hex $(TARGET).eep
344
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
344
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
345
 
345
 
346
#programlock: 
346
#programlock: 
347
#	$(AVRDUDE) $(AVRDUDE_FLAGS) -U lock:w:0x00:m
347
#	$(AVRDUDE) $(AVRDUDE_FLAGS) -U lock:w:0x00:m
348
 
348
 
349
#programinit: 
349
#programinit: 
350
#	$(AVRDUDE) $(AVRDUDE_FLAGS) -U hfuse:w:0xd9:m -U lfuse:w:0xe4:m
350
#	$(AVRDUDE) $(AVRDUDE_FLAGS) -U hfuse:w:0xd9:m -U lfuse:w:0xe4:m
351
 
351
 
352
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
352
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
353
COFFCONVERT=$(OBJCOPY) --debugging \
353
COFFCONVERT=$(OBJCOPY) --debugging \
354
--change-section-address .data-0x800000 \
354
--change-section-address .data-0x800000 \
355
--change-section-address .bss-0x800000 \
355
--change-section-address .bss-0x800000 \
356
--change-section-address .noinit-0x800000 \
356
--change-section-address .noinit-0x800000 \
357
--change-section-address .eeprom-0x810000 
357
--change-section-address .eeprom-0x810000 
358
 
358
 
359
 
359
 
360
coff: $(TARGET).elf
360
coff: $(TARGET).elf
361
	@echo
361
	@echo
362
	@echo $(MSG_COFF) $(TARGET).cof
362
	@echo $(MSG_COFF) $(TARGET).cof
363
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
363
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
364
 
364
 
365
 
365
 
366
extcoff: $(TARGET).elf
366
extcoff: $(TARGET).elf
367
	@echo
367
	@echo
368
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
368
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
369
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
369
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
370
 
370
 
371
 
371
 
372
 
372
 
373
# Create final output files (.hex, .eep) from ELF output file.
373
# Create final output files (.hex, .eep) from ELF output file.
374
%.hex: %.elf
374
%.hex: %.elf
375
	@echo
375
	@echo
376
	@echo $(MSG_FLASH) $@
376
	@echo $(MSG_FLASH) $@
377
	$(OBJCOPY) -j .text -j .data -O $(FORMAT) $< $@
377
	$(OBJCOPY) -j .text -j .data -O $(FORMAT) $< $@
378
 
378
 
379
%.eep: %.elf
379
%.eep: %.elf
380
	@echo
380
	@echo
381
	@echo $(MSG_EEPROM) $@
381
	@echo $(MSG_EEPROM) $@
382
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
382
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
383
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
383
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
384
 
384
 
385
# Create extended listing file from ELF output file.
385
# Create extended listing file from ELF output file.
386
%.lss: %.elf
386
%.lss: %.elf
387
	@echo
387
	@echo
388
	@echo $(MSG_EXTENDED_LISTING) $@
388
	@echo $(MSG_EXTENDED_LISTING) $@
389
	$(OBJDUMP) -h -S $< > $@
389
	$(OBJDUMP) -h -S $< > $@
390
 
390
 
391
# Create a symbol table from ELF output file.
391
# Create a symbol table from ELF output file.
392
%.sym: %.elf
392
%.sym: %.elf
393
	@echo
393
	@echo
394
	@echo $(MSG_SYMBOL_TABLE) $@
394
	@echo $(MSG_SYMBOL_TABLE) $@
395
	$(NM) -n $< > $@
395
	$(NM) -n $< > $@
396
 
396
 
397
 
397
 
398
 
398
 
399
# Link: create ELF output file from object files.
399
# Link: create ELF output file from object files.
400
.SECONDARY : $(TARGET).elf
400
.SECONDARY : $(TARGET).elf
401
.PRECIOUS : $(OBJ)
401
.PRECIOUS : $(OBJ)
402
%.elf: $(OBJ)
402
%.elf: $(OBJ)
403
	@echo
403
	@echo
404
	@echo $(MSG_LINKING) $@
404
	@echo $(MSG_LINKING) $@
405
	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $^
405
	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $^
406
 
406
 
407
# Compile: create object files from C source files.
407
# Compile: create object files from C source files.
408
%.o : %.c
408
%.o : %.c
409
	@echo
409
	@echo
410
	@echo $(MSG_COMPILING) $<
410
	@echo $(MSG_COMPILING) $<
411
	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
411
	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
412
 
412
 
413
 
413
 
414
# Compile: create assembler files from C source files.
414
# Compile: create assembler files from C source files.
415
%.s : %.c
415
%.s : %.c
416
	$(CC) -S $(ALL_CFLAGS) $< -o $@
416
	$(CC) -S $(ALL_CFLAGS) $< -o $@
417
 
417
 
418
 
418
 
419
# Assemble: create object files from assembler source files.
419
# Assemble: create object files from assembler source files.
420
%.o : %.S
420
%.o : %.S
421
	@echo
421
	@echo
422
	@echo $(MSG_ASSEMBLING) $<
422
	@echo $(MSG_ASSEMBLING) $<
423
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
423
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
424
 
424
 
425
 
425
 
426
 
426
 
427
# Target: clean project.
427
# Target: clean project.
428
clean: begin clean_list finished end
428
clean: begin clean_list finished end
429
 
429
 
430
clean_list :
430
clean_list :
431
	@echo
431
	@echo
432
	@echo $(MSG_CLEANING)
432
	@echo $(MSG_CLEANING)
433
	$(REMOVE) $(TARGET).hex
433
	$(REMOVE) $(TARGET).hex
434
	$(REMOVE) $(TARGET).eep
434
	$(REMOVE) $(TARGET).eep
435
	$(REMOVE) $(TARGET).obj
435
	$(REMOVE) $(TARGET).obj
436
	$(REMOVE) $(TARGET).cof
436
	$(REMOVE) $(TARGET).cof
437
	$(REMOVE) $(TARGET).elf
437
	$(REMOVE) $(TARGET).elf
438
	$(REMOVE) $(TARGET).map
438
	$(REMOVE) $(TARGET).map
439
	$(REMOVE) $(TARGET).obj
439
	$(REMOVE) $(TARGET).obj
440
	$(REMOVE) $(TARGET).a90
440
	$(REMOVE) $(TARGET).a90
441
	$(REMOVE) $(TARGET).sym
441
	$(REMOVE) $(TARGET).sym
442
	$(REMOVE) $(TARGET).lnk
442
	$(REMOVE) $(TARGET).lnk
443
	$(REMOVE) $(TARGET).lss
443
	$(REMOVE) $(TARGET).lss
444
	$(REMOVE) $(OBJ)
444
	$(REMOVE) $(OBJ)
445
	$(REMOVE) $(LST)
445
	$(REMOVE) $(LST)
446
	$(REMOVE) $(SRC:.c=.s)
446
	$(REMOVE) $(SRC:.c=.s)
447
	$(REMOVE) $(SRC:.c=.d)
447
	$(REMOVE) $(SRC:.c=.d)
448
	$(REMOVE) .dep/*
448
	$(REMOVE) .dep/*
449
 
449
 
450
 
450
 
451
 
451
 
452
# Include the dependency files.
452
# Include the dependency files.
453
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
453
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
454
 
454
 
455
 
455
 
456
# Listing of phony targets.
456
# Listing of phony targets.
457
.PHONY : all begin finish end sizebefore sizeafter gccversion \
457
.PHONY : all begin finish end sizebefore sizeafter gccversion \
458
build elf hex eep lss sym coff extcoff \
458
build elf hex eep lss sym coff extcoff \
459
clean clean_list program programlock programinit
459
clean clean_list program programlock programinit
460
 
460