Project

General

Profile

Statistics
| Revision:

root / branches / encoders / code / projects / odometry / Makefile @ 1390

History | View | Annotate | Download (13.8 KB)

1
########Update This Section########
2
#
3
#
4

    
5
# Relative path to the root directory (containing lib directory)
6
ifndef COLONYROOT
7
COLONYROOT = ../../..
8
endif
9

    
10
# Target file name (without extension).
11
TARGET = main
12

    
13
# Uncomment this to use the wireless library
14
# USE_WIRELESS = 1
15

    
16
# com1 = serial port. Use lpt1 to connect to parallel port.
17
AVRDUDE_PORT = $(shell if uname -s |grep -i w32 >/dev/null; then echo 'COM4:'; else echo '/dev/ttyUSB0'; fi)
18
#
19
###################################
20

    
21
# Hey Emacs, this is a -*- makefile -*-
22
#----------------------------------------------------------------------------
23
# WinAVR Makefile Template written by Eric B. Weddington, J?rg Wunsch, et al.
24
#
25
# Released to the Public Domain
26
#
27
# Additional material for this makefile was written by:
28
# Peter Fleury
29
# Tim Henigan
30
# Colin O'Flynn
31
# Reiner Patommel
32
# Markus Pfaff
33
# Sander Pool
34
# Frederik Rouleau
35
#
36
#----------------------------------------------------------------------------
37
# On command line:
38
#
39
# make all = Make software.
40
#
41
# make clean = Clean out built project files.
42
#
43
# make coff = Convert ELF to AVR COFF.
44
#
45
# make extcoff = Convert ELF to AVR Extended COFF.
46
#
47
# make program = Download the hex file to the device, using avrdude.
48
#                Please customize the avrdude settings below first!
49
#
50
# make debug = Start either simulavr or avarice as specified for debugging, 
51
#              with avr-gdb or avr-insight as the front end for debugging.
52
#
53
# make filename.s = Just compile filename.c into the assembler code only.
54
#
55
# make filename.i = Create a preprocessed source file for use in submitting
56
#                   bug reports to the GCC project.
57
#
58
# To rebuild project do "make clean" then "make all".
59
#----------------------------------------------------------------------------
60

    
61
#if you want your code to work on the Firefly++ and not Firefly+
62
#then add the -DFFPP line to CDEFS
63
CDEFS = 
64
#-DFFPP
65

    
66
# MCU name
67
MCU = atmega128
68

    
69
# Processor frequency.
70
#     This will define a symbol, F_CPU, in all source code files equal to the 
71
#     processor frequency. You can then use this symbol in your source code to 
72
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
73
#     automatically to create a 32-bit value in your source code.
74
F_CPU = 8000000
75

    
76
# Output format. (can be srec, ihex, binary)
77
FORMAT = ihex
78

    
79
# List C source files here. (C dependencies are automatically generated.)
80
SRC = $(wildcard *.c)
81

    
82
# List Assembler source files here.
83
#     Make them always end in a capital .S.  Files ending in a lowercase .s
84
#     will not be considered source files but generated files (assembler
85
#     output from the compiler), and will be deleted upon "make clean"!
86
#     Even though the DOS/Win* filesystem matches both .s and .S the same,
87
#     it will preserve the spelling of the filenames, and gcc itself does
88
#     care about how the name is spelled on its command-line.
89
ASRC = 
90

    
91
# Optimization level, can be [0, 1, 2, 3, s]. 
92
#     0 = turn off optimization. s = optimize for size.
93
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
94
OPT = s
95

    
96
# Debugging format.
97
#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
98
#     AVR Studio 4.10 requires dwarf-2.
99
#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
100
DEBUG =
101

    
102
# Compiler flag to set the C Standard level.
103
#     c89   = "ANSI" C
104
#     gnu89 = c89 plus GCC extensions
105
#     c99   = ISO C99 standard (not yet fully implemented)
106
#     gnu99 = c99 plus GCC extensions
107
CSTANDARD = -std=gnu99
108

    
109
# Place -D or -U options here
110
CDEFS += -DF_CPU=$(F_CPU)UL 
111
CDEFS += -DFFP
112
# for wireless library
113
ifdef USE_WIRELESS
114
	CDEFS += -DROBOT
