Subversion Repositories HomeAutomation

Rev

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

Rev Author Line No. Line
239 eqlazer 1
# Hey Emacs, this is a -*- makefile -*-
2
#
255 eqlazer 3
# WinAVR makefile written by Eric B. Weddington, Jörg Wunsch, et al.
239 eqlazer 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
255 eqlazer 53
#F_OSC = 11059200
239 eqlazer 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\
73
		$(LIBDIR)sensor/ds18s20/ds18x20.c\
74
		$(LIBDIR)sensor/ds18s20/crc8.c\
255 eqlazer 75
		$(LIBDIR)sensor/ds18s20/delay.c\
76
		$(LIBDIR)sensor/ds18s20/onewire.c\
239 eqlazer 77
		$(LIBDIR)sensor/tc1047/tc1047.c\
78
 
79
# List Assembler source files here.
80
# Make them always end in a capital .S.  Files ending in a lowercase .s
81
# will not be considered source files but generated files (assembler
82
# output from the compiler), and will be deleted upon "make clean"!
83
# Even though the DOS/Win* filesystem matches both .s and .S the same,
84
# it will preserve the spelling of the filenames, and gcc itself does
85
# care about how the name is spelled on its command-line.
86
ASRC = 
87
 
88
 
89
# Optimization level, can be [0, 1, 2, 3, s]. 
90
# 0 = turn off optimization. s = optimize for size.
91
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
92
OPT = s
93
#OPT = 3
94
 
95
# Debugging format.
96
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
97
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
98
#DEBUG = stabs
255 eqlazer 99
DEBUG = dwarf-2
239 eqlazer 100
 
101
# List any extra directories to look for include files here.
102
#     Each directory must be seperated by a space.
255 eqlazer 103
EXTRAINCDIRS = 	$(LIBDIR)/can\
104
				$(LIBDIR)/can/mcp2515\
105
				$(LIBDIR)/mcu\
106
				$(LIBDIR)/../funcdefs\
107
				$(LIBDIR)/sensor/ds18s20 \
108
				$(LIBDIR)/sensor/tc1047 \
239 eqlazer 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
255 eqlazer 131
CFLAGS = 
132
#CFLAGS += -g$(DEBUG)
239 eqlazer 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)
140
CFLAGS += -DF_OSC=$(F_OSC)
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)
152
ASFLAGS += -DF_OSC=$(F_OSC)
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
 
255 eqlazer 163
PRINTF_LIB = $(PRINTF_LIB_MIN)
239 eqlazer 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
 
196
 
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
#
206
AVRDUDE_PROGRAMMER = avrispv2
207
 
208
# com1 = serial port. Use lpt1 to connect to parallel port.
209
AVRDUDE_PORT = /dev/ttyUSB0    # programmer connected to serial device
255 eqlazer 210
AVRDUDE_BAUD = 115200
239 eqlazer 211
 
212
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
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
255 eqlazer 229
 
230
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -b $(AVRDUDE_BAUD)
231
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
239 eqlazer 232
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
233
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
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
254
AVRDUDE = avrdude
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
 
346
 
347
# Program the device.  
348
program: $(TARGET).hex $(TARGET).eep
349
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
350
 
351
#programlock: 
352
#	$(AVRDUDE) $(AVRDUDE_FLAGS) -U lock:w:0x00:m
353
 
354
#programinit: 
355
#	$(AVRDUDE) $(AVRDUDE_FLAGS) -U hfuse:w:0xd9:m -U lfuse:w:0xe4:m
356
 
357
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
358
COFFCONVERT=$(OBJCOPY) --debugging \
359
--change-section-address .data-0x800000 \
360
--change-section-address .bss-0x800000 \
361
--change-section-address .noinit-0x800000 \
362
--change-section-address .eeprom-0x810000 
363
 
364
 
365
coff: $(TARGET).elf
366
	@echo
367
	@echo $(MSG_COFF) $(TARGET).cof
368
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
369
 
370
 
371
extcoff: $(TARGET).elf
372
	@echo
373
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
374
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
375
 
376
 
377
 
378
# Create final output files (.hex, .eep) from ELF output file.
379
%.hex: %.elf
380
	@echo
381
	@echo $(MSG_FLASH) $@
382
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
383
 
384
%.eep: %.elf
385
	@echo
386
	@echo $(MSG_EEPROM) $@
387
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
388
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
389
 
390
# Create extended listing file from ELF output file.
391
%.lss: %.elf
392
	@echo
393
	@echo $(MSG_EXTENDED_LISTING) $@
394
	$(OBJDUMP) -h -S $< > $@
395
 
396
# Create a symbol table from ELF output file.
397
%.sym: %.elf
398
	@echo
399
	@echo $(MSG_SYMBOL_TABLE) $@
400
	$(NM) -n $< > $@
401
 
402
 
403
 
404
# Link: create ELF output file from object files.
405
.SECONDARY : $(TARGET).elf
406
.PRECIOUS : $(OBJ)
407
%.elf: $(OBJ)
408
	@echo
409
	@echo $(MSG_LINKING) $@
410
	$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
411
 
412
 
413
# Compile: create object files from C source files.
414
%.o : %.c
415
	@echo
416
	@echo $(MSG_COMPILING) $<
417
	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
418
 
419
 
420
# Compile: create assembler files from C source files.
421
%.s : %.c
422
	$(CC) -S $(ALL_CFLAGS) $< -o $@
423
 
424
 
425
# Assemble: create object files from assembler source files.
426
%.o : %.S
427
	@echo
428
	@echo $(MSG_ASSEMBLING) $<
429
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
430
 
431
 
432
 
433
# Target: clean project.
434
clean: begin clean_list finished end
435
 
436
clean_list :
437
	@echo
438
	@echo $(MSG_CLEANING)
439
	$(REMOVE) $(TARGET).hex
440
	$(REMOVE) $(TARGET).eep
441
	$(REMOVE) $(TARGET).obj
442
	$(REMOVE) $(TARGET).cof
443
	$(REMOVE) $(TARGET).elf
444
	$(REMOVE) $(TARGET).map
445
	$(REMOVE) $(TARGET).obj
446
	$(REMOVE) $(TARGET).a90
447
	$(REMOVE) $(TARGET).sym
448
	$(REMOVE) $(TARGET).lnk
449
	$(REMOVE) $(TARGET).lss
450
	$(REMOVE) $(OBJ)
451
	$(REMOVE) $(LST)
452
	$(REMOVE) $(SRC:.c=.s)
453
	$(REMOVE) $(SRC:.c=.d)
454
	$(REMOVE) .dep/*
455
 
456
 
457
 
458
# Include the dependency files.
459
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
460
 
461
 
462
# Listing of phony targets.
463
.PHONY : all begin finish end sizebefore sizeafter gccversion \
464
build elf hex eep lss sym coff extcoff \
465
clean clean_list program programlock programinit
466