Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (14.4 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 = robot_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
robot: all
20
	TARGET = robot_main
21
	
22
#
23
#
24
###################################
25

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

    
66
#if you want your code to work on the Firefly++ and not Firefly+
67
#then add the -DFFPP line to CDEFS
68
CDEFS = 
69
#-DFFPP
70

    
71
# MCU name
72
MCU = atmega128
73

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

    
81
# Output format. (can be srec, ihex, binary)
82
FORMAT = ihex
83

    
84
# List C source files here. (C dependencies are automatically generated.)
85
SRC = $(wildcard *.c)
86

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

    
96
# Optimization level, can be [0, 1, 2, 3, s]. 
97
#     0 = turn off optimization. s = optimize for size.
98
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
99
OPT = s
100

    
101
# Debugging format.
102
#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
103
#     AVR Studio 4.10 requires dwarf-2.
104
#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
105
DEBUG =
106

    
107
# Compiler flag to set the C Standard level.
108
#     c89   = "ANSI" C
109
#     gnu89 = c89 plus GCC extensions
110
#     c99   = ISO C99 standard (not yet fully implemented)
111
#     gnu99 = c99 plus GCC extensions
112
CSTANDARD = -std=gnu99
113

    
114
# Place -D or -U options here
115
CDEFS += -DF_CPU=$(F_CPU)UL 
116
CDEFS += -DFFP
117
# for wireless library
118
ifdef USE_WIRELESS
119
	CDEFS += -DROBOT
120
endif
121

    
122
# Place -I, -L options here
123
CINCS = -I$(COLONYROOT)/code/lib/include/libdragonfly 
124
CINCS += -L$(COLONYROOT)/code/lib/bin
125
ifdef USE_WIRELESS
126
	CINCS += -I$(COLONYROOT)/code/lib/include/libwireless
127
endif
128

    
129
#---------------- Compiler Options ----------------
130
#  -g*:          generate debugging information
131
#  -O*:          optimization level
132
#  -f...:        tuning, see GCC manual and avr-libc documentation
133
#  -Wall...:     warning level
134
#  -Wa,...:      tell GCC to pass this to the assembler.
135
#    -adhlns...: create assembler listing
136
CFLAGS =
137
# CFLAGS = -g$(DEBUG)
138
CFLAGS += $(CDEFS) $(CINCS)
139
CFLAGS += -O$(OPT)
140
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
141
CFLAGS += -Wall -Wstrict-prototypes
142
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
143
CFLAGS += $(CSTANDARD)
144

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

    
154

    
155
#---------------- Library Options ----------------
156
# Minimalistic printf version
157
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
158

    
159
# Floating point printf version (requires MATH_LIB = -lm below)
160
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
161

    
162
# If this is left blank, then it will use the Standard printf version.
163
PRINTF_LIB = 
164
#PRINTF_LIB = $(PRINTF_LIB_MIN)
165
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
166

    
167

    
168
# Minimalistic scanf version
169
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
170

    
171
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
172
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
173

    
174
# If this is left blank, then it will use the Standard scanf version.
175
SCANF_LIB = 
176
#SCANF_LIB = $(SCANF_LIB_MIN)
177
#SCANF_LIB = $(SCANF_LIB_FLOAT)
178

    
179
MATH_LIB = -lm
180

    
181
#---------------- External Memory Options ----------------
182

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

    
187
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
188
# only used for heap (malloc()).
189
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
190

    
191
EXTMEMOPTS =
192

    
193
#---------------- Linker Options ----------------
194
#  -Wl,...:     tell GCC to pass this to linker.
195
#    -Map:      create map file
196
#    --cref:    add cross reference to  map file
197
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
198
LDFLAGS += $(EXTMEMOPTS)
199
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
200
ifdef USE_WIRELESS
201
	LDFLAGS += -lwireless
202
endif
203
LDFLAGS += -ldragonfly
204

    
205

    
206

    
207
#---------------- Programming Options (avrdude) ----------------
208

    
209
# Programming hardware: alf avr910 avrisp bascom bsd 
210
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
211
#
212
# Type: avrdude -c ?
213
# to get a full listing.
214
#
215
AVRDUDE_PROGRAMMER = avrisp
216

    
217
# programmer connected to serial device
218

    
219
AVRDUDE_WRITE_FLASH = -b 57600 -U flash:w:$(TARGET).hex
220
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
221

    
222

    
223
# Uncomment the following if you want avrdude's erase cycle counter.
224
# Note that this counter needs to be initialized first using -Yn,
225
# see avrdude manual.
226
#AVRDUDE_ERASE_COUNTER = -y
227

    
228
# Uncomment the following if you do /not/ wish a verification to be
229
# performed after programming the device.
230
#AVRDUDE_NO_VERIFY = -V
231

    
232
# Increase verbosity level.  Please use this when submitting bug
233
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
234
# to submit bug reports.
235
#AVRDUDE_VERBOSE = -v -v
236

    
237
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
238
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
239
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
240
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
241

    
242
#don't check for device signature
243
AVRDUDE_FLAGS += -F
244

    
245

    
246

    
247
#---------------- Debugging Options ----------------
248

    
249
# For simulavr only - target MCU frequency.
250
DEBUG_MFREQ = $(F_CPU)
251

    
252
# Set the DEBUG_UI to either gdb or insight.
253
# DEBUG_UI = gdb
254
DEBUG_UI = insight
255

    
256
# Set the debugging back-end to either avarice, simulavr.
257
DEBUG_BACKEND = avarice
258
#DEBUG_BACKEND = simulavr
259

    
260
# GDB Init Filename.
261
GDBINIT_FILE = __avr_gdbinit
262

    
263
# When using avarice settings for the JTAG
264
JTAG_DEV = /dev/com1
265

    
266
# Debugging port used to communicate between GDB / avarice / simulavr.
267
DEBUG_PORT = 4242
268

    
269
# Debugging host used to communicate between GDB / avarice / simulavr, normally
270
#     just set to localhost unless doing some sort of crazy debugging when 
271
#     avarice is running on a different computer.
272
DEBUG_HOST = localhost
273

    
274

    
275

    
276
#============================================================================
277

    
278

    
279
# Define programs and commands.
280
SHELL = sh
281
CC = avr-gcc
282
OBJCOPY = avr-objcopy
283
OBJDUMP = avr-objdump
284
SIZE = avr-size
285
NM = avr-nm
286
AVRDUDE = avrdude
287
REMOVE = rm -f
288
REMOVEDIR = rm -rf
289
COPY = cp
290
WINSHELL = cmd
291

    
292

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

    
311

    
312

    
313

    
314
# Define all object files.
315
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
316

    
317
# Define all listing files.
318
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) 
319

    
320

    
321
# Compiler flags to generate dependency files.
322
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
323

    
324

    
325
# Combine all necessary flags and optional flags.
326
# Add target processor to flags.
327
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
328
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
329

    
330

    
331

    
332

    
333

    
334
# Default target.
335
all: begin gccversion sizebefore build sizeafter end
336

    
337
build: elf hex eep lss sym
338

    
339
elf: $(TARGET).elf
340
hex: $(TARGET).hex
341
eep: $(TARGET).eep
342
lss: $(TARGET).lss 
343
sym: $(TARGET).sym
344

    
345

    
346

    
347
# Eye candy.
348
# AVR Studio 3.x does not check make's exit code but relies on
349
# the following magic strings to be generated by the compile job.
350
begin:
351
	@echo
