Project

General

Profile

Statistics
| Revision:

root / branches / rbom / code / projects / template / Makefile @ 1390

History | View | Annotate | Download (13.7 KB)

1 63 emarinel
########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 863 abuchan
TARGET = main
12 63 emarinel
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 1390 chihsiuh
AVRDUDE_PORT = $(shell if uname -s |grep -i w32 >/dev/null; then echo 'COM4:'; else echo '/dev/ttyUSB0'; fi)
18 63 emarinel
#
19
#
20
###################################
21
22
# Hey Emacs, this is a -*- makefile -*-
23
#----------------------------------------------------------------------------
24
# WinAVR Makefile Template written by Eric B. Weddington, J?rg Wunsch, et al.
25
#
26
# Released to the Public Domain
27
#
28
# Additional material for this makefile was written by:
29
# Peter Fleury
30
# Tim Henigan
31
# Colin O'Flynn
32
# Reiner Patommel
33
# Markus Pfaff
34
# Sander Pool
35
# Frederik Rouleau
36
#
37
#----------------------------------------------------------------------------
38
# On command line:
39
#
40
# make all = Make software.
41
#
42
# make clean = Clean out built project files.
43
#
44
# make coff = Convert ELF to AVR COFF.
45
#
46
# make extcoff = Convert ELF to AVR Extended COFF.
47
#
48
# make program = Download the hex file to the device, using avrdude.
49
#                Please customize the avrdude settings below first!
50
#
51 156 emarinel
# make debug = Start either simulavr or avarice as specified for debugging,
52 63 emarinel
#              with avr-gdb or avr-insight as the front end for debugging.
53
#
54
# make filename.s = Just compile filename.c into the assembler code only.
55
#
56
# make filename.i = Create a preprocessed source file for use in submitting
57
#                   bug reports to the GCC project.
58
#
59
# To rebuild project do "make clean" then "make all".
60
#----------------------------------------------------------------------------
61
62
#if you want your code to work on the Firefly++ and not Firefly+
63
#then add the -DFFPP line to CDEFS
64 156 emarinel
CDEFS =
65 63 emarinel
#-DFFPP
66
67
# MCU name
68
MCU = atmega128
69
70
# Processor frequency.
71 156 emarinel
#     This will define a symbol, F_CPU, in all source code files equal to the
72
#     processor frequency. You can then use this symbol in your source code to
73 63 emarinel
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
74
#     automatically to create a 32-bit value in your source code.
75
F_CPU = 8000000
76
77
# Output format. (can be srec, ihex, binary)
78
FORMAT = ihex
79
80
# List C source files here. (C dependencies are automatically generated.)
81
SRC = $(wildcard *.c)
82
83
# List Assembler source files here.
84
#     Make them always end in a capital .S.  Files ending in a lowercase .s
85
#     will not be considered source files but generated files (assembler
86
#     output from the compiler), and will be deleted upon "make clean"!
87
#     Even though the DOS/Win* filesystem matches both .s and .S the same,
88
#     it will preserve the spelling of the filenames, and gcc itself does
89
#     care about how the name is spelled on its command-line.
90 156 emarinel
ASRC =
91 63 emarinel
92 156 emarinel
# Optimization level, can be [0, 1, 2, 3, s].
93 63 emarinel
#     0 = turn off optimization. s = optimize for size.
94
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
95
OPT = s
96
97
# Debugging format.
98
#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
99
#     AVR Studio 4.10 requires dwarf-2.
100
#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
101
DEBUG =
102
103
# Compiler flag to set the C Standard level.
104
#     c89   = "ANSI" C
105
#     gnu89 = c89 plus GCC extensions
106
#     c99   = ISO C99 standard (not yet fully implemented)
107
#     gnu99 = c99 plus GCC extensions
108
CSTANDARD = -std=gnu99
109
110
# Place -D or -U options here
111 156 emarinel
CDEFS += -DF_CPU=$(F_CPU)UL
112 63 emarinel
CDEFS += -DFFP
113
# for wireless library
114
ifdef USE_WIRELESS
115
	CDEFS += -DROBOT
