Subversion Repositories HomeAutomation

Rev

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

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