352
	@echo $(MSG_BEGIN)
353

    
354
end:
355
	@echo $(MSG_END)
356
	@echo
357

    
358

    
359
# Display size of file.
360
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
361
ELFSIZE = $(SIZE) -A $(TARGET).elf
362
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
363

    
364
sizebefore:
365
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
366
	$(AVRMEM) 2>/dev/null; echo; fi
367

    
368
sizeafter:
369
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
370
	$(AVRMEM) 2>/dev/null; echo; fi
371

    
372

    
373

    
374
# Display compiler version information.
375
gccversion : 
376
	@$(CC) --version
377

    
378

    
379

    
380
# Program the device.  
381
program: $(TARGET).hex $(TARGET).eep
382
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
383

    
384

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

    
414

    
415

    
416
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
417
COFFCONVERT=$(OBJCOPY) --debugging \
418
--change-section-address .data-0x800000 \
419
--change-section-address .bss-0x800000 \
420
--change-section-address .noinit-0x800000 \
421
--change-section-address .eeprom-0x810000 
422

    
423

    
424
coff: $(TARGET).elf
425
	@echo
426
	@echo $(MSG_COFF) $(TARGET).cof
427
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
428

    
429

    
430
extcoff: $(TARGET).elf
431
	@echo
432
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
433
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
434

    
435

    
436

    
437
# Create final output files (.hex, .eep) from ELF output file.
438
%.hex: %.elf
439
	@echo
440
	@echo $(MSG_FLASH) $@
441
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
442

    
443
%.eep: %.elf
444
	@echo
445
	@echo $(MSG_EEPROM) $@
446
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
447
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
448

    
449
# Create extended listing file from ELF output file.
450
%.lss: %.elf
451
	@echo
452
	@echo $(MSG_EXTENDED_LISTING) $@
453
	$(OBJDUMP) -h -S $< > $@
454

    
455
# Create a symbol table from ELF output file.
456
%.sym: %.elf
457
	@echo
458
	@echo $(MSG_SYMBOL_TABLE) $@
459
	$(NM) -n $< > $@
460

    
461

    
462

    
463
# Link: create ELF output file from object files.
464
.SECONDARY : $(TARGET).elf
465
.PRECIOUS : $(OBJ)
466
%.elf: $(OBJ)
467
	@echo
468
	@echo $(MSG_LINKING) $@
469
	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
470

    
471

    
472
# Compile: create object files from C source files.
473
%.o : %.c
474
	@echo
475
	@echo $(MSG_COMPILING) $<
476
	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
477

    
478

    
479
# Compile: create assembler files from C source files.
480
%.s : %.c
481
	$(CC) -S $(ALL_CFLAGS) $< -o $@
482

    
483

    
484
# Assemble: create object files from assembler source files.
485
%.o : %.S
486
	@echo
487
	@echo $(MSG_ASSEMBLING) $<
488
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
489

    
490
# Create preprocessed source for use in sending a bug report.
491
%.i : %.c
492
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ 
493

    
494

    
495
# Target: clean project.
496
clean: begin clean_list end
497

    
498
clean_list :
499
	@echo
500
	@echo $(MSG_CLEANING)
501
	$(REMOVE) $(TARGET).hex
502
	$(REMOVE) $(TARGET).eep
503
	$(REMOVE) $(TARGET).cof
504
	$(REMOVE) $(TARGET).elf
505
	$(REMOVE) $(TARGET).map
506
	$(REMOVE) $(TARGET).sym
507
	$(REMOVE) $(TARGET).lss
508
	$(REMOVE) $(OBJ)
509
	$(REMOVE) $(LST)
510
	$(REMOVE) $(SRC:.c=.s)
511
	$(REMOVE) $(SRC:.c=.d)
512
	$(REMOVEDIR) .dep
513

    
514

    
515

    
516
# Include the dependency files.
517
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
518

    
519

    
520
# Listing of phony targets.
521
.PHONY : all begin finish end sizebefore sizeafter gccversion \
522
build elf hex eep lss sym coff extcoff \
523
clean clean_list program debug gdb-config
524