115
endif
116

    
117
# Place -I, -L options here
118
CINCS = -I$(COLONYROOT)/code/lib/include/libdragonfly
119
CINCS += -L$(COLONYROOT)/code/lib/bin
120
ifdef USE_WIRELESS
121
	CINCS += -I$(COLONYROOT)/code/lib/include/libwireless
122
endif
123
#---------------- Compiler Options ----------------
124
#  -g*:          generate debugging information
125
#  -O*:          optimization level
126
#  -f...:        tuning, see GCC manual and avr-libc documentation
127
#  -Wall...:     warning level
128
#  -Wa,...:      tell GCC to pass this to the assembler.
129
#    -adhlns...: create assembler listing
130
CFLAGS =
131
# CFLAGS = -g$(DEBUG)
132
CFLAGS += $(CDEFS) $(CINCS)
133
CFLAGS += -O$(OPT)
134
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
135
CFLAGS += -Wall -Wstrict-prototypes
136
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
137
CFLAGS += $(CSTANDARD)
138

    
139
#---------------- Assembler Options ----------------
140
#  -Wa,...:   tell GCC to pass this to the assembler.
141
#  -ahlms:    create listing
142
#  -gstabs:   have the assembler create line number information; note that
143
#             for use in COFF files, additional information about filenames
144
#             and function names needs to be present in the assembler source
145
#             files -- see avr-libc docs [FIXME: not yet described there]
146
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
147

    
148

    
149
#---------------- Library Options ----------------
150
# Minimalistic printf version
151
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
152

    
153
# Floating point printf version (requires MATH_LIB = -lm below)
154
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
155

    
156
# If this is left blank, then it will use the Standard printf version.
157
PRINTF_LIB = 
158
#PRINTF_LIB = $(PRINTF_LIB_MIN)
159
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
160

    
161

    
162
# Minimalistic scanf version
163
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
164

    
165
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
166
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
167

    
168
# If this is left blank, then it will use the Standard scanf version.
169
SCANF_LIB = 
170
#SCANF_LIB = $(SCANF_LIB_MIN)
171
#SCANF_LIB = $(SCANF_LIB_FLOAT)
172

    
173
MATH_LIB = -lm
174

    
175
#---------------- External Memory Options ----------------
176

    
177
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
178
# used for variables (.data/.bss) and heap (malloc()).
179
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
180

    
181
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
182
# only used for heap (malloc()).
183
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
184

    
185
EXTMEMOPTS =
186

    
187
#---------------- Linker Options ----------------
188
#  -Wl,...:     tell GCC to pass this to linker.
189
#    -Map:      create map file
190
#    --cref:    add cross reference to  map file
191
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
192
LDFLAGS += $(EXTMEMOPTS)
193
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
194
ifdef USE_WIRELESS
195
	LDFLAGS += -lwireless
