Project

General

Profile

Statistics
| Revision:

root / trunk / code / makefile_root.mk @ 1510

History | View | Annotate | Download (14.6 KB)

1
# This is makefile_root.mk
2
#
3
# Make global makefile changes here
4
#
5
###################################
6

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

    
49
#if you want your code to work on the Firefly++ and not Firefly+
50
#then add the -DFFPP line to CDEFS
51
CDEFS =
52
#-DFFPP
53

    
54
# MCU name
55
MCU = atmega128
56

    
57
# Processor frequency.
58
#     This will define a symbol, F_CPU, in all source code files equal to the
59
#     processor frequency. You can then use this symbol in your source code to
60
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
61
#     automatically to create a 32-bit value in your source code.
62
F_CPU = 8000000
63

    
64
# Output format. (can be srec, ihex, binary)
65
FORMAT = ihex
66

    
67
# List C source files here. (C dependencies are automatically generated.)
68
SRC = $(wildcard *.c)
69

    
70
# List Assembler source files here.
71
#     Make them always end in a capital .S.  Files ending in a lowercase .s
72
#     will not be considered source files but generated files (assembler
73
#     output from the compiler), and will be deleted upon "make clean"!
74
#     Even though the DOS/Win* filesystem matches both .s and .S the same,
75
#     it will preserve the spelling of the filenames, and gcc itself does
76
#     care about how the name is spelled on its command-line.
77
ASRC =
78

    
79
# Optimization level, can be [0, 1, 2, 3, s].
80
#     0 = turn off optimization. s = optimize for size.
81
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
82
OPT = s
83

    
84
# Debugging format.
85
#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
86
#     AVR Studio 4.10 requires dwarf-2.
87
#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
88
DEBUG =
89

    
90
# Compiler flag to set the C Standard level.
91
#     c89   = "ANSI" C
92
#     gnu89 = c89 plus GCC extensions
93
#     c99   = ISO C99 standard (not yet fully implemented)
94
#     gnu99 = c99 plus GCC extensions
95
CSTANDARD = -std=gnu99
96

    
97
# Place -D or -U options here
98
CDEFS += -DF_CPU=$(F_CPU)UL
99
CDEFS += -DFFP
100
# for wireless library
101
ifdef USE_WIRELESS
102
	CDEFS += -DROBOT
103
endif
104

    
105
# Place -I, -L options here
106
CINCS = -I$(COLONYROOT)/code/lib/include/libdragonfly
107
CINCS += -L$(COLONYROOT)/code/lib/bin
108
ifdef USE_WIRELESS
109
  CINCS += -I$(COLONYROOT)/code/lib/include/libwireless
110
endif
111

    
112
#---------------- Compiler Options ----------------
113
#  -g*:          generate debugging information
114
#  -O*:          optimization level
115
#  -f...:        tuning, see GCC manual and avr-libc documentation
116
#  -Wall...:     warning level
117
#  -Wa,...:      tell GCC to pass this to the assembler.
118
#    -adhlns...: create assembler listing
119
CFLAGS =
120
# CFLAGS = -g$(DEBUG)
121
CFLAGS += $(CDEFS) $(CINCS)
122
CFLAGS += -O$(OPT)
123
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
124
CFLAGS += -Wall -Wstrict-prototypes
125
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
126
CFLAGS += $(CSTANDARD)
127

    
128
#---------------- Assembler Options ----------------
129
#  -Wa,...:   tell GCC to pass this to the assembler.
130
#  -ahlms:    create listing
131
#  -gstabs:   have the assembler create line number information; note that
132
#             for use in COFF files, additional information about filenames
133
#             and function names needs to be present in the assembler source
134
#             files -- see avr-libc docs [FIXME: not yet described there]
135
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
136

    
137

    
138
#---------------- Library Options ----------------
139
# Minimalistic printf version
140
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
141

    
142
# Floating point printf version (requires MATH_LIB = -lm below)
143
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
144

    
145
# If this is left blank, then it will use the Standard printf version.
146
PRINTF_LIB =
147
#PRINTF_LIB = $(PRINTF_LIB_MIN)
148
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
149

    
150

    
151
# Minimalistic scanf version
152
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
153

    
154
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
155
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
156

    
157
# If this is left blank, then it will use the Standard scanf version.
158
SCANF_LIB =
159
#SCANF_LIB = $(SCANF_LIB_MIN)
160
#SCANF_LIB = $(SCANF_LIB_FLOAT)
161

    
162
MATH_LIB = -lm
163

    
164
#---------------- External Memory Options ----------------
165

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

    
170
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
171
# only used for heap (malloc()).
172
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
173

    
174
EXTMEMOPTS =
175

    
176
#---------------- Linker Options ----------------
177
#  -Wl,...:     tell GCC to pass this to linker.
178
#    -Map:      create map file
179
#    --cref:    add cross reference to  map file
180
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
181
LDFLAGS += $(EXTMEMOPTS)
182
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
183
ifdef USE_WIRELESS
184
	LDFLAGS += -lwireless
