Subversion Repositories HomeAutomation

Rev

Go to most recent revision | Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
553 andfri 1
# Paths: default pathnames if they are not
2
# passed on from parent Makefile.
3
ifndef TARGET
4
TARGET = main
5
endif
6
ifndef LIBDIR
7
LIBDIR = ../../../avr-lib
8
endif
9
ifndef SRCDIR
10
SRCDIR = ../src
11
endif
12
ifndef BIOSDIR
13
BIOSDIR = ../bios
14
endif
15
ifndef CFGDIR
16
CFGDIR = ..
17
endif
18
 
19
include $(BIOSDIR)/bios.inc
20
 
21
# VPATH: setup search path for source files.
22
vpath
23
vpath %.c $(LIBDIR):$(SRCDIR)
24
 
25
# List source files here. (C dependencies are automatically generated.)
26
SOURCES =	main.c\
27
			drivers/timer/timer.c\
28
			drivers/uart/serial.c\
29
			drivers/uart/uart.c\
30
			drivers/mcu/mcu.c\
31
 
32
# Optimization level, can be [0, 1, 2, 3, s]. 
33
# 0 = turn off optimization. s = optimize for size.
34
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
35
OPT = s
36
#OPT = 3
37
 
38
# Debugging format.
39
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
40
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
41
DEBUG = stabs
42
#DEBUG = dwarf-2
43
 
44
# List any extra directories to look for include files here.
45
# Each directory must be separated by a space.
46
EXTRAINCDIRS = $(LIBDIR) $(BIOSDIR)
47
 
48
# Compiler flag to set the C Standard level.
49
# c89   - "ANSI" C
50
# gnu89 - c89 plus GCC extensions
51
# c99   - ISO C99 standard (not yet fully implemented)
52
# gnu99 - c99 plus GCC extensions
53
CSTANDARD = -std=gnu99
54
 
55
# Place -D or -U options here
56
CDEFS =
57
 
58
# Place -I options here
59
CINCS =
60
 
61
 
62
# Compiler flags.
63
#  -g*:          generate debugging information
64
#  -O*:          optimization level
65
#  -f...:        tuning, see GCC manual and avr-libc documentation
66
#  -Wall...:     warning level
67
#  -Wa,...:      tell GCC to pass this to the assembler.
68
#    -adhlns...: create assembler listing
69
CFLAGS = -mmcu=$(MCU) -I.
70
CFLAGS += -g$(DEBUG)
71
CFLAGS += $(CDEFS) $(CINCS)
72
CFLAGS += -O$(OPT)
73
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
74
CFLAGS += -Wall -Wstrict-prototypes
75
CFLAGS += -Wa,-adhlns=$(@:.o=.lst)
76
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
77
CFLAGS += $(CSTANDARD)
78
 
79
 
80
 
81
# Assembler flags.
82
#  -Wa,...:   tell GCC to pass this to the assembler.
83
#  -ahlms:    create listing
84
#  -gstabs:   have the assembler create line number information; note that
85
#             for use in COFF files, additional information about filenames
86
#             and function names needs to be present in the assembler source
87
#             files -- see avr-libc docs [FIXME: not yet described there]
88
##ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
89
ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp
90
ASFLAGS += -Wa,-adhlns=$(@:.o=.lst),-g$(DEBUG)
91
 
92
 
93
#Additional libraries.
94
 
95
# Minimalistic printf version
96
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
97
 
98
# Floating point printf version (requires MATH_LIB = -lm below)
99
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
100
 
101
PRINTF_LIB = 
102
 
103
# Minimalistic scanf version
104
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
105
 
106
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
107
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
108
 
109
SCANF_LIB = 
110
 
111
MATH_LIB = -lm
112
 
113
# External memory options
114
 
115
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
116
# used for variables (.data/.bss) and heap (malloc()).
117
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
118
 
119
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
120
# only used for heap (malloc()).
121
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
122
 
