Project

General

Profile

Statistics
| Revision:

root / branches / simulator / projects / template / Makefile @ 1101

History | View | Annotate | Download (14.3 KB)

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

    
5
# COMX in Windows. /dev/ttyUSBX in Linux.
6
AVRDUDE_PORT = /dev/ttyUSB0
7

    
8
# Target file name (without extension).
9
TARGET = template
10

    
11
# Uncomment this to use the wireless library
12
# USE_WIRELESS = 1
13

    
14
# Relative path to the root directory (containing lib directory)
15
PROJECTSROOT = ..
16
ifndef COLONYLIB
17
COLONYLIB = $(PROJECTSROOT)/../lib
18
endif
19

    
20
#
21
#
22
###################################
23

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

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

    
69
# MCU name
70
MCU = atmega128
71

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

    
79
# Output format. (can be srec, ihex, binary)
80
FORMAT = ihex
81

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

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

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

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

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

    
112
# Place -D or -U options here
113
CDEFS += -DF_CPU=$(F_CPU)UL
114
CDEFS += -DFFP
115
# for wireless library
116
CDEFS += -DROBOT
117

    
118
# Place -I, -L options here
119
CINCS = -I$(COLONYLIB)/include/libdragonfly
120
CINCS += -L$(COLONYLIB)/bin
121
ifdef USE_WIRELESS
122
	CINCS += -I$(COLONYLIB)/include/libwireless
123
endif
124

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

    
141
SIMCFLAGS = 
142
# SIMCFLAGS = -g$(DEBUG)
143
SIMCFLAGS += $(CDEFS) $(CINCS)
144
SIMCFLAGS += -O$(OPT)
145
SIMCFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
146
SIMCFLAGS += -Wall -Wstrict-prototypes
147
CFSIMLAGS += $(CSTANDARD)
148

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

    
158

    
159
#---------------- Library Options ----------------
160
# Minimalistic printf version
161
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
162

    
163
# Floating point printf version (requires MATH_LIB = -lm below)
164
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
165

    
166
# If this is left blank, then it will use the Standard printf version.
167
PRINTF_LIB =
168
#PRINTF_LIB = $(PRINTF_LIB_MIN)
169
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
170

    
171

    
172
# Minimalistic scanf version
173
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
174

    
175
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
176
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
177

    
178
# If this is left blank, then it will use the Standard scanf version.
179
SCANF_LIB =
180
#SCANF_LIB = $(SCANF_LIB_MIN)
181
#SCANF_LIB = $(SCANF_LIB_FLOAT)
182

    
183
MATH_LIB = -lm
184

    
185
#---------------- External Memory Options ----------------
186

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

    
191
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
192
# only used for heap (malloc()).
193
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
194

    
195
EXTMEMOPTS =
196

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

    
210

    
211

    
212
#---------------- Programming Options (avrdude) ----------------
213

    
214
# Programming hardware: alf avr910 avrisp bascom bsd
215
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
216
#
217
# Type: avrdude -c ?
218
# to get a full listing.
219
#
220
AVRDUDE_PROGRAMMER = avrisp
221

    
222
# programmer connected to serial device
223

    
224
AVRDUDE_WRITE_FLASH = -b 57600 -U flash:w:$(TARGET).hex
225
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
226

    
227

    
228
# Uncomment the following if you want avrdude's erase cycle counter.
229
# Note that this counter needs to be initialized first using -Yn,
230
# see avrdude manual.
231
#AVRDUDE_ERASE_COUNTER = -y
232

    
233
# Uncomment the following if you do /not/ wish a verification to be
234
# performed after programming the device.
235
#AVRDUDE_NO_VERIFY = -V
236

    
237
# Increase verbosity level.  Please use this when submitting bug
238
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
239
# to submit bug reports.
240
#AVRDUDE_VERBOSE = -v -v
241

    
242
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
243
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
244
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
245
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
246

    
247
#don't check for device signature
248
AVRDUDE_FLAGS += -F
249

    
250

    
251

    
252
#---------------- Debugging Options ----------------
253

    
254
# For simulavr only - target MCU frequency.
255
DEBUG_MFREQ = $(F_CPU)
256

    
257
# Set the DEBUG_UI to either gdb or insight.
258
# DEBUG_UI = gdb
259
DEBUG_UI = insight
260

    
261
# Set the debugging back-end to either avarice, simulavr.
262
DEBUG_BACKEND = avarice
263
#DEBUG_BACKEND = simulavr
264

    
265
# GDB Init Filename.
266
GDBINIT_FILE = __avr_gdbinit
267

    
268
# When using avarice settings for the JTAG
269
JTAG_DEV = /dev/com1
270

    
271
# Debugging port used to communicate between GDB / avarice / simulavr.
272
DEBUG_PORT = 4242
273

    
274
# Debugging host used to communicate between GDB / avarice / simulavr, normally
275
#     just set to localhost unless doing some sort of crazy debugging when
276
#     avarice is running on a different computer.
277
DEBUG_HOST = localhost
278

    
279

    
280

    
281
#============================================================================
282

    
283

    
284
# Define programs and commands.
285
SHELL = sh
286
CC = avr-gcc
287
SIMCC = gcc
288
OBJCOPY = avr-objcopy
289
OBJDUMP = avr-objdump
290
SIZE = avr-size
291
NM = avr-nm
292
AVRDUDE = avrdude
293
REMOVE = rm -f
294
REMOVEDIR = rm -rf
295
COPY = cp
296
CP = cp
297
WINSHELL = cmd
298

    
299

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

    
318

    
319

    
320

    
321
# Define all object files.
322
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
323
SIMOBJ = $(SRC:.c=.obj) $(ASRC:.S=.obj)
324

    
325
# Define all listing files.
326
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst)
327

    
328

    
329
# Compiler flags to generate dependency files.
330
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
331

    
332

    
333
# Combine all necessary flags and optional flags.
334
# Add target processor to flags.
335
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
336
SIMALL_CFLAGS = -I. $(SIMCFLAGS)
337
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
338

    
339
# Default target.
340
all: begin gccversion sizebefore build sizeafter end
341

    
342
build: elf hex eep lss sym
343
sim: dist
344

    
345
buildsim: $(SIMOBJ)
346
	$(SIMCC) $(SIMALL_CFLAGS) $^ -o $(TARGET).csim $(SIMLDFLAGS)