196
endif
197
LDFLAGS += -ldragonfly
198

    
199

    
200
#---------------- Programming Options (avrdude) ----------------
201

    
202
# Programming hardware: alf avr910 avrisp bascom bsd 
203
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
204
#
205
# Type: avrdude -c ?
206
# to get a full listing.
207
#
208
AVRDUDE_PROGRAMMER = avrisp
209

    
210
# programmer connected to serial device
211

    
212
AVRDUDE_WRITE_FLASH = -b 57600 -U flash:w:$(TARGET).hex
213
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
214

    
215

    
216
# Uncomment the following if you want avrdude's erase cycle counter.
217
# Note that this counter needs to be initialized first using -Yn,
218
# see avrdude manual.
219
#AVRDUDE_ERASE_COUNTER = -y
220

    
221
# Uncomment the following if you do /not/ wish a verification to be
222
# performed after programming the device.
223
#AVRDUDE_NO_VERIFY = -V
224

    
225
# Increase verbosity level.  Please use this when submitting bug
226
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
227
# to submit bug reports.
228
#AVRDUDE_VERBOSE = -v -v
229

    
230
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
231
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
232
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
233
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
234

    
235
#don't check for device signature
236
AVRDUDE_FLAGS += -F
237

    
238

    
239

    
240
#---------------- Debugging Options ----------------
241

    
242
# For simulavr only - target MCU frequency.
243
DEBUG_MFREQ = $(F_CPU)
244

    
245
# Set the DEBUG_UI to either gdb or insight.
246
# DEBUG_UI = gdb
247
DEBUG_UI = insight
248

    
249
# Set the debugging back-end to either avarice, simulavr.
250
DEBUG_BACKEND = avarice
251
#DEBUG_BACKEND = simulavr
252

    
253
# GDB Init Filename.
254
GDBINIT_FILE = __avr_gdbinit
255

    
256
# When using avarice settings for the JTAG
257
JTAG_DEV = /dev/com1
258

    
259
# Debugging port used to communicate between GDB / avarice / simulavr.
260
DEBUG_PORT = 4242
261

    
262
# Debugging host used to communicate between GDB / avarice / simulavr, normally
263
#     just set to localhost unless doing some sort of crazy debugging when 
264
#     avarice is running on a different computer.
265
DEBUG_HOST = localhost
266

    
267

    
268

    
269
#============================================================================
270

    
271

    
272
# Define programs and commands.
273
SHELL = sh
274
CC = avr-gcc
275
OBJCOPY = avr-objcopy
276
OBJDUMP = avr-objdump
277
SIZE = avr-size
278
NM = avr-nm
279
AVRDUDE = avrdude
280
REMOVE = rm -f
281
REMOVEDIR = rm -rf
282
COPY = cp
283
WINSHELL = cmd
284

    
285

    
286
# Define Messages
287
# English
288
MSG_ERRORS_NONE = Errors: none
289
MSG_BEGIN = -------- begin --------
290
MSG_END = --------  end  --------
291
MSG_SIZE_BEFORE = Size before: 
292
MSG_SIZE_AFTER = Size after:
293
MSG_COFF = Converting to AVR COFF:
294
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
295
MSG_FLASH = Creating load file for Flash:
296
MSG_EEPROM = Creating load file for EEPROM:
297
MSG_EXTENDED_LISTING = Creating Extended Listing:
298
MSG_SYMBOL_TABLE = Creating Symbol Table:
299
MSG_LINKING = Linking:
300
MSG_COMPILING = Compiling:
301
MSG_ASSEMBLING = Assembling:
302
MSG_CLEANING = Cleaning project:
303

    
304

    
305

    
306

    
307
# Define all object files.
308
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
309

    
310
# Define all listing files.
311
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) 
312

    
313

    
314
# Compiler flags to generate dependency files.
315
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
316

    
317

    
318
# Combine all necessary flags and optional flags.
319
# Add target processor to flags.
320
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
321
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
322

    
323

    
324

    
325

    
326

    
327
# Default target.
328
all: begin gccversion sizebefore build sizeafter end
329

    
330
build: elf hex eep lss sym
331

    
332
elf: $(TARGET).elf
333
hex: $(TARGET).hex
334
eep: $(TARGET).eep
335
lss: $(TARGET).lss 
336
sym: $(TARGET).sym
337

    
338

    
339

    
340
# Eye candy.
341
# AVR Studio 3.x does not check make's exit code but relies on
342
# the following magic strings to be generated by the compile job.
343
begin:
344
	@echo
345
	@echo $(MSG_BEGIN)
346

    
347
end:
348
	@echo $(MSG_END)
349
	@echo
350

    
351

    
352
# Display size of file.
353
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
354
ELFSIZE = $(SIZE) -A $(TARGET).elf
355
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
356

    
357
sizebefore:
358
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
359
	$(AVRMEM) 2>/dev/null; echo; fi
360

    
361
sizeafter:
362
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
363
	$(AVRMEM) 2>/dev/null; echo; fi
364

    
365

    
366

    
367
# Display compiler version information.
368
gccversion : 
369
	@$(CC) --version
370

    
371

    
372

    
373
# Program the device.  
374
program: $(TARGET).hex $(TARGET).eep
375
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
376

    
377

    
378
# Generate avr-gdb config/init file which does the following:
379
#     define the reset signal, load the target file, connect to target, and set 
380
#     a breakpoint at main().
381
gdb-config: 
382
	@$(REMOVE) $(GDBINIT_FILE)
