Subversion Repositories HomeAutomation

Rev

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

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