123
EXTMEMOPTS =
124
 
125
BIOSOPTS = -Wl,-L$(BIOSDIR),-Tdata,$(BIOS_RAM_END) -lbios
126
 
127
# Linker flags.
128
#  -Wl,...:     tell GCC to pass this to linker.
129
#    -Map:      create map file
130
#    --cref:    add cross reference to  map file
131
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
132
LDFLAGS += $(EXTMEMOPTS)
133
LDFLAGS += $(BIOSOPTS)
134
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
135
 
136
# ---------------------------------------------------------------------------
137
 
138
# Define programs and commands.
139
SHELL = sh
140
CC = avr-gcc
141
AWK = awk
142
OBJCOPY = avr-objcopy
143
OBJDUMP = avr-objdump
144
SIZE = avr-size
145
NM = avr-nm
146
RM = rm -f
147
CP = cp
148
MKDIR = mkdir
149
 
150
 
151
 
152
# Define Messages
153
# English
154
MSG_ERRORS_NONE = Errors: none
155
MSG_BEGIN = -------- begin --------
156
MSG_END = --------  end  --------
157
MSG_SIZE_BEFORE = Size before: 
158
MSG_SIZE_AFTER = Size after:
159
MSG_COFF = Converting to AVR COFF:
160
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
161
MSG_FLASH = Creating load file for Flash:
162
MSG_EEPROM = Creating load file for EEPROM:
163
MSG_EXTENDED_LISTING = Creating Extended Listing:
164
MSG_SYMBOL_TABLE = Creating Symbol Table:
165
MSG_LINKING = Linking:
166
MSG_COMPILING = Compiling:
167
MSG_ASSEMBLING = Assembling:
168
MSG_DEPEND = Generating dependencies:
169
MSG_CLEANING = Cleaning project:
170
MSG_CREATE = Creating:
171
 
172
# Define all object files.
173
OBJ = $(filter %.o,$(SOURCES:.c=.o) $(SOURCES:.S=.o))
174
 
175
# Define all listing files.
176
LST = $(OBJ:.o=.lst)
177
 
178
# Define all dependency files.
179
DEP = $(OBJ:.o=.dep)
180
 
181
BUILDDIRS = $(sort $(filter-out ./,$(dir $(OBJ))))
182
 
183
# Compiler flags to generate dependency files.
184
### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
185
GENDEPFLAGS = -M -MG -MP -MT "$(@:.d=.o) $@" -MF $@
186
 
187
# Default target.
188
all: sizebefore build sizeafter
189
 
190
build: elf hex eep lss sym
191
 
192
elf: $(TARGET).elf
193
hex: $(TARGET).hex
194
eep: $(TARGET).eep
195
lss: $(TARGET).lss 
196
sym: $(TARGET).sym
197
 
198
# Display size of file.
199
HEXSIZE = $(SIZE) --target=ihex $(TARGET).hex
200
ELFSIZE = $(SIZE) $(TARGET).elf
201
sizebefore:
202
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
203
 
204
sizeafter:
205
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
206
 
207
# Generate config.h from bios.inc and config.inc
208
config.h: $(BIOSDIR)/bios.inc $(CFGDIR)/config.inc
209
	@echo Generating $@
210
	@echo "/* This file is automatically generated. Do not edit. */\n" > $@
211
	@cat $^ | $(AWK) 'BEGIN { FS="="; print "#ifndef CONFIG_H_\n#define CONFIG_H_\n" } /^[^#].*=.*/ { print "#define "$$1,$$2 } END { print "\n#endif /*CONFIG_H_*/" }' >> $@
212
 
213
$(CFGDIR)/config.inc: $(SRCDIR)/config.inc.template
214
	@if [ ! -f $@ ]; then cp $< $@; fi
215
 
216
# Display compiler version information.
217
gccversion : 
218
	@$(CC) --version
219
 
