Project

General

Profile

Statistics
| Revision:

root / branches / wireless / code / Makefile @ 1560

History | View | Annotate | Download (14.9 KB)

1
# This is the root makefile
2
#
3
# Make global makefile changes here
4
#
5
###################################
6

    
7
# Relative path to the root directory (containing lib directory)
8
ifndef COLONYROOT
9
COLONYROOT := ..
10
else
11
COLONYROOT := ../$(COLONYROOT)
12
endif
13

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

    
56
#if you want your code to work on the Firefly++ and not Firefly+
57
#then add the -DFFPP line to CDEFS
58
CDEFS =
59
#-DFFPP
60

    
61
# MCU name
62
MCU = atmega128
63

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

    
71
# Output format. (can be srec, ihex, binary)
72
FORMAT = ihex
73

    
74
# List C source files here. (C dependencies are automatically generated.)
75
SRC = $(wildcard *.c)
76

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

    
86
# Optimization level, can be [0, 1, 2, 3, s].
87
#     0 = turn off optimization. s = optimize for size.
88
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
89
OPT = s
90

    
91
# Debugging format.
92
#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
93
#     AVR Studio 4.10 requires dwarf-2.
94
#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
95
DEBUG =
96

    
97
# Compiler flag to set the C Standard level.
98
#     c89   = "ANSI" C
99
#     gnu89 = c89 plus GCC extensions
100
#     c99   = ISO C99 standard (not yet fully implemented)
101
#     gnu99 = c99 plus GCC extensions
102
CSTANDARD = -std=gnu99
103

    
104
# Place -D or -U options here
105
CDEFS += -DF_CPU=$(F_CPU)UL
106
CDEFS += -DFFP
107
# for wireless library
108
ifdef USE_WIRELESS
109
	CDEFS += -DROBOT
110
endif
111

    
112
# Place -I, -L options here
113
CINCS = -I$(COLONYROOT)/code/lib/include/libdragonfly
114
CINCS += -L$(COLONYROOT)/code/lib/bin
115
ifdef USE_WIRELESS
116
  CINCS += -I$(COLONYROOT)/code/lib/include/libwireless
117
endif
118

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

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

    
144

    
145
#---------------- Library Options ----------------
146
# Minimalistic printf version
147
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
148

    
149
# Floating point printf version (requires MATH_LIB = -lm below)
150
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
151

    
152
# If this is left blank, then it will use the Standard printf version.
153
PRINTF_LIB =
154
#PRINTF_LIB = $(PRINTF_LIB_MIN)
155
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
156

    
157

    
158
# Minimalistic scanf version
159
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
160

    
161
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
162
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
163

    
164
# If this is left blank, then it will use the Standard scanf version.
165
SCANF_LIB =
166
#SCANF_LIB = $(SCANF_LIB_MIN)
167
#SCANF_LIB = $(SCANF_LIB_FLOAT)
168

    
169
MATH_LIB = -lm
170

    
171
#---------------- External Memory Options ----------------
172

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

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

    
181
EXTMEMOPTS =
182

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

    
195

    
196

    
197
#---------------- Programming Options (avrdude) ----------------
198

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

    
207
# programmer connected to serial device
208

    
209
AVRDUDE_WRITE_FLASH = -b 57600 -U flash:w:$(TARGET).hex
210
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
211

    
212

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

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

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

    
227
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
228
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
229
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
230
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
231

    
232
#don't check for device signature
233
AVRDUDE_FLAGS += -F
234

    
235

    
236

    
237
#---------------- Debugging Options ----------------
238

    
239
# For simulavr only - target MCU frequency.
240
DEBUG_MFREQ = $(F_CPU)
241

    
242
# Set the DEBUG_UI to either gdb or insight.
243
# DEBUG_UI = gdb
244
DEBUG_UI = insight
245

    
246
# Set the debugging back-end to either avarice, simulavr.
247
DEBUG_BACKEND = avarice
248
#DEBUG_BACKEND = simulavr
249

    
250
# GDB Init Filename.
251
GDBINIT_FILE = __avr_gdbinit
252

    
253
# When using avarice settings for the JTAG
254
JTAG_DEV = /dev/com1
255

    
256
# Debugging port used to communicate between GDB / avarice / simulavr.
257
DEBUG_PORT = 4242
258

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

    
264

    
265

    
266
#============================================================================
267

    
268

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

    
282

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

    
303

    
304

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

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

    
311

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

    
315

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

    
321

    
322

    
323

    
324

    
325
# Default target.
326
all: begin gccversion lib sizebefore build sizeafter checksize end
327

    
328
build: elf hex eep lss sym
329

    
330
elf: $(TARGET).elf
331
hex: $(TARGET).hex
332
eep: $(TARGET).eep
333
lss: $(TARGET).lss
334
sym: $(TARGET).sym
335

    
336

    
337

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

    
345
end:
346
	@echo $(MSG_END)
347
	@echo
348

    
349

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

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

    
370
# Display size before
371
sizebefore:
372
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
373
	$(AVRMEM) 2>/dev/null; echo; fi
374

    
375
# Display size after
376
sizeafter:
377
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
378
	$(AVRMEM) 2>/dev/null; echo; fi
379

    
380

    
381

    
382
# Display compiler version information.
383
gccversion :
384
	@$(CC) --version
