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
 
215
# Eye candy.
216
# AVR Studio 3.x does not check make's exit code but relies on
217
# the following magic strings to be generated by the compile job.
218
begin:
219
	@echo
220
	@echo $(MSG_BEGIN)
221
 
222
finished:
223
	@echo $(MSG_ERRORS_NONE)
224
 
225
end:
226
	@echo $(MSG_END)
227
	@echo
228
 
229
 
230
# Display size of file.
231
HEXSIZE = $(SIZE) --target=ihex $(TARGET).hex
232
ELFSIZE = $(SIZE) $(TARGET).elf
233
sizebefore:
234
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
235
 
236
sizeafter:
237
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
238
 
239
 
240
# Generate config.h from bios.inc and config.inc
241
config.h: bios.inc config.inc
242
	@echo Generating $@
243
	@echo "/* This file is automatically generated. Do not edit. */\n" > $@
244
	@cat $^ | awk 'BEGIN { FS="="; print "#ifndef CONFIG_H_\n#define CONFIG_H_\n" } /^[^#].*=.*/ { print "#define "$$1,$$2 } END { print "\n#endif /*CONFIG_H_*/" }' >> $@
245
 
246
# Display compiler version information.
247
gccversion : 
248
	@$(CC) --version
249
 
250
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
251
COFFCONVERT=$(OBJCOPY) --debugging \
252
--change-section-address .data-0x800000 \
253
--change-section-address .bss-0x800000 \
254
--change-section-address .noinit-0x800000 \
255
--change-section-address .eeprom-0x810000 
256
 
257
 
258
coff: $(TARGET).elf
259
	@echo
260
	@echo $(MSG_COFF) $(TARGET).cof
261
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
262
 
263
 
264
extcoff: $(TARGET).elf
265
	@echo
266
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
267
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
268
 
269
 
270
 
271
# Create final output files (.hex, .eep) from ELF output file.
317 eqlazer 272
%.hex: %.elf
388 eqlazer 273
	@echo
274
	@echo $(MSG_FLASH) $@
317 eqlazer 275
	$(OBJCOPY) -j .text -j .data -O ihex $< $@
276
 
388 eqlazer 277
%.eep: %.elf
278
	@echo
279
	@echo $(MSG_EEPROM) $@
280
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
281
	--change-section-lma .eeprom=0 -O ihex $< $@
317 eqlazer 282
 
388 eqlazer 283
# Create extended listing file from ELF output file.
284
%.lss: %.elf
285
	@echo
286
	@echo $(MSG_EXTENDED_LISTING) $@
287
	$(OBJDUMP) -h -S $< > $@
317 eqlazer 288
 
388 eqlazer 289
# Create a symbol table from ELF output file.
290
%.sym: %.elf
291
	@echo
292
	@echo $(MSG_SYMBOL_TABLE) $@
293
	$(NM) -n $< > $@
317 eqlazer 294
 
295
 
296
 
388 eqlazer 297
# Link: create ELF output file from object files.
298
.SECONDARY : $(TARGET).elf
299
.PRECIOUS : $(OBJ)
300
ifneq (,$(filter atmega88 atmega168, $(MCU)))
301
%.elf: $(OBJ)
302
	@echo
303
	@echo $(MSG_LINKING) $@
304
	@echo GCC bug workaround for ATmega88/ATmega168:
305
	eval $$($(CC) -v $(CFLAGS) -o $@ $^ $(LDFLAGS) 2>&1 | awk '{ if (gsub("0x800100","$(BIOS_RAM_END)") == 1) print }')
306
else
307
%.elf: $(OBJ)
308
	@echo
309
	@echo $(MSG_LINKING) $@
310
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
311
endif
317 eqlazer 312
 
388 eqlazer 313
# Compile: create object files from C source files.
314
%.o : %.c
315
	@echo
316
	@echo $(MSG_COMPILING) $<
317
	$(CC) -c $(CFLAGS) $< -o $@ 
317 eqlazer 318
 
319
 
388 eqlazer 320
# Compile: create assembler files from C source files.
321
%.s : %.c
322
	$(CC) -S $(CFLAGS) $< -o $@
317 eqlazer 323
 
324
 
388 eqlazer 325
# Assemble: create object files from assembler source files.
326
%.o : %.S
327
	@echo
328
	@echo $(MSG_ASSEMBLING) $<
329
	$(CC) -c $(ASFLAGS) $< -o $@
317 eqlazer 330
 
388 eqlazer 331
# Depends: create dependency files from c source files.
332
%.d : %.c
333
	@echo $(MSG_DEPEND) $<
334
	@$(CC) -c $(CFLAGS) $(GENDEPFLAGS) $<
317 eqlazer 335
 
388 eqlazer 336
# Target: clean project.
337
clean: begin clean_list finished end
317 eqlazer 338
 
388 eqlazer 339
clean_list :
340
	@echo
341
	@echo $(MSG_CLEANING)
342
	$(REMOVE) $(TARGET).hex
343
	$(REMOVE) $(TARGET).eep
344
	$(REMOVE) $(TARGET).obj
345
	$(REMOVE) $(TARGET).cof
346
	$(REMOVE) $(TARGET).elf
347
	$(REMOVE) $(TARGET).map
348
	$(REMOVE) $(TARGET).obj
349
	$(REMOVE) $(TARGET).a90
350
	$(REMOVE) $(TARGET).sym
351
	$(REMOVE) $(TARGET).lnk
352
	$(REMOVE) $(TARGET).lss
353
	$(REMOVE) $(OBJ)
354
	$(REMOVE) $(LST)
355
	$(REMOVE) $(CSRC:.c=.s)
356
	$(REMOVE) $(CSRC:.c=.d)
357
	$(REMOVE) -r .dep
358
	$(REMOVE) config.h
317 eqlazer 359
 
360
 
361
 
388 eqlazer 362
# Include the dependency files.
363
-include $(CSRC:%.c=%.d)
317 eqlazer 364
 
388 eqlazer 365
 
366
# Listing of phony targets.
367
.PHONY : all begin finish end sizebefore sizeafter gccversion \
368
build elf hex eep lss sym config coff extcoff \
369
clean clean_list program programlock programinit
370