220
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
221
COFFCONVERT=$(OBJCOPY) --debugging \
222
--change-section-address .data-0x800000 \
223
--change-section-address .bss-0x800000 \
224
--change-section-address .noinit-0x800000 \
225
--change-section-address .eeprom-0x810000 
226
 
227
 
228
coff: $(TARGET).elf
229
	@echo $(MSG_COFF) $(TARGET).cof
230
	@$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
231
 
232
extcoff: $(TARGET).elf
233
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
234
	@$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
235
 
236
# Create final output files (.hex, .eep) from ELF output file.
237
%.hex: %.elf
238
	@echo $(MSG_FLASH) $@
239
	@$(OBJCOPY) -j .text -j .data -O ihex $< $@
240
 
241
%.eep: %.elf
242
	@echo $(MSG_EEPROM) $@
243
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
244
	--change-section-lma .eeprom=0 -O ihex $< $@
245
 
246
# Create extended listing file from ELF output file.
247
%.lss: %.elf
248
	@echo $(MSG_EXTENDED_LISTING) $@
249
	@$(OBJDUMP) -h -S $< > $@
250
 
251
# Create a symbol table from ELF output file.
252
%.sym: %.elf
253
	@echo $(MSG_SYMBOL_TABLE) $@
254
	@$(NM) -n $< > $@
255
 
256
# Link: create ELF output file from object files.
257
.SECONDARY : $(TARGET).elf
258
.PRECIOUS : $(OBJ)
259
ifneq (,$(filter atmega88 atmega168, $(MCU)))
260
%.elf: $(OBJ)
261
	@echo $(MSG_LINKING) $@
262
	@echo GCC bug workaround for ATmega88/ATmega168:
263
	@eval $$($(CC) -v $(CFLAGS) -o $@ $^ $(LDFLAGS) 2>&1 | $(AWK) '{ if (gsub("0x800100","$(BIOS_RAM_END)") == 1) print }')
264
else
265
%.elf: $(OBJ)
266
	@echo $(MSG_LINKING) $@
267
	@$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
268
endif
269
 
270
# Compile: create object files from C source files.
271
%.o : %.c
272
	@echo $(MSG_COMPILING) $<
273
	@$(CC) -c $(CFLAGS) $< -o $@ 
274
 
275
# Compile: create assembler files from C source files.
276
%.s : %.c
277
	@$(CC) -S $(CFLAGS) $< -o $@
278
 
279
# Assemble: create object files from assembler source files.
280
%.o : %.S
281
	@echo $(MSG_ASSEMBLING) $<
282
	$(CC) -c $(ASFLAGS) $< -o $@
283
 
284
# Depends: create dependency files from c source files.
285
%.dep : %.c | $(BUILDDIRS)
286
	@echo $(MSG_DEPEND) $<
287
	@$(CC) -c $(CFLAGS) $(GENDEPFLAGS) $<
288
 
289
# Buildtree: create directories for output files.
290
$(BUILDDIRS) :
291
	@echo $(MSG_CREATE) $@
292
	@$(MKDIR) -p $@
293
 
294
# Target: clean project.
295
clean: 
296
	@echo $(MSG_CLEANING)
297
	$(RM) $(TARGET).hex
298
	$(RM) $(TARGET).eep
299
	$(RM) $(TARGET).cof
300
	$(RM) $(TARGET).elf
301
	$(RM) $(TARGET).map
302
	$(RM) $(TARGET).sym
303
	$(RM) $(TARGET).lss
304
	$(RM) $(OBJ)
305
	$(RM) $(LST)
306
	$(RM) config.h
307
 
308
distclean: clean
309
	$(RM) -r $(BUILDDIRS)
310
 
311
# Include the dependency files.
312
-include $(DEP)
313
 
314
# Listing of phony targets.
315
.PHONY : all sizebefore sizeafter build \
316
elf hex eep lss sym coff extcoff clean \
317
distclean gccversion
318