385
  
386
  
387
# Build the library
388
library:
389
	@echo $(MSG_LIBRARY_BUILD)
390
	make clean -C $(COLONYROOT)/code/projects/libdragonfly
391
	make dist -C $(COLONYROOT)/code/projects/libdragonfly
392
ifdef USE_WIRELESS
393
	make clean -C $(COLONYROOT)/code/projects/libwireless/lib
394
	make dist -C $(COLONYROOT)/code/projects/libwireless/lib
395
endif
396

    
397
# Check if library needs to be built
398
lib:
399
	@echo $(MSG_LIBRARY_CHECK)
400
	make dist -C $(COLONYROOT)/code/projects/libdragonfly
401
#ifdef USE_WIRELESS
402
	make dist -C $(COLONYROOT)/code/projects/libwireless/lib
403
#endif
404

    
405

    
406
# Program the device.
407
program: $(TARGET).hex $(TARGET).eep
408
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
409

    
410

    
411
# Generate avr-gdb config/init file which does the following:
412
#     define the reset signal, load the target file, connect to target, and set
413
#     a breakpoint at main().
414
gdb-config:
415
	@$(REMOVE) $(GDBINIT_FILE)
416
	@echo define reset >> $(GDBINIT_FILE)
417
	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
418
	@echo end >> $(GDBINIT_FILE)
419
	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
420
	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
421
ifeq ($(DEBUG_BACKEND),simulavr)
422
	@echo load  >> $(GDBINIT_FILE)
423
endif
424
	@echo break main >> $(GDBINIT_FILE)
425

    
426
debug: gdb-config $(TARGET).elf
427
ifeq ($(DEBUG_BACKEND), avarice)
428
	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
429
	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
430
	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
431
	@$(WINSHELL) /c pause
432

    
433
else
434
	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
435
	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
436
endif
437
	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
438

    
439

    
440

    
441

    
442
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
443
COFFCONVERT=$(OBJCOPY) --debugging \
444
--change-section-address .data-0x800000 \
445
--change-section-address .bss-0x800000 \
446
--change-section-address .noinit-0x800000 \
447
--change-section-address .eeprom-0x810000
448

    
449

    
450
coff: $(TARGET).elf
451
	@echo
452
	@echo $(MSG_COFF) $(TARGET).cof
453
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
454

    
455

    
456
extcoff: $(TARGET).elf
457
	@echo
458
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
459
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
460

    
461

    
462

    
463
# Create final output files (.hex, .eep) from ELF output file.
464
%.hex: %.elf
465
	@echo
466
	@echo $(MSG_FLASH) $@
467
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
468

    
469
%.eep: %.elf
470
	@echo
471
	@echo $(MSG_EEPROM) $@
472
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
473
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
474

    
475
# Create extended listing file from ELF output file.
476
%.lss: %.elf
477
	@echo
478
	@echo $(MSG_EXTENDED_LISTING) $@
479
	$(OBJDUMP) -h -S $< > $@
480

    
481
# Create a symbol table from ELF output file.
482
%.sym: %.elf
483
	@echo
484
	@echo $(MSG_SYMBOL_TABLE) $@
485
	$(NM) -n $< > $@
486

    
487

    
488

    
489
# Link: create ELF output file from object files.
490
.SECONDARY : $(TARGET).elf
491
.PRECIOUS : $(OBJ)
492
%.elf: $(OBJ)
493
	@echo
494
	@echo $(MSG_LINKING) $@
495
	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
496

    
497

    
498
# Compile: create object files from C source files.
499
%.o : %.c
500
	@echo
501
	@echo $(MSG_COMPILING) $<
502
	$(CC) -c $(ALL_CFLAGS) $< -o $@
503

    
504

    
505
# Compile: create assembler files from C source files.
506
%.s : %.c
507
	$(CC) -S $(ALL_CFLAGS) $< -o $@
508

    
509

    
510
# Assemble: create object files from assembler source files.
511
%.o : %.S
512
	@echo
513
	@echo $(MSG_ASSEMBLING) $<
514
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
515

    
516
# Create preprocessed source for use in sending a bug report.
517
%.i : %.c
518
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
519

    
520

    
521
# Target: clean project.
522
clean: begin clean_list end
523

    
524
clean_list :
525
	@echo
526
	@echo $(MSG_CLEANING)
527
	$(REMOVE) $(TARGET).hex
528
	$(REMOVE) $(TARGET).eep
529
	$(REMOVE) $(TARGET).cof
530
	$(REMOVE) $(TARGET).elf
531
	$(REMOVE) $(TARGET).map
532
	$(REMOVE) $(TARGET).sym
533
	$(REMOVE) $(TARGET).lss
534
	$(REMOVE) $(OBJ)
535
	$(REMOVE) $(LST)
536
	$(REMOVE) $(SRC:.c=.s)
537
	$(REMOVE) $(SRC:.c=.d)
538
	$(REMOVEDIR) .dep
539

    
540

    
541

    
542
# Include the dependency files.
543
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
544

    
545

    
546
# Listing of phony targets.
547
.PHONY : all begin finish end sizebefore sizeafter gccversion \
548
build elf hex eep lss sym coff extcoff \
549
clean clean_list program debug gdb-config
550