Subversion Repositories HomeAutomation

Rev

Rev 1694 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

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