347
dist: buildsim
348
	$(CP) $(TARGET) $(PROJECTSROOT)/simulator/simulator/bin/
349

    
350
%.obj : %.c
351
	$(SIMCC) -c $(SIMALL_CFLAGS) $< -o $@
352

    
353

    
354
elf: $(TARGET).elf
355
hex: $(TARGET).hex
356
eep: $(TARGET).eep
357
lss: $(TARGET).lss
358
sym: $(TARGET).sym
359

    
360

    
361

    
362
# Eye candy.
363
# AVR Studio 3.x does not check make's exit code but relies on
364
# the following magic strings to be generated by the compile job.
365
begin:
366
	@echo
367
	@echo $(MSG_BEGIN)
368

    
369
end:
370
	@echo $(MSG_END)
371
	@echo
372

    
373

    
374
# Display size of file.
375
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
376
ELFSIZE = $(SIZE) -A $(TARGET).elf
377
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
378

    
379
sizebefore:
380
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
381
	$(AVRMEM) 2>/dev/null; echo; fi
382

    
383
sizeafter:
384
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
385
	$(AVRMEM) 2>/dev/null; echo; fi
386

    
387

    
388

    
389
# Display compiler version information.
390
gccversion :
391
	@$(CC) --version
392

    
393

    
394

    
395
# Program the device.
396
program: $(TARGET).hex $(TARGET).eep
397
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
398

    
399

    
400
# Generate avr-gdb config/init file which does the following:
401
#     define the reset signal, load the target file, connect to target, and set
402
#     a breakpoint at main().
403
gdb-config:
404
	@$(REMOVE) $(GDBINIT_FILE)
405
	@echo define reset >> $(GDBINIT_FILE)
