Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

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