Subversion Repositories HomeAutomation

Rev

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

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