406
	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
407
	@echo end >> $(GDBINIT_FILE)
408
	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
409
	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
410
ifeq ($(DEBUG_BACKEND),simulavr)
411
	@echo load  >> $(GDBINIT_FILE)
412
endif
413
	@echo break main >> $(GDBINIT_FILE)
414

    
415
debug: gdb-config $(TARGET).elf
416
ifeq ($(DEBUG_BACKEND), avarice)
417
	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
418
	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
419
	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
420
	@$(WINSHELL) /c pause
421

    
422
else
423
	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
424
	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
425
endif
426
	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
427

    
428

    
429

    
430

    
431
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
432
COFFCONVERT=$(OBJCOPY) --debugging \
433
--change-section-address .data-0x800000 \
434
--change-section-address .bss-0x800000 \
435
--change-section-address .noinit-0x800000 \
436
--change-section-address .eeprom-0x810000
437

    
438

    
439
coff: $(TARGET).elf
440
	@echo
441
	@echo $(MSG_COFF) $(TARGET).cof
442
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
443

    
444

    
445
extcoff: $(TARGET).elf
446
	@echo
447
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
448
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
449

    
450

    
451

    
452
# Create final output files (.hex, .eep) from ELF output file.
453
%.hex: %.elf
454
	@echo
455
	@echo $(MSG_FLASH) $@
456
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
457

    
458
%.eep: %.elf
459
	@echo
460
	@echo $(MSG_EEPROM) $@
461
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
462
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
463

    
464
# Create extended listing file from ELF output file.
465
%.lss: %.elf
466
	@echo
467
	@echo $(MSG_EXTENDED_LISTING) $@
468
	$(OBJDUMP) -h -S $< > $@
469

    
470
# Create a symbol table from ELF output file.
471
%.sym: %.elf
472
	@echo
473
	@echo $(MSG_SYMBOL_TABLE) $@
474
	$(NM) -n $< > $@
475

    
476

    
477

    
478
# Link: create ELF output file from object files.
479
.SECONDARY : $(TARGET).elf
480
.PRECIOUS : $(OBJ)
481
%.elf: $(OBJ)
482
	@echo
483
	@echo $(MSG_LINKING) $@
484
	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
485

    
486

    
487
# Compile: create object files from C source files.
488
%.o : %.c
489
	@echo
490
	@echo $(MSG_COMPILING) $<
491
	$(CC) -c $(ALL_CFLAGS) $< -o $@
492

    
493

    
494
# Compile: create assembler files from C source files.
495
%.s : %.c
496
	$(CC) -S $(ALL_CFLAGS) $< -o $@
497

    
498

    
499
# Assemble: create object files from assembler source files.
500
%.o : %.S
501
	@echo
502
	@echo $(MSG_ASSEMBLING) $<
503
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
504

    
505
# Create preprocessed source for use in sending a bug report.
506
%.i : %.c
507
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
508

    
509

    
510
# Target: clean project.
511
clean: begin clean_list end
512

    
513
clean_list :
514
	@echo
515
	@echo $(MSG_CLEANING)
516
	$(REMOVE) $(TARGET).hex
517
	$(REMOVE) $(TARGET).eep
518
	$(REMOVE) $(TARGET).cof
519
	$(REMOVE) $(TARGET).elf
520
	$(REMOVE) $(TARGET).map
521
	$(REMOVE) $(TARGET).sym
522
	$(REMOVE) $(TARGET).lss
523
	$(REMOVE) $(OBJ)
524
	$(REMOVE) $(SIMOBJ)
525
	$(REMOVE) $(LST)
526
	$(REMOVE) $(SRC:.c=.s)
527
	$(REMOVE) $(SRC:.c=.d)
528
	$(REMOVEDIR) .dep
529

    
530

    
531

    
532
# Include the dependency files.
533
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
534

    
535

    
536
# Listing of phony targets.
537
.PHONY : all begin finish end sizebefore sizeafter gccversion \
538
build elf hex eep lss sym coff extcoff \
539
clean clean_list program debug gdb-config
540