383
	@echo define reset >> $(GDBINIT_FILE)
384
	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
385
	@echo end >> $(GDBINIT_FILE)
386
	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
387
	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
388
ifeq ($(DEBUG_BACKEND),simulavr)
389
	@echo load  >> $(GDBINIT_FILE)
390
endif	
391
	@echo break main >> $(GDBINIT_FILE)
392
	
393
debug: gdb-config $(TARGET).elf
394
ifeq ($(DEBUG_BACKEND), avarice)
395
	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
396
	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
397
	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
398
	@$(WINSHELL) /c pause
399
	
400
else
401
	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
402
	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
403
endif
404
	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
405
	
406

    
407

    
408

    
409
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
410
COFFCONVERT=$(OBJCOPY) --debugging \
411
--change-section-address .data-0x800000 \
412
--change-section-address .bss-0x800000 \
413
--change-section-address .noinit-0x800000 \
414
--change-section-address .eeprom-0x810000 
415

    
416

    
417
coff: $(TARGET).elf
418
	@echo
419
	@echo $(MSG_COFF) $(TARGET).cof
420
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
421

    
422

    
423
extcoff: $(TARGET).elf
424
	@echo
425
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
426
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
427

    
428

    
429

    
430
# Create final output files (.hex, .eep) from ELF output file.
431
%.hex: %.elf
432
	@echo
433
	@echo $(MSG_FLASH) $@
434
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
435

    
436
%.eep: %.elf
437
	@echo
438
	@echo $(MSG_EEPROM) $@
439
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
440
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
441

    
442
# Create extended listing file from ELF output file.
443
%.lss: %.elf
444
	@echo
445
	@echo $(MSG_EXTENDED_LISTING) $@
446
	$(OBJDUMP) -h -S $< > $@
447

    
448
# Create a symbol table from ELF output file.
449
%.sym: %.elf
450
	@echo
451
	@echo $(MSG_SYMBOL_TABLE) $@
452
	$(NM) -n $< > $@
453

    
454

    
455

    
456
# Link: create ELF output file from object files.
457
.SECONDARY : $(TARGET).elf
458
.PRECIOUS : $(OBJ)
459
%.elf: $(OBJ)
460
	@echo
461
	@echo $(MSG_LINKING) $@
462
	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
463

    
464

    
465
# Compile: create object files from C source files.
466
%.o : %.c
467
	@echo
468
	@echo $(MSG_COMPILING) $<
469
	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
470

    
471

    
472
# Compile: create assembler files from C source files.
473
%.s : %.c
474
	$(CC) -S $(ALL_CFLAGS) $< -o $@
475

    
476

    
477
# Assemble: create object files from assembler source files.
478
%.o : %.S
479
	@echo
480
	@echo $(MSG_ASSEMBLING) $<
481
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
482

    
483
# Create preprocessed source for use in sending a bug report.
484
%.i : %.c
485
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ 
486

    
487

    
488
# Target: clean project.
489
clean: begin clean_list end
490

    
491
clean_list :
492
	@echo
493
	@echo $(MSG_CLEANING)
494
	$(REMOVE) $(TARGET).hex
495
	$(REMOVE) $(TARGET).eep
496
	$(REMOVE) $(TARGET).cof
497
	$(REMOVE) $(TARGET).elf
498
	$(REMOVE) $(TARGET).map
499
	$(REMOVE) $(TARGET).sym
500
	$(REMOVE) $(TARGET).lss
501
	$(REMOVE) $(OBJ)
502
	$(REMOVE) $(LST)
503
	$(REMOVE) $(SRC:.c=.s)
504
	$(REMOVE) $(SRC:.c=.d)
505
	$(REMOVEDIR) .dep
506

    
507

    
508

    
509
# Include the dependency files.
510
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
511

    
512

    
513
# Listing of phony targets.
514
.PHONY : all begin finish end sizebefore sizeafter gccversion \
515
build elf hex eep lss sym coff extcoff \
516
clean clean_list program debug gdb-config
517