Subversion Repositories HomeAutomation

Rev

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

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