185
endif
186
LDFLAGS += -ldragonfly
187

    
188

    
189

    
190
#---------------- Programming Options (avrdude) ----------------
191

    
192
# Programming hardware: alf avr910 avrisp bascom bsd
193
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
194
#
195
# Type: avrdude -c ?
196
# to get a full listing.
197
#
198
AVRDUDE_PROGRAMMER = avrisp
199

    
200
# programmer connected to serial device
201

    
202
AVRDUDE_WRITE_FLASH = -b 57600 -U flash:w:$(TARGET).hex
203
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
204

    
205

    
206
# Uncomment the following if you want avrdude's erase cycle counter.
207
# Note that this counter needs to be initialized first using -Yn,
208
# see avrdude manual.
209
#AVRDUDE_ERASE_COUNTER = -y
210

    
211
# Uncomment the following if you do /not/ wish a verification to be
212
# performed after programming the device.
213
#AVRDUDE_NO_VERIFY = -V
214

    
215
# Increase verbosity level.  Please use this when submitting bug
216
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
217
# to submit bug reports.
218
#AVRDUDE_VERBOSE = -v -v
219

    
220
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
221
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
222
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
223
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
224

    
225
#don't check for device signature
226
AVRDUDE_FLAGS += -F
227

    
228

    
229

    
230
#---------------- Debugging Options ----------------
231

    
232
# For simulavr only - target MCU frequency.
233
DEBUG_MFREQ = $(F_CPU)
234

    
235
# Set the DEBUG_UI to either gdb or insight.
236
# DEBUG_UI = gdb
237
DEBUG_UI = insight
238

    
239
# Set the debugging back-end to either avarice, simulavr.
240
DEBUG_BACKEND = avarice
241
#DEBUG_BACKEND = simulavr
242

    
243
# GDB Init Filename.
244
GDBINIT_FILE = __avr_gdbinit
245

    
246
# When using avarice settings for the JTAG
247
JTAG_DEV = /dev/com1
248

    
249
# Debugging port used to communicate between GDB / avarice / simulavr.
250
DEBUG_PORT = 4242
251

    
252
# Debugging host used to communicate between GDB / avarice / simulavr, normally
253
#     just set to localhost unless doing some sort of crazy debugging when
254
#     avarice is running on a different computer.
255
DEBUG_HOST = localhost
256

    
257

    
258

    
259
#============================================================================
260

    
261

    
262
# Define programs and commands.
263
SHELL = sh
264
CC = avr-gcc
265
OBJCOPY = avr-objcopy
266
OBJDUMP = avr-objdump
267
SIZE = avr-size
268
NM = avr-nm
269
AVRDUDE = avrdude
270
REMOVE = rm -f
271
REMOVEDIR = rm -rf
272
COPY = cp
273
WINSHELL = cmd
274

    
275

    
276
# Define Messages
277
# English
278
MSG_ERRORS_NONE = Errors: none
279
MSG_BEGIN = -------- begin --------
280
MSG_END = --------  end  --------
281
MSG_SIZE_BEFORE = Size before:
282
MSG_SIZE_AFTER = Size after:
283
MSG_COFF = Converting to AVR COFF:
284
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
285
MSG_FLASH = Creating load file for Flash:
286
MSG_EEPROM = Creating load file for EEPROM:
287
MSG_EXTENDED_LISTING = Creating Extended Listing:
288
MSG_SYMBOL_TABLE = Creating Symbol Table:
289
MSG_LINKING = Linking:
290
MSG_COMPILING = Compiling:
291
MSG_ASSEMBLING = Assembling:
292
MSG_CLEANING = Cleaning project:
293
MSG_LIBRARY_BUILD = Building library:
294
MSG_LIBRARY_CHECK = Checking if we need to rebuild the library:
295

    
296

    
297

    
298
# Define all object files.
299
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
300

    
301
# Define all listing files.
302
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst)
303

    
304

    
305
# Compiler flags to generate dependency files.
306
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
307

    
308

    
309
# Combine all necessary flags and optional flags.
310
# Add target processor to flags.
311
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
312
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
313

    
314

    
315

    
316

    
317

    
318
# Default target.
319
all: begin gccversion lib sizebefore build sizeafter checksize end
320

    
321
build: elf hex eep lss sym
322

    
323
elf: $(TARGET).elf
324
hex: $(TARGET).hex
325
eep: $(TARGET).eep
326
lss: $(TARGET).lss
327
sym: $(TARGET).sym
328

    
329

    
330

    
331
# Eye candy.
332
# AVR Studio 3.x does not check make's exit code but relies on
333
# the following magic strings to be generated by the compile job.
334
begin:
335
	@echo
