Subversion Repositories HomeAutomation

Rev

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