116
endif
117
118
# Place -I, -L options here
119 369 abuchan
CINCS = -I../libdragonfly
120
CINCS += -L../libdragonfly
121 63 emarinel
122
#---------------- Compiler Options ----------------
123
#  -g*:          generate debugging information
124
#  -O*:          optimization level
125
#  -f...:        tuning, see GCC manual and avr-libc documentation
126
#  -Wall...:     warning level
127
#  -Wa,...:      tell GCC to pass this to the assembler.
128
#    -adhlns...: create assembler listing
129
CFLAGS =
130
# CFLAGS = -g$(DEBUG)
131
CFLAGS += $(CDEFS) $(CINCS)
132
CFLAGS += -O$(OPT)
133
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
134
CFLAGS += -Wall -Wstrict-prototypes
135
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
136
CFLAGS += $(CSTANDARD)
137
138
#---------------- Assembler Options ----------------
139
#  -Wa,...:   tell GCC to pass this to the assembler.
140
#  -ahlms:    create listing
141
#  -gstabs:   have the assembler create line number information; note that
142
#             for use in COFF files, additional information about filenames
143
#             and function names needs to be present in the assembler source
144
#             files -- see avr-libc docs [FIXME: not yet described there]
145 156 emarinel
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
146 63 emarinel
147
148
#---------------- Library Options ----------------
149
# Minimalistic printf version
150
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
151
152
# Floating point printf version (requires MATH_LIB = -lm below)
153
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
154
155
# If this is left blank, then it will use the Standard printf version.
156 156 emarinel
PRINTF_LIB =
157 63 emarinel
#PRINTF_LIB = $(PRINTF_LIB_MIN)
158
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
159
160
161
# Minimalistic scanf version
162
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
163
164
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
165
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
166
167
# If this is left blank, then it will use the Standard scanf version.
168 156 emarinel
SCANF_LIB =
169 63 emarinel
#SCANF_LIB = $(SCANF_LIB_MIN)
170
#SCANF_LIB = $(SCANF_LIB_FLOAT)
171
172
MATH_LIB = -lm
173
174
#---------------- External Memory Options ----------------
175
176
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
177
# used for variables (.data/.bss) and heap (malloc()).
178
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
179
180
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
181
# only used for heap (malloc()).
182
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
183
184
EXTMEMOPTS =
185
186
#---------------- Linker Options ----------------
187
#  -Wl,...:     tell GCC to pass this to linker.
188
#    -Map:      create map file
189
#    --cref:    add cross reference to  map file
190
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
191
LDFLAGS += $(EXTMEMOPTS)
192
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
193
ifdef USE_WIRELESS
194
	LDFLAGS += -lwireless
195
endif
196
LDFLAGS += -ldragonfly
197
198
199
200
#---------------- Programming Options (avrdude) ----------------
201
202 156 emarinel
# Programming hardware: alf avr910 avrisp bascom bsd
203 63 emarinel
# 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 156 emarinel
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
227 63 emarinel
# 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 156 emarinel
#     just set to localhost unless doing some sort of crazy debugging when
264 63 emarinel
#     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 156 emarinel
MSG_SIZE_BEFORE = Size before:
292 63 emarinel
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 156 emarinel
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
309 63 emarinel
310
# Define all listing files.
311 156 emarinel
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst)
312 63 emarinel
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 156 emarinel
lss: $(TARGET).lss
336 63 emarinel
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 156 emarinel
gccversion :
369 63 emarinel
	@$(CC) --version
370
371
372
373 156 emarinel
# Program the device.
374 63 emarinel
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 156 emarinel
#     define the reset signal, load the target file, connect to target, and set
380 63 emarinel
#     a breakpoint at main().
381 156 emarinel
gdb-config:
382 63 emarinel
	@$(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 156 emarinel
endif
391 63 emarinel
	@echo break main >> $(GDBINIT_FILE)
392 156 emarinel
393 63 emarinel
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 156 emarinel
400 63 emarinel
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 156 emarinel
409 63 emarinel
# 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 156 emarinel
--change-section-address .eeprom-0x810000
415 63 emarinel
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 156 emarinel
	$(CC) -c $(ALL_CFLAGS) $< -o $@
470 63 emarinel
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 156 emarinel
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
486 63 emarinel
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