Project

General

Profile

Statistics
| Revision:

root / branches / wireless / code / Makefile @ 1513

History | View | Annotate | Download (14.8 KB)

1 1499 dsschult
# This is the root makefile
2 1491 dsschult
#
3
# Make global makefile changes here
4
#
5
###################################
6
7 1499 dsschult
# Relative path to the root directory (containing lib directory)
8
ifndef COLONYROOT
9
COLONYROOT := ..
10
else
11
COLONYROOT := ../$(COLONYROOT)
12
endif
13
14 1491 dsschult
# 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 1513 dsschult
	make clean -C $(COLONYROOT)/code/projects/libdragonfly
391
	make dist -C $(COLONYROOT)/code/projects/libdragonfly
392
	make clean -C $(COLONYROOT)/code/projects/libwireless/lib
393
	make dist -C $(COLONYROOT)/code/projects/libwireless/lib
394 1491 dsschult
395
# Check if library needs to be built
396
lib:
397
	@echo $(MSG_LIBRARY_CHECK)
398 1513 dsschult
	make dist -C $(COLONYROOT)/code/projects/libdragonfly
399
	make dist -C $(COLONYROOT)/code/projects/libwireless/lib
400 1491 dsschult
401
402
# Program the device.
403
program: $(TARGET).hex $(TARGET).eep
404
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
405
406
407
# Generate avr-gdb config/init file which does the following:
408
#     define the reset signal, load the target file, connect to target, and set
409
#     a breakpoint at main().
410
gdb-config:
411
	@$(REMOVE) $(GDBINIT_FILE)
412
	@echo define reset >> $(GDBINIT_FILE)
413
	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
414
	@echo end >> $(GDBINIT_FILE)
415
	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
416
	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
417
ifeq ($(DEBUG_BACKEND),simulavr)
418
	@echo load  >> $(GDBINIT_FILE)
419
endif
420
	@echo break main >> $(GDBINIT_FILE)
421
422
debug: gdb-config $(TARGET).elf
423
ifeq ($(DEBUG_BACKEND), avarice)
424
	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
425
	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
426
	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
427
	@$(WINSHELL) /c pause
428
429
else
430
	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
431
	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
432
endif
433
	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
434
435
436
437
438
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
439
COFFCONVERT=$(OBJCOPY) --debugging \
440
--change-section-address .data-0x800000 \
441
--change-section-address .bss-0x800000 \
442
--change-section-address .noinit-0x800000 \
443
--change-section-address .eeprom-0x810000
444
445
446
coff: $(TARGET).elf
447
	@echo
448
	@echo $(MSG_COFF) $(TARGET).cof
449
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
450
451
452
extcoff: $(TARGET).elf
453
	@echo
454
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
455
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
456
457
458
459
# Create final output files (.hex, .eep) from ELF output file.
460
%.hex: %.elf
461
	@echo
462
	@echo $(MSG_FLASH) $@
463
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
464
465
%.eep: %.elf
466
	@echo
467
	@echo $(MSG_EEPROM) $@
468
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
469
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
470
471
# Create extended listing file from ELF output file.
472
%.lss: %.elf
473
	@echo
474
	@echo $(MSG_EXTENDED_LISTING) $@
475
	$(OBJDUMP) -h -S $< > $@
476
477
# Create a symbol table from ELF output file.
478
%.sym: %.elf
479
	@echo
480
	@echo $(MSG_SYMBOL_TABLE) $@
481
	$(NM) -n $< > $@
482
483
484
485
# Link: create ELF output file from object files.
486
.SECONDARY : $(TARGET).elf
487
.PRECIOUS : $(OBJ)
488
%.elf: $(OBJ)
489
	@echo
490
	@echo $(MSG_LINKING) $@
491
	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
492
493
494
# Compile: create object files from C source files.
495
%.o : %.c
496
	@echo
497
	@echo $(MSG_COMPILING) $<
498
	$(CC) -c $(ALL_CFLAGS) $< -o $@
499
500
501
# Compile: create assembler files from C source files.
502
%.s : %.c
503
	$(CC) -S $(ALL_CFLAGS) $< -o $@
504
505
506
# Assemble: create object files from assembler source files.
507
%.o : %.S
508
	@echo
509
	@echo $(MSG_ASSEMBLING) $<
510
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
511
512
# Create preprocessed source for use in sending a bug report.
513
%.i : %.c
514
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
515
516
517
# Target: clean project.
518
clean: begin clean_list end
519
520
clean_list :
521
	@echo
522
	@echo $(MSG_CLEANING)
523
	$(REMOVE) $(TARGET).hex
524
	$(REMOVE) $(TARGET).eep
525
	$(REMOVE) $(TARGET).cof
526
	$(REMOVE) $(TARGET).elf
527
	$(REMOVE) $(TARGET).map
528
	$(REMOVE) $(TARGET).sym
529
	$(REMOVE) $(TARGET).lss
530
	$(REMOVE) $(OBJ)
531
	$(REMOVE) $(LST)
532
	$(REMOVE) $(SRC:.c=.s)
533
	$(REMOVE) $(SRC:.c=.d)
534
	$(REMOVEDIR) .dep
535
536
537
538
# Include the dependency files.
539
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
540
541
542
# Listing of phony targets.
543
.PHONY : all begin finish end sizebefore sizeafter gccversion \
544
build elf hex eep lss sym coff extcoff \
545
clean clean_list program debug gdb-config