336
	@echo $(MSG_BEGIN)
337

    
338
end:
339
	@echo $(MSG_END)
340
	@echo
341

    
342

    
343
# Display size of file.
344
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
345
ELFSIZE = $(SIZE) -A $(TARGET).elf
346
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
347

    
348
# Check RAM size (make sure under 4 kB)
349
AWK = $(shell if uname -s |grep -i w32 >/dev/null; then echo 'gawk'; else echo 'awk'; fi)
350
DATASIZE = avr-size -A main.elf | grep 'data' | $(AWK) '{ print $$2 }' > 1.tmp
351
BSSSIZE = avr-size -A main.elf | grep 'bss' | $(AWK) '{ print $$2 }' > 2.tmp
352
ADD = expr `cat 1.tmp` + `cat 2.tmp` > 3.tmp
353
CLEANSIZE = rm 1.tmp 2.tmp 3.tmp
354
checksize:
355
	@$(DATASIZE)
356
	@$(BSSSIZE)
357
	@$(ADD)
358
	@if test `cat 3.tmp` -gt 4096; \
359
	then echo "RAM size exceeded.  Make .data or .bss smaller.";echo;exit 1; \
360
	else echo ".data and .bss size fine";echo; fi
361
	@$(CLEANSIZE)
362

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

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

    
373

    
374

    
375
# Display compiler version information.
376
gccversion :
377
	@$(CC) --version
378
  
379
  
380
# Build the library
381
library:
382
	@echo $(MSG_LIBRARY_BUILD)
383
	@cd $(COLONYROOT)/code/projects/libdragonfly;make clean;make dist
384
	@cd $(COLONYROOT)/code/projects/libwireless/lib;make clean;make dist
385

    
386
# Check if library needs to be built
387
lib:
388
	@echo $(MSG_LIBRARY_CHECK)
389
	@cd $(COLONYROOT)/code/projects/libdragonfly;make dist
390
	@cd $(COLONYROOT)/code/projects/libwireless/lib;make dist
391

    
392

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

    
397

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

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

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

    
426

    
427

    
428

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

    
436

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

    
442

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

    
448

    
449

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

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

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

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

    
474

    
475

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

    
484

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

    
491

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

    
496

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

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

    
507

    
508
# Target: clean project.
509
clean: begin clean_list end
510

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

    
527

    
528

    
529
# Include the dependency files.
